From 1b4f4160b88b50740c36e772387b20ace80c353c Mon Sep 17 00:00:00 2001 From: Taylor Silva Date: Thu, 5 Nov 2020 10:53:27 -0500 Subject: [PATCH] add logic around when to start fetching prs for generate if the version to release is a major/minor, we want to start fetching prs from the last major or minor release. If the version to release is a patch, we want to start fetching prs from the last release regardless of major/minor/patch. As a result, major/minor release notes will include prs that were released in previous patches. Signed-off-by: Taylor Silva Co-authored-by: Clara Fu --- cmd/generate.go | 27 ++++----------------------- github/github.go | 17 +++++++++++------ 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 167eb16..e8085f6 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -21,6 +21,8 @@ var generateCmd = &cobra.Command{ 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.MarkFlagRequired("release-version") } func generateReleaseNote(cmd *cobra.Command, args []string) { @@ -44,33 +46,12 @@ func generateReleaseNote(cmd *cobra.Command, args []string) { // and compare each commit SHA to the list of release commit SHAs. Once we // find a match, this is the the point at which we want to start generating // the release notes for. - // - // We also will skip over any commit SHAs that are - // associated to a patch release because we only want to start from a - // major/minor release. - startingCommitSHA, err := client.FetchLatestReleaseCommitFromBranch(githubOwner, githubRepo, githubBranch, releaseSHAs) + versionToRelease, _ := cmd.Flags().GetString("release-version") + startingCommitSHA, err := client.FetchLatestReleaseCommitFromBranch(githubOwner, githubRepo, githubBranch, versionToRelease, releaseSHAs) if err != nil { failf("failed to fetch latest release commit from branch: %s", err) } - // 5904,5905 - // release/6.5.x: 6.5.0 -------------- 6.5.1 - // 6602,5904,5905 - // release/6.6.x: 6.5.0 ---------------6.5.1--------------- current (6.6.0) - - // patchReleases []patches := {6.5.1} - - // Fetch pull requests from patch releases that were skipped over while - // finding the starting commit SHA. These pull requests will be used to know - // which pull requests to ignore within the release note generation. This is - // because we don't want to include any pull requests that have already been - // mentioned in previous patch releases - patchReleasesPRs, err := client.FetchPullRequestsFromPatchReleases(githubOwner, githubRepo, githubBranch, releaseSHAs) - if err != nil { - failf("failed to fetch pull requests from patches: %s", err) - } - - lastCommitSHA, _ := cmd.Flags().GetString("last-commit-SHA") // Fetch all pull requests that are associated to a commit after the starting diff --git a/github/github.go b/github/github.go index abf04c2..9b2248d 100644 --- a/github/github.go +++ b/github/github.go @@ -48,7 +48,7 @@ func (g GitHub) FetchCommitsFromReleases(owner, repo string) (map[string]string, Releases struct { Nodes []struct { Tag struct { - Name string + Name string Target struct { Oid string } @@ -76,7 +76,7 @@ func (g GitHub) FetchCommitsFromReleases(owner, repo string) (map[string]string, return releaseSHAs, nil } -func (g GitHub) FetchLatestReleaseCommitFromBranch(owner, repo, branch string, releaseSHAs map[string]string) (string, error) { +func (g GitHub) FetchLatestReleaseCommitFromBranch(owner, repo, branch, versionToRelease string, releaseSHAs map[string]string) (string, error) { var commitsQuery struct { Repository struct { Ref struct { @@ -115,10 +115,15 @@ func (g GitHub) FetchLatestReleaseCommitFromBranch(owner, repo, branch string, r for _, commit := range history.Nodes { lastCommit = commit.Oid - // Skips over any patch releases. This is so that we will always start - // fetching commits from the last major or minor release. - if releaseName, found := releaseSHAs[commit.Oid]; found && !isPatchRelease(releaseName) { - return commit.Oid, nil + // If release-version is a Patch then don't skip patch releases + if previousRelease, found := releaseSHAs[commit.Oid]; found { + if isPatchRelease(versionToRelease) { + return commit.Oid, nil + } else { //Major/Minor skip patch releases + if !isPatchRelease(previousRelease) { + return commit.Oid, nil + } + } } }