@@ -66,11 +66,12 @@ var scheduledPrReminders = &cobra.Command{
66
66
return fmt .Errorf ("did not provide GITHUB_TOKEN environment variable" )
67
67
}
68
68
gh := github .NewClient (nil ).WithAuthToken (githubToken )
69
- return execScheduledPrReminders (gh )
69
+ mgh := membership .NewClient (githubToken )
70
+ return execScheduledPrReminders (gh , mgh )
70
71
},
71
72
}
72
73
73
- func execScheduledPrReminders (gh * github.Client ) error {
74
+ func execScheduledPrReminders (gh * github.Client , mgh GithubClient ) error {
74
75
ctx := context .Background ()
75
76
opt := & github.PullRequestListOptions {
76
77
State : "open" ,
@@ -165,7 +166,14 @@ func execScheduledPrReminders(gh *github.Client) error {
165
166
)
166
167
sinceDays := businessDaysDiff (since , time .Now ())
167
168
if shouldNotify (pr , state , sinceDays ) {
168
- comment , err := formatReminderComment (pr , state , sinceDays )
169
+ // Determine the current primary reviewer.
170
+ comments , err := mgh .GetPullRequestComments (fmt .Sprintf ("%d" , * pr .Number ))
171
+ if err != nil {
172
+ return err
173
+ }
174
+ _ , currentReviewer := membership .FindReviewerComment (comments )
175
+
176
+ reminderComment , err := formatReminderComment (pr , state , sinceDays , currentReviewer )
169
177
if err != nil {
170
178
fmt .Printf (
171
179
"%d/%d: PR %d: error rendering comment: %s\n " ,
@@ -177,15 +185,15 @@ func execScheduledPrReminders(gh *github.Client) error {
177
185
continue
178
186
}
179
187
if dryRun {
180
- fmt .Printf ("DRY RUN: Would post comment: %s\n " , comment )
188
+ fmt .Printf ("DRY RUN: Would post comment: %s\n " , reminderComment )
181
189
} else {
182
190
_ , _ , err := gh .Issues .CreateComment (
183
191
ctx ,
184
192
"GoogleCloudPlatform" ,
185
193
"magic-modules" ,
186
194
* pr .Number ,
187
195
& github.IssueComment {
188
- Body : github .String (comment ),
196
+ Body : github .String (reminderComment ),
189
197
},
190
198
)
191
199
if err != nil {
@@ -433,7 +441,7 @@ func shouldNotify(pr *github.PullRequest, state pullRequestReviewState, sinceDay
433
441
return false
434
442
}
435
443
436
- func formatReminderComment (pullRequest * github.PullRequest , state pullRequestReviewState , sinceDays int ) (string , error ) {
444
+ func formatReminderComment (pullRequest * github.PullRequest , state pullRequestReviewState , sinceDays int , currentReviewer string ) (string , error ) {
437
445
embeddedTemplate := ""
438
446
switch state {
439
447
case waitingForMerge :
@@ -454,11 +462,15 @@ func formatReminderComment(pullRequest *github.PullRequest, state pullRequestRev
454
462
panic (fmt .Sprintf ("Unable to parse template for %s: %s" , state .String (), err ))
455
463
}
456
464
457
- coreReviewers := []string {}
458
- for _ , reviewer := range pullRequest .RequestedReviewers {
459
- if membership .IsCoreReviewer (* reviewer .Login ) {
460
- coreReviewers = append (coreReviewers , * reviewer .Login )
465
+ var coreReviewers []string
466
+ if currentReviewer == "" {
467
+ for _ , reviewer := range pullRequest .RequestedReviewers {
468
+ if membership .IsCoreReviewer (* reviewer .Login ) {
469
+ coreReviewers = append (coreReviewers , * reviewer .Login )
470
+ }
461
471
}
472
+ } else {
473
+ coreReviewers = append (coreReviewers , currentReviewer )
462
474
}
463
475
464
476
data := reminderCommentData {
0 commit comments