aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorOlivier Blanvillain <olivier.blanvillain@gmail.com>2017-02-13 10:08:01 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-02-13 10:53:46 +0100
commit35337eabfa00eb3db09438623aaf825076121ff1 (patch)
tree8a02617989018118f807c5af54a1641b81b50e17 /bot
parentc1836497af19e809ffb60017b28416a68467fa10 (diff)
downloaddotty-35337eabfa00eb3db09438623aaf825076121ff1.tar.gz
dotty-35337eabfa00eb3db09438623aaf825076121ff1.tar.bz2
dotty-35337eabfa00eb3db09438623aaf825076121ff1.zip
Use `.pure` at use site instead of warpping with Task.now
Diffstat (limited to 'bot')
-rw-r--r--bot/src/dotty/tools/bot/PullRequestService.scala27
-rw-r--r--bot/test/PRServiceTests.scala1
2 files changed, 17 insertions, 11 deletions
diff --git a/bot/src/dotty/tools/bot/PullRequestService.scala b/bot/src/dotty/tools/bot/PullRequestService.scala
index 1d215cb4f..c0745acc8 100644
--- a/bot/src/dotty/tools/bot/PullRequestService.scala
+++ b/bot/src/dotty/tools/bot/PullRequestService.scala
@@ -5,6 +5,7 @@ import org.http4s.client.blaze._
import org.http4s.client.Client
import org.http4s.headers.Authorization
+import cats.syntax.applicative._
import scalaz.concurrent.Task
import scala.util.control.NonFatal
@@ -17,6 +18,15 @@ import org.http4s.util._
import model.Github._
+object TaskIsApplicative {
+ implicit val taskIsApplicative = new cats.Applicative[Task] {
+ def pure[A](x: A): Task[A] = Task.now(x)
+ def ap[A, B](ff: Task[A => B])(fa: Task[A]): Task[B] =
+ for(f <- ff; a <- fa) yield f(a)
+ }
+}
+import TaskIsApplicative._
+
trait PullRequestService {
/** Username for authorized admin */
@@ -55,17 +65,14 @@ trait PullRequestService {
def toUri(url: String): Task[Uri] =
Uri.fromString(url).fold(Task.fail, Task.now)
- def getRequest(endpoint: Uri): Task[Request] = Task.now {
+ def getRequest(endpoint: Uri): Request =
Request(uri = endpoint, method = Method.GET).putHeaders(authHeader)
- }
- def postRequest(endpoint: Uri): Task[Request] = Task.now {
+ def postRequest(endpoint: Uri): Request =
Request(uri = endpoint, method = Method.POST).putHeaders(authHeader)
- }
- def shutdownClient(client: Client): Task[Unit] = Task.now {
+ def shutdownClient(client: Client): Unit =
client.shutdownNow()
- }
sealed trait CommitStatus {
def commit: Commit
@@ -81,7 +88,7 @@ trait PullRequestService {
def checkUser(user: String, commit: Commit): Task[CommitStatus] = {
val claStatus = for {
endpoint <- toUri(claUrl(user))
- claReq <- getRequest(endpoint)
+ claReq <- getRequest(endpoint).pure[Task]
claRes <- httpClient.expect(claReq)(jsonOf[CLASignature])
res = if (claRes.signed) Valid(user, commit) else Invalid(user, commit)
} yield res
@@ -127,7 +134,7 @@ trait PullRequestService {
for {
endpoint <- toUri(statusUrl(cm.commit.sha))
- req <- postRequest(endpoint).map(_.withBody(stat.asJson))
+ req <- postRequest(endpoint).withBody(stat.asJson).pure[Task]
res <- httpClient.expect(req)(jsonOf[StatusResponse])
} yield res
}
@@ -152,7 +159,7 @@ trait PullRequestService {
def makeRequest(url: String): Task[List[Commit]] =
for {
endpoint <- toUri(url)
- req <- getRequest(endpoint)
+ req <- getRequest(endpoint).pure[Task]
res <- httpClient.fetch(req){ res =>
val link = CaseInsensitiveString("Link")
val next = findNext(res.headers.get(link)).map(makeRequest).getOrElse(Task.now(Nil))
@@ -176,7 +183,7 @@ trait PullRequestService {
// Send statuses to Github and exit
_ <- sendStatuses(statuses, httpClient)
- _ <- shutdownClient(httpClient)
+ _ <- shutdownClient(httpClient).pure[Task]
resp <- Ok("All statuses checked")
} yield resp
}
diff --git a/bot/test/PRServiceTests.scala b/bot/test/PRServiceTests.scala
index 202c721e6..08155d59d 100644
--- a/bot/test/PRServiceTests.scala
+++ b/bot/test/PRServiceTests.scala
@@ -21,7 +21,6 @@ class PRServiceTests extends PullRequestService {
.map(_.mkString)
.getOrElse(throw new Exception(s"resource not found: $r"))
-
@Test def canUnmarshalIssueJson = {
val json = getResource("/test-pr.json")
val issue: Issue = decode[Issue](json) match {