blob: 1701d90c8f7ac23275362c06876a36783e4c6f17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package com.getbootstrap.savage.server
import scala.util.{Failure, Success, Try}
import org.eclipse.egit.github.core.service.IssueService
import com.getbootstrap.savage.github.{GitHubActorWithLogging, PullRequestNumber}
import com.getbootstrap.savage.PullRequestBuildResult
class PullRequestCommenter extends GitHubActorWithLogging {
private def tryToCommentOn(prNum: PullRequestNumber, commentMarkdown: String) = {
val issueService = new IssueService(gitHubClient)
Try { issueService.createComment(settings.MainRepoId, prNum.number, commentMarkdown) }
}
override def receive = {
case PullRequestBuildResult(prNum, commitSha, buildUrl, succeeded) => {
val mythicalStatus = if (succeeded) { "**CONFIRMED**" } else { "**BUSTED**" }
val plainStatus = if (succeeded) { "**Tests passed.**" } else { "**Tests failed.**" }
val previewInfo = if (settings.ShowPreviewUrls) { "Docs preview: http://preview.twbsapps.com/c/${commitSha.sha}" } else { "" }
val commentMarkdown = s"""
|${plainStatus} Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: ${mythicalStatus}
|
|Commit: ${commitSha.sha}
|Build details: ${buildUrl}
|${previewInfo}
|
|(*Please note that this is a [fully automated](https://github.com/twbs/savage) comment.*)
""".stripMargin
tryToCommentOn(prNum, commentMarkdown) match {
case Success(comment) => log.info(s"Successfully posted comment ${comment.getUrl} for ${prNum}")
case Failure(exc) => log.error(exc, s"Error posting comment for ${prNum}")
}
}
}
}
|