Skip to content

Commit

Permalink
allow ignoring releases by regular expression
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aoldershaw committed Jan 26, 2021
1 parent 1b4f416 commit 402fa93
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"regexp"

"github.com/clarafu/release-me/generate"
"github.com/clarafu/release-me/github"
Expand All @@ -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")
}

Expand All @@ -33,13 +35,29 @@ 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)
if err != nil {
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
Expand Down

0 comments on commit 402fa93

Please sign in to comment.