Skip to content

Commit c915380

Browse files
committed
pr: Do not exceed GitHub comment mention limit
Fixes: https://trac.macports.org/ticket/63821
1 parent a79d1c8 commit c915380

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

pr/webhook/pull_request.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,26 @@ func (receiver *Receiver) processPullRequest(event *github.PullRequestEvent) {
117117
mentionSymbol = "@"
118118
}
119119
if len(handles) > 0 && !strings.Contains(*event.PullRequest.Body, "[skip notification]") {
120-
body := "Notifying maintainers:\n"
120+
// GitHub limits mentions to 50 per comment
121+
const MentionLimit := 50
122+
i := 0
123+
var body string
121124
for handle, ports := range handles {
125+
if i % MentionLimit == 0 {
126+
body = "Notifying maintainers:\n"
127+
}
122128
body += mentionSymbol + handle + " for port " + strings.Join(ports, ", ") + ".\n"
123129
err = receiver.githubClient.AddAssignees(owner, repo, number, []string{handle})
124130
if err != nil {
125131
log.Println(err)
126132
}
127-
}
128-
err = receiver.githubClient.CreateComment(owner, repo, number, &body)
129-
if err != nil {
130-
log.Println(err)
133+
i++
134+
if i % MentionLimit == 0 || i == len(handles) {
135+
err = receiver.githubClient.CreateComment(owner, repo, number, &body)
136+
if err != nil {
137+
log.Println(err)
138+
}
139+
}
131140
}
132141
}
133142

0 commit comments

Comments
 (0)