Skip to content

Commit a082b9c

Browse files
authored
Merge pull request #2683 from dotty-staging/topic/bot-recheck-response
Make sure the bot responds to re-check instruction
2 parents b8398a3 + c51ec42 commit a082b9c

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

bot/src/dotty/tools/bot/PullRequestService.scala

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ trait PullRequestService {
117117
final case class InvalidPrevious(users: List[String], commit: Commit) extends CommitStatus { def isValid = false }
118118

119119
/** Partitions invalid and valid commits */
120-
def checkCLA(xs: List[Commit], httpClient: Client): Task[List[CommitStatus]] = {
120+
def checkCLA(xs: List[Commit])(implicit client: Client): Task[List[CommitStatus]] = {
121121
def checkUser(user: String): Task[Commit => CommitStatus] = {
122122
val claStatus = for {
123-
claRes <- httpClient.expect(get(claUrl(user)))(jsonOf[CLASignature])
123+
claRes <- client.expect(get(claUrl(user)))(jsonOf[CLASignature])
124124
} yield { (commit: Commit) =>
125125
if (claRes.signed) Valid(Some(user), commit)
126126
else Invalid(user, commit)
@@ -303,7 +303,7 @@ trait PullRequestService {
303303

304304
for {
305305
commits <- getCommits(issue.number)
306-
statuses <- checkCLA(commits, httpClient)
306+
statuses <- checkCLA(commits)
307307

308308
(validStatuses, invalidStatuses) = statuses.partition(_.isValid)
309309
invalidUsers = usersFromInvalid(invalidStatuses)
@@ -372,23 +372,41 @@ trait PullRequestService {
372372
.map(_.forall(identity))
373373

374374
def checkSynchronize(issue: Issue): Task[Response] = {
375-
implicit val httpClient = PooledHttp1Client()
375+
implicit val client = PooledHttp1Client()
376+
377+
def extractFailures(c: List[CommitStatus]): List[String] = c.collect {
378+
case Invalid(user, _) =>
379+
s"@$user hasn't signed the CLA"
380+
case MissingUser(commit) =>
381+
s"missing user for commit: ${commit.sha} - correct email associated with GitHub account?"
382+
case CLAServiceDown(user, _) =>
383+
s"couldn't fetch status for: $user"
384+
}
376385

377386
for {
378387
commits <- getCommits(issue.number)
379-
statuses <- checkCLA(commits, httpClient)
388+
statuses <- checkCLA(commits)
380389
invalid = statuses.filterNot(_.isValid)
381-
_ <- sendStatuses(invalid, httpClient)
382-
_ <- cancelBuilds(commits.dropRight(1))(httpClient)
390+
_ <- sendStatuses(invalid, client)
391+
_ <- cancelBuilds(commits.dropRight(1))
383392

384393
// Set final commit status based on `invalid`:
385394
_ <- {
386395
if (invalid.nonEmpty)
387-
setStatus(InvalidPrevious(usersFromInvalid(invalid), commits.last), httpClient)
396+
setStatus(InvalidPrevious(usersFromInvalid(invalid), commits.last), client)
388397
else
389-
setStatus(statuses.last, httpClient)
398+
setStatus(statuses.last, client)
390399
}
391-
_ <- httpClient.shutdown
400+
401+
// Send comment regarding recheck:
402+
comment =
403+
if (invalid.isEmpty) "All users have signed the CLA as far as I can tell! :tada:"
404+
else s"There are still some issues:\n\n- ${extractFailures(invalid).mkString("\n- ")}"
405+
406+
req <- post(issueCommentsUrl(issue.number)).withAuth(githubUser, githubToken)
407+
_ <- client.fetch(req.withBody(comment.asJson))(Task.now)
408+
409+
_ <- client.shutdown
392410
resp <- Ok("Updated PR checked")
393411
} yield resp
394412
}

0 commit comments

Comments
 (0)