Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/savage.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <code@rebertia.com>2015-03-05 13:25:49 +0300
committerChris Rebert <code@rebertia.com>2015-03-05 13:25:49 +0300
commit6a5f1a2ef5ab8431ff8c06d607fa62af77589c5d (patch)
tree77fe1252cf8ac66d9bd779f2b81e63310a9eb572
parented525d687fac7749cea6b1c73902e83330f5a0fa (diff)
implement most of #11 but keep it neutered for now
-rw-r--r--src/main/scala/com/getbootstrap/savage/github/commit_status/Status.scala33
-rw-r--r--src/main/scala/com/getbootstrap/savage/github/commit_status/StatusForCommit.scala5
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/Boot.scala5
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/CommitStatusSetter.scala29
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala11
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala11
6 files changed, 88 insertions, 6 deletions
diff --git a/src/main/scala/com/getbootstrap/savage/github/commit_status/Status.scala b/src/main/scala/com/getbootstrap/savage/github/commit_status/Status.scala
new file mode 100644
index 0000000..41b2101
--- /dev/null
+++ b/src/main/scala/com/getbootstrap/savage/github/commit_status/Status.scala
@@ -0,0 +1,33 @@
+package com.getbootstrap.savage.github.commit_status
+
+import org.eclipse.egit.github.core.{CommitStatus => RawCommitStatus}
+
+object Status {
+ private val context = "continuous-integration/savage"
+}
+trait Status {
+ def description: String
+ protected def githubState: String
+ def asRawStatus: RawCommitStatus = {
+ // FIXME: set context too
+ // FIXME: set targetUrl when available
+ new RawCommitStatus().setState(githubState).setDescription(description + Status.context)
+ }
+ def name: String
+}
+case class Success(description: String) extends Status {
+ override def githubState = RawCommitStatus.STATE_SUCCESS
+ override def name = "Success"
+}
+case class Failure(description: String) extends Status {
+ override def githubState = RawCommitStatus.STATE_FAILURE
+ override def name = "Failure"
+}
+case class Error(description: String) extends Status {
+ override def githubState = RawCommitStatus.STATE_ERROR
+ override def name = "Error"
+}
+case class Pending(description: String) extends Status {
+ override def githubState = RawCommitStatus.STATE_PENDING
+ override def name = "Pending"
+}
diff --git a/src/main/scala/com/getbootstrap/savage/github/commit_status/StatusForCommit.scala b/src/main/scala/com/getbootstrap/savage/github/commit_status/StatusForCommit.scala
new file mode 100644
index 0000000..987e325
--- /dev/null
+++ b/src/main/scala/com/getbootstrap/savage/github/commit_status/StatusForCommit.scala
@@ -0,0 +1,5 @@
+package com.getbootstrap.savage.github.commit_status
+
+import com.getbootstrap.savage.github.CommitSha
+
+case class StatusForCommit(commit: CommitSha, status: Status)
diff --git a/src/main/scala/com/getbootstrap/savage/server/Boot.scala b/src/main/scala/com/getbootstrap/savage/server/Boot.scala
index 26894eb..bcd3a9e 100644
--- a/src/main/scala/com/getbootstrap/savage/server/Boot.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/Boot.scala
@@ -35,10 +35,11 @@ object Boot extends App {
// import actorSystem.dispatcher
val deleter = system.actorOf(SmallestMailboxPool(3).props(Props(classOf[BranchDeleter])), "branch-deleters")
+ val statusSetters = system.actorOf(SmallestMailboxPool(3).props(Props(classOf[CommitStatusSetter])), "status-setters")
val commenter = system.actorOf(SmallestMailboxPool(3).props(Props(classOf[PullRequestCommenter])), "gh-pr-commenters")
val pusher = system.actorOf(Props(classOf[PullRequestPusher]), "pr-pusher")
- val prHandlers = system.actorOf(SmallestMailboxPool(3).props(Props(classOf[PullRequestEventHandler], pusher)), "pr-handlers")
- val webService = system.actorOf(Props(classOf[SavageWebService], prHandlers, commenter, deleter), "savage-service")
+ val prHandlers = system.actorOf(SmallestMailboxPool(3).props(Props(classOf[PullRequestEventHandler], pusher, statusSetters)), "pr-handlers")
+ val webService = system.actorOf(Props(classOf[SavageWebService], prHandlers, commenter, deleter, statusSetters), "savage-service")
implicit val timeout = Timeout(15.seconds)
IO(Http) ? Http.Bind(webService, interface = "0.0.0.0", port = port.getOrElse(settings.DefaultPort))
diff --git a/src/main/scala/com/getbootstrap/savage/server/CommitStatusSetter.scala b/src/main/scala/com/getbootstrap/savage/server/CommitStatusSetter.scala
new file mode 100644
index 0000000..58b393e
--- /dev/null
+++ b/src/main/scala/com/getbootstrap/savage/server/CommitStatusSetter.scala
@@ -0,0 +1,29 @@
+package com.getbootstrap.savage.server
+
+import scala.util.{Try,Success,Failure}
+import org.eclipse.egit.github.core.{CommitStatus=>RawCommitStatus}
+import org.eclipse.egit.github.core.service.CommitService
+import com.getbootstrap.savage.github.commit_status.StatusForCommit
+import com.getbootstrap.savage.github.GitHubActorWithLogging
+
+class CommitStatusSetter extends GitHubActorWithLogging {
+ def tryToSetCommitStatus(commitStatus: StatusForCommit): Try[RawCommitStatus] = {
+ val commitService = new CommitService(gitHubClient)
+ val commitSha = commitStatus.commit.sha
+ val status = commitStatus.status.asRawStatus
+ Try { commitService.createStatus(settings.MainRepoId, commitSha, status) }
+ }
+
+ override def receive = {
+ case commitStatus@StatusForCommit(commit, status) => {
+ if (false) {
+ tryToSetCommitStatus(commitStatus) match {
+ case Success(createdCommitStatus) => {
+ log.info(s"Successfully set/created commit status ${createdCommitStatus.getUrl} with state ${status.name} for ${commit}")
+ }
+ case Failure(exc) => log.error(exc, s"Error setting ${commitStatus}")
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala b/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala
index 1a4ceff..9ea23a0 100644
--- a/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala
@@ -9,10 +9,13 @@ import org.eclipse.egit.github.core._
import org.eclipse.egit.github.core.service.{CommitService, OrganizationService, PullRequestService}
import com.getbootstrap.savage.github._
import com.getbootstrap.savage.github.util._
+import com.getbootstrap.savage.github.commit_status.StatusForCommit
import com.getbootstrap.savage.util.UnixFileSystemString
-class PullRequestEventHandler(protected val pusher: ActorRef) extends GitHubActorWithLogging {
-
+class PullRequestEventHandler(
+ protected val pusher: ActorRef,
+ protected val statusSetter: ActorRef
+) extends GitHubActorWithLogging {
private def affectedFilesFor(repoId: RepositoryId, base: CommitSha, head: CommitSha): Try[Set[Path]] = {
val commitService = new CommitService(gitHubClient)
Try { commitService.compare(repoId, base.sha, head.sha) }.map { comparison =>
@@ -110,6 +113,10 @@ class PullRequestEventHandler(protected val pusher: ActorRef) extends GitHubActo
number = pr.number,
commitSha = headSha
)
+ statusSetter ! StatusForCommit(
+ status = commit_status.Pending("Savage has initiated its special separate Travis CI build"),
+ commit = headSha
+ )
}
else {
logPrInfo(s"Ignoring PR with no interesting file changes")
diff --git a/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala b/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala
index a300ff4..2f81f6d 100644
--- a/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala
@@ -5,12 +5,13 @@ import akka.actor.ActorRef
import spray.routing._
import spray.http._
import com.getbootstrap.savage.PullRequestBuildResult
-import com.getbootstrap.savage.github.{BranchDeletionRequest, PullRequestNumber}
+import com.getbootstrap.savage.github.{BranchDeletionRequest, PullRequestNumber, commit_status}
class SavageWebService(
protected val pullRequestEventHandler: ActorRef,
protected val pullRequestCommenter: ActorRef,
- protected val branchDeleter: ActorRef
+ protected val branchDeleter: ActorRef,
+ protected val statusSetter: ActorRef
) extends ActorWithLogging with HttpService {
import GitHubWebHooksDirectives.{authenticatedPullRequestEvent,authenticatedIssueOrCommentEvent}
import TravisWebHookDirectives.authenticatedTravisEvent
@@ -73,6 +74,12 @@ class SavageWebService(
case Failure(exc) => log.error(exc, s"Invalid Savage branch name from Travis event: ${event.branchName}")
case Success(prNum) => {
branchDeleter ! BranchDeletionRequest(event.branchName, event.commitSha)
+ val commitStatus = if (event.status.isSuccessful) {
+ commit_status.Success("CONFIRMED: Savage cross-browser JS testing passed")
+ } else {
+ commit_status.Failure("BUSTED: Savage cross-browser JS testing failed")
+ }
+ statusSetter ! commitStatus
pullRequestCommenter ! PullRequestBuildResult(
prNum = prNum,
commitSha = event.commitSha,