Skip to content

Commit

Permalink
add logic around when to start fetching prs for generate
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Clara Fu <[email protected]>
  • Loading branch information
taylorsilva and clarafu committed Nov 5, 2020
1 parent 1e4e884 commit 1b4f416
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
27 changes: 4 additions & 23 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
17 changes: 11 additions & 6 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
}

Expand Down

0 comments on commit 1b4f416

Please sign in to comment.