@@ -103,6 +103,9 @@ trait PullRequestService {
103
103
def reviewUrl (issueNbr : Int ): String =
104
104
withGithubSecret(s " $githubUrl/repos/lampepfl/dotty/pulls/ $issueNbr/reviews " )
105
105
106
+ def contributorsUrl : String =
107
+ withGithubSecret(" https://api.github.com/repos/lampepfl/dotty/contributors" )
108
+
106
109
sealed trait CommitStatus {
107
110
def commit : Commit
108
111
def isValid : Boolean
@@ -183,6 +186,13 @@ trait PullRequestService {
183
186
.headOption
184
187
}
185
188
189
+ /** Get all contributors from GitHub */
190
+ def getContributors (implicit client : Client ): Task [Set [String ]] =
191
+ for {
192
+ authors <- client.expect(get(contributorsUrl))(jsonOf[List [Author ]])
193
+ logins = authors.map(_.login).flatten
194
+ } yield logins.toSet
195
+
186
196
/** Ordered from earliest to latest */
187
197
def getCommits (issueNbr : Int )(implicit httpClient : Client ): Task [List [Commit ]] = {
188
198
def makeRequest (url : String ): Task [List [Commit ]] =
@@ -226,8 +236,11 @@ trait PullRequestService {
226
236
wrongTense || firstLine.last == '.' || firstLine.length > 80
227
237
}
228
238
229
- def sendInitialComment (issueNbr : Int , invalidUsers : List [String ], commits : List [Commit ], client : Client ): Task [ReviewResponse ] = {
230
-
239
+ /** Returns the body of a `ReviewResponse` */
240
+ def sendInitialComment (issueNbr : Int ,
241
+ invalidUsers : List [String ],
242
+ commits : List [Commit ],
243
+ newContributors : Boolean )(implicit client : Client ): Task [String ] = {
231
244
val cla = if (invalidUsers.nonEmpty) {
232
245
s """ |## CLA ##
233
246
|In order for us to be able to accept your contribution, all users
@@ -272,9 +285,16 @@ trait PullRequestService {
272
285
273
286
val review = Review .comment(body)
274
287
288
+ val shouldPost = newContributors || commitRules.nonEmpty || invalidUsers.nonEmpty
289
+
275
290
for {
276
291
req <- post(reviewUrl(issueNbr)).withAuth(githubUser, githubToken)
277
- res <- client.expect(req.withBody(review.asJson))(jsonOf[ReviewResponse ])
292
+ res <- {
293
+ if (shouldPost)
294
+ client.expect(req.withBody(review.asJson))(jsonOf[ReviewResponse ]).map(_.body)
295
+ else
296
+ Task .now(" " )
297
+ }
278
298
} yield res
279
299
}
280
300
@@ -299,10 +319,12 @@ trait PullRequestService {
299
319
setStatus(statuses.last, httpClient)
300
320
}
301
321
302
- // Send positive comment:
303
- _ <- sendInitialComment(issue.number, invalidUsers, commits, httpClient)
304
- _ <- httpClient.shutdown
305
- resp <- Ok (" Fresh PR checked" )
322
+ authors = commits.map(_.author.login).flatten.toSet
323
+ contribs <- getContributors
324
+ newContr = ! authors.forall(contribs.contains)
325
+ _ <- sendInitialComment(issue.number, invalidUsers, commits, newContr)
326
+ _ <- httpClient.shutdown
327
+ resp <- Ok (" Fresh PR checked" )
306
328
} yield resp
307
329
308
330
}
0 commit comments