@@ -32,7 +32,9 @@ import (
32
32
type githubFromToPRLister struct {
33
33
client * githubClient
34
34
fromRef , toRef ref
35
- branch string
35
+ // branch is optional. It helps optimize the PR query by restricting
36
+ // the results to PRs merged in the selected branch and in main
37
+ branch string
36
38
}
37
39
38
40
func newGithubFromToPRLister (repo string , fromRef , toRef ref , branch string ) * githubFromToPRLister {
@@ -44,8 +46,7 @@ func newGithubFromToPRLister(repo string, fromRef, toRef ref, branch string) *gi
44
46
}
45
47
}
46
48
47
- // listPRs queries the PRs merged in a branch after
48
- // the `fromRef` reference and before `toRef` (included).
49
+ // listPRs returns the PRs merged between `fromRef` and `toRef` (included).
49
50
func (l * githubFromToPRLister ) listPRs () ([]pr , error ) {
50
51
log .Printf ("Computing diff between %s and %s" , l .fromRef , l .toRef )
51
52
diff , err := l .client .getDiffAllCommits (l .fromRef .value , l .toRef .value )
@@ -83,19 +84,19 @@ func (l *githubFromToPRLister) listPRs() ([]pr, error) {
83
84
// any PRs entries not belonging to the computed diff
84
85
toDate := toCommit .Committer .Date .Add (1 * time .Minute )
85
86
86
- log .Printf ("Listing PRs from branch %s from %s to %s" , l . branch , fromDate , toDate )
87
+ log .Printf ("Listing PRs from %s to %s" , fromDate , toDate )
87
88
gPRs , err := l .client .listMergedPRs (fromDate , toDate , l .branch , "main" )
88
89
if err != nil {
89
90
return nil , err
90
91
}
91
92
92
93
log .Printf ("Found %d PRs in github" , len (gPRs ))
93
94
94
- prIDs := buildSetOfPrIDs (diff .Commits )
95
+ selectedPRNumbers := buildSetOfPRNumbers (diff .Commits )
95
96
96
97
prs := make ([]pr , 0 , len (gPRs ))
97
98
for _ , p := range gPRs {
98
- if _ , ok := prIDs [fmt .Sprintf ("%d" , p .Number )]; ! ok {
99
+ if _ , ok := selectedPRNumbers [fmt .Sprintf ("%d" , p .Number )]; ! ok {
99
100
continue
100
101
}
101
102
labels := make ([]string , 0 , len (p .Labels ))
@@ -111,24 +112,24 @@ func (l *githubFromToPRLister) listPRs() ([]pr, error) {
111
112
112
113
log .Printf ("%d PRs match the commits from the git diff" , len (prs ))
113
114
114
- if len (prs ) != len (prIDs ) {
115
- return nil , errors .Errorf ("expected %d PRs from commit list but only found %d" , len (prIDs ), len (prs ))
115
+ if len (prs ) != len (selectedPRNumbers ) {
116
+ return nil , errors .Errorf ("expected %d PRs from commit list but only found %d" , len (selectedPRNumbers ), len (prs ))
116
117
}
117
118
118
119
return prs , nil
119
120
}
120
121
121
122
var mergeCommitMessage = regexp .MustCompile (`(?m)^Merge pull request #(\d+) .*$` )
122
123
123
- func buildSetOfPrIDs (commits []githubCommitNode ) map [string ]struct {} {
124
- prIDs := make (map [string ]struct {})
124
+ func buildSetOfPRNumbers (commits []githubCommitNode ) map [string ]struct {} {
125
+ prNumbers := make (map [string ]struct {})
125
126
for _ , commit := range commits {
126
127
match := mergeCommitMessage .FindStringSubmatch (commit .Commit .Message )
127
128
if len (match ) != 2 {
128
129
continue
129
130
}
130
- prIDs [match [1 ]] = struct {}{}
131
+ prNumbers [match [1 ]] = struct {}{}
131
132
}
132
133
133
- return prIDs
134
+ return prNumbers
134
135
}
0 commit comments