Skip to content

Commit

Permalink
add comments to generate cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Fu <[email protected]>
Co-authored-by: James Thomson <[email protected]>
  • Loading branch information
clarafu and James Thomson committed Nov 2, 2020
1 parent 2628521 commit 1e4e884
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,51 @@ func generateReleaseNote(cmd *cobra.Command, args []string) {
githubOwner, _ := cmd.Flags().GetString("github-owner")
githubRepo, _ := cmd.Flags().GetString("github-repo")

// 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)
}

githubBranch, _ := cmd.Flags().GetString("github-branch")

// Starting from the latest commit on the branch, we want to walk backwards
// 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)
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
// commit SHA. If the pull request is already used for a patch release, it is
// not included.
pullRequests, err := client.FetchPullRequestsAfterCommit(githubOwner, githubRepo, githubBranch, startingCommitSHA, lastCommitSHA)
if err != nil {
failf("failed to fetch pull requests: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ 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) {
fmt.Println(releaseName)
return commit.Oid, nil
}
}
Expand Down

0 comments on commit 1e4e884

Please sign in to comment.