diff options
author | Olivier Blanvillain <olivier.blanvillain@gmail.com> | 2017-02-13 10:08:40 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-02-13 10:53:46 +0100 |
commit | dea3d5e2e32587c378353c9ba326fc50cc6e5a13 (patch) | |
tree | d14b8239f2fdd4112f93026fce05a49c85df63f3 /bot/src/dotty | |
parent | 35337eabfa00eb3db09438623aaf825076121ff1 (diff) | |
download | dotty-dea3d5e2e32587c378353c9ba326fc50cc6e5a13.tar.gz dotty-dea3d5e2e32587c378353c9ba326fc50cc6e5a13.tar.bz2 dotty-dea3d5e2e32587c378353c9ba326fc50cc6e5a13.zip |
Only make one request per author
Diffstat (limited to 'bot/src/dotty')
-rw-r--r-- | bot/src/dotty/tools/bot/PullRequestService.scala | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/bot/src/dotty/tools/bot/PullRequestService.scala b/bot/src/dotty/tools/bot/PullRequestService.scala index c0745acc8..5ae0b37d0 100644 --- a/bot/src/dotty/tools/bot/PullRequestService.scala +++ b/bot/src/dotty/tools/bot/PullRequestService.scala @@ -8,6 +8,7 @@ import org.http4s.headers.Authorization import cats.syntax.applicative._ import scalaz.concurrent.Task import scala.util.control.NonFatal +import scala.Function.tupled import io.circe._ import io.circe.generic.auto._ @@ -85,34 +86,32 @@ trait PullRequestService { /** Partitions invalid and valid commits */ def checkCLA(xs: List[Commit], httpClient: Client): Task[List[CommitStatus]] = { - def checkUser(user: String, commit: Commit): Task[CommitStatus] = { + def checkUser(user: String): Task[Commit => CommitStatus] = { val claStatus = for { endpoint <- toUri(claUrl(user)) claReq <- getRequest(endpoint).pure[Task] claRes <- httpClient.expect(claReq)(jsonOf[CLASignature]) - res = if (claRes.signed) Valid(user, commit) else Invalid(user, commit) - } yield res + } yield { (commit: Commit) => + if (claRes.signed) Valid(user, commit) + else Invalid(user, commit) + } claStatus.handleWith { case NonFatal(e) => println(e) - Task.now(CLAServiceDown(user, commit)) + Task.now((commit: Commit) => CLAServiceDown(user, commit)) } } - def checkCommit(commit: Commit, author: Author): Task[CommitStatus] = - author.login.map(checkUser(_, commit)).getOrElse(Task.now(MissingUser(commit))) + def checkCommit(author: Author, commit: List[Commit]): Task[List[CommitStatus]] = + author.login.map(checkUser) + .getOrElse(Task.now(MissingUser)) + .map(f => commit.map(f)) Task.gatherUnordered { - xs.flatMap { - case c @ Commit(_, author, commiter, _) => - if (author == commiter) List(checkCommit(c, author)) - else List( - checkCommit(c, author), - checkCommit(c, commiter) - ) - } - } + val groupedByAuthor: Map[Author, List[Commit]] = xs.groupBy(_.author) + groupedByAuthor.map(tupled(checkCommit)).toList + }.map(_.flatten) } def sendStatuses(xs: List[CommitStatus], httpClient: Client): Task[List[StatusResponse]] = { @@ -176,15 +175,15 @@ trait PullRequestService { for { // First get all the commits from the PR - commits <- getCommits(issue.number, httpClient) + commits <- getCommits(issue.number, httpClient) // Then check the CLA of each commit for both author and committer - statuses <- checkCLA(commits, httpClient) + statuses <- checkCLA(commits, httpClient) // Send statuses to Github and exit - _ <- sendStatuses(statuses, httpClient) - _ <- shutdownClient(httpClient).pure[Task] - resp <- Ok("All statuses checked") + _ <- sendStatuses(statuses, httpClient) + _ <- shutdownClient(httpClient).pure[Task] + resp <- Ok("All statuses checked") } yield resp } } |