@@ -117,17 +117,44 @@ 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 will only notify the first 50 handles in a single comment
121+ const mentionLimit = 50
122+
123+ // i counts from 0 to len(handles)
124+ // Use (i % mentionLimit) to limit each comment to containing
125+ // at most (mentionLimit) handles
126+ i := 0
127+
128+ totalBatches := (len (handles ) + mentionLimit - 1 ) / mentionLimit
129+
130+ var body string
131+
121132 for handle , ports := range handles {
133+ // Increment counter for each handle
134+ i ++
135+
136+ // Initialize body if first handle for this batch
137+ if (i % mentionLimit ) == 1 {
138+ currentBatch := (i + mentionLimit - 1 ) / mentionLimit
139+ body = "Notifying maintainers (batch " + strconv .Itoa (currentBatch ) +
140+ " of " + strconv .Itoa (totalBatches ) + "):\n "
141+ }
142+
122143 body += mentionSymbol + handle + " for port " + strings .Join (ports , ", " ) + ".\n "
123144 err = receiver .githubClient .AddAssignees (owner , repo , number , []string {handle })
124145 if err != nil {
125146 log .Println (err )
126147 }
127- }
128- err = receiver .githubClient .CreateComment (owner , repo , number , & body )
129- if err != nil {
130- log .Println (err )
148+
149+ // Create comment if last handle for this batch
150+ // (either once body contains (mentionLimit) handles,
151+ // or when there are no handles left)
152+ if ((i % mentionLimit ) == 0 ) || (i == len (handles )) {
153+ err = receiver .githubClient .CreateComment (owner , repo , number , & body )
154+ if err != nil {
155+ log .Println (err )
156+ }
157+ }
131158 }
132159 }
133160
0 commit comments