changed PR collection logic for release notes
@@ -19,10 +19,6 @@ package main
import (
"context"
"fmt"
- "os"
- "regexp"
- "strconv"
-
"github.com/google/go-github/github"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -59,32 +55,34 @@ func main() {
func printPullRequests() {
client := getClient()
- if len(fromTag) == 0 {
- tags, _, _ := client.Repositories.ListTags(context.Background(), org, repo, &github.ListOptions{})
- fromTag = tags[0].GetName()
- }
-
- fmt.Println(fmt.Sprintf("Collecting PR commits between %s and %s...", fromTag, toTag))
- fmt.Println("---------")
-
- comparison := commits(client)
-
- repositoryCommits := comparison.Commits
+ releases, _, _ := client.Repositories.ListReleases(context.Background(), org, repo, &github.ListOptions{})
+ lastReleaseTime := *releases[0].PublishedAt
+ fmt.Println(fmt.Sprintf("Collecting pull request that were merged since the last release: %s (%s)", *releases[0].TagName, lastReleaseTime))
+
+ listSize := 1
+ for page := 0; listSize > 0; page++ {
+ pullRequests, _, _ := client.PullRequests.List(context.Background(), org, repo, &github.PullRequestListOptions{
+ State: "closed",
+ Sort: "updated",
+ Direction: "desc",
+ ListOptions: github.ListOptions{
+ PerPage: 100,
+ Page: page,
+ },
+ })
- re := regexp.MustCompile("Merge pull request #(.*) from.*")
- for idx := range repositoryCommits {
- commit := repositoryCommits[idx]
- msg := *commit.Commit.Message
- match := re.FindStringSubmatch(msg)
- if match == nil {
- continue
+ for idx := range pullRequests {
+ pr := pullRequests[idx]
+ if pr.MergedAt != nil {
+ if pr.GetMergedAt().After(lastReleaseTime.Time) {
+ fmt.Printf("* %s [#%d](https://github.com/%s/%s/pull/%d)\n", pr.GetTitle(), *pr.Number, org, repo, *pr.Number)
}
- prID, _ := strconv.Atoi(match[1])
- pullRequest, _, _ := client.PullRequests.Get(context.Background(), org, repo, prID)
- fmt.Printf("* %s [#%d](https://github.com/%s/%s/pull/%d)\n", pullRequest.GetTitle(), prID, org, repo, prID)
}
}
+ listSize = len(pullRequests)
+ }}
+
func getClient() *github.Client {
if len(token) <= 0 {
return github.NewClient(nil)
@@ -97,11 +95,3 @@ func getClient() *github.Client {
return github.NewClient(tc)
}
-func commits(client *github.Client) *github.CommitsComparison {
- commits, resp, e := client.Repositories.CompareCommits(context.Background(), org, repo, fromTag, toTag)
- if e != nil {
- fmt.Println(fmt.Errorf("error %s, %s", e, resp))
- os.Exit(1)
- }
- return commits
-}
