Skip to content

Commit 726ae71

Browse files
committed
Make the bot check contributors before sending greeting
1 parent 81a0b53 commit 726ae71

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ trait PullRequestService {
103103
def reviewUrl(issueNbr: Int): String =
104104
withGithubSecret(s"$githubUrl/repos/lampepfl/dotty/pulls/$issueNbr/reviews")
105105

106+
def contributorsUrl: String =
107+
withGithubSecret("https://api.github.com/repos/lampepfl/dotty/contributors")
108+
106109
sealed trait CommitStatus {
107110
def commit: Commit
108111
def isValid: Boolean
@@ -183,6 +186,13 @@ trait PullRequestService {
183186
.headOption
184187
}
185188

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+
186196
/** Ordered from earliest to latest */
187197
def getCommits(issueNbr: Int)(implicit httpClient: Client): Task[List[Commit]] = {
188198
def makeRequest(url: String): Task[List[Commit]] =
@@ -299,10 +309,16 @@ trait PullRequestService {
299309
setStatus(statuses.last, httpClient)
300310
}
301311

302-
// Send positive comment:
303-
_ <- sendInitialComment(issue.number, invalidUsers, commits, httpClient)
304-
_ <- httpClient.shutdown
305-
resp <- Ok("Fresh PR checked")
312+
authors = commits.map(_.author.login).flatten.toSet
313+
contribs <- getContributors
314+
_ <- {
315+
if (!authors.forall(contribs.contains))
316+
sendInitialComment(issue.number, invalidUsers, commits, httpClient)
317+
else
318+
Task.now(())
319+
}
320+
_ <- httpClient.shutdown
321+
resp <- Ok("Fresh PR checked")
306322
} yield resp
307323

308324
}

0 commit comments

Comments
 (0)