From 402fa93120678b6ea9d8b92664944ad986564360 Mon Sep 17 00:00:00 2001 From: Aidan Oldershaw Date: Mon, 25 Jan 2021 22:34:46 -0500 Subject: [PATCH] allow ignoring releases by regular expression 6.7.0 was a weird release since there was a lot of new behaviour added to master between 6.6.0 and 6.7.0, but 6.7.0 received very few of those changes. However, we have merged 6.7.x back into master, so the tags are clearly present on master. In this unusual case, we want to ignore the 6.7.x release, since otherwise the PRs merged pre-6.7.0 won't be included. This commit adds the flag `--ignore-release-regex` which takes a regular expression of release names to ignore. e.g. ``` --ignore-release-regex '^v6\.7\.\d+' ``` matches all 6.7.x releases Signed-off-by: Aidan Oldershaw --- cmd/generate.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/generate.go b/cmd/generate.go index e8085f6..6912ebf 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "regexp" "github.com/clarafu/release-me/generate" "github.com/clarafu/release-me/github" @@ -22,6 +23,7 @@ func init() { generateCmd.Flags().String("github-branch", "master", "the branch name of the github repository to pull the pull requests from") generateCmd.Flags().String("last-commit-SHA", "", "will generate a release note using all prs merged up to this commit SHA. If empty, will generate release note until latest commit.") generateCmd.Flags().String("release-version", "", "the version that the release note will be generated for") + generateCmd.Flags().String("ignore-release-regex", "", "a regular expression indicating releases to ignore when determining the previous release") generateCmd.MarkFlagRequired("release-version") } @@ -33,6 +35,8 @@ func generateReleaseNote(cmd *cobra.Command, args []string) { githubOwner, _ := cmd.Flags().GetString("github-owner") githubRepo, _ := cmd.Flags().GetString("github-repo") + ignoreReleaseRegexStr, _ := cmd.Flags().GetString("ignore-release-regex") + // Fetch previous 50 releases from the repository and grab the commit hash // associated to each release releaseSHAs, err := client.FetchCommitsFromReleases(githubOwner, githubRepo) @@ -40,6 +44,20 @@ func generateReleaseNote(cmd *cobra.Command, args []string) { failf("failed to fetch release commit SHAs from github: %s", err) } + if ignoreReleaseRegexStr != "" { + filteredReleaseSHAs := make(map[string]string) + ignoreReleaseRegex, err := regexp.Compile(ignoreReleaseRegexStr) + if err != nil { + failf("invalid regex in --ignore-release-regex: %s", err) + } + for oid, release := range releaseSHAs { + if !ignoreReleaseRegex.MatchString(release) { + filteredReleaseSHAs[oid] = release + } + } + releaseSHAs = filteredReleaseSHAs + } + githubBranch, _ := cmd.Flags().GetString("github-branch") // Starting from the latest commit on the branch, we want to walk backwards