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:
Diffstat (limited to 'src/main/scala/com/getbootstrap/savage/server')
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala68
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/Settings.scala2
2 files changed, 38 insertions, 32 deletions
diff --git a/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala b/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala
index 746a8fa..904e7a2 100644
--- a/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/PullRequestEventHandler.scala
@@ -89,48 +89,52 @@ class PullRequestEventHandler(
destinationRepo match {
case None => log.error(s"Received event from GitHub about irrelevant repository with unsafe name")
case Some(settings.MainRepoId) => {
- val destBranch = bsBase.getRef
- destBranch match {
- case "master" => {
- prHead.getRepo.repositoryId match {
- case None => log.error(s"Received event from GitHub about repository with unsafe name")
- case Some(settings.MainRepoId) if settings.IgnoreBranchesFromMainRepo => log.info("Ignoring PR whose branch is from the main repo, per settings.")
- case Some(foreignRepo) => {
- val baseSha = bsBase.commitSha
- val headSha = prHead.commitSha
+ bsBase.branch match {
+ case None => logPrInfo(s"Ignoring since PR targets the unsafely-named ${bsBase.getRef} branch")
+ case Some(destBranch) => {
+ if (settings.AllowedBaseBranches.contains(destBranch)) {
+ prHead.getRepo.repositoryId match {
+ case None => log.error(s"Received event from GitHub about repository with unsafe name")
+ case Some(settings.MainRepoId) if settings.IgnoreBranchesFromMainRepo => log.info("Ignoring PR whose branch is from the main repo, per settings.")
+ case Some(foreignRepo) => {
+ val baseSha = bsBase.commitSha
+ val headSha = prHead.commitSha
- affectedFilesFor(foreignRepo, baseSha, headSha) match {
- case Failure(exc) => {
- log.error(exc, s"Could not get affected files for commits ${baseSha}...${headSha} for ${foreignRepo}")
- }
- case Success(affectedFiles) => {
- log.debug("Files affected by {}: {}", prNum, affectedFiles)
- if (areSafe(affectedFiles)) {
- if (areInteresting(affectedFiles)) {
- logPrInfo(s"Requesting build for safe & interesting PR")
- pusher ! PullRequestPushRequest(
- origin = foreignRepo,
- number = pr.number,
- commitSha = headSha
- )
- statusSetter ! StatusForCommit(
- status = commit_status.Pending("Savage has initiated its special separate Travis CI build"),
- commit = headSha
- )
+ affectedFilesFor(foreignRepo, baseSha, headSha) match {
+ case Failure(exc) => {
+ log.error(exc, s"Could not get affected files for commits ${baseSha}...${headSha} for ${foreignRepo}")
+ }
+ case Success(affectedFiles) => {
+ log.debug("Files affected by {}: {}", prNum, affectedFiles)
+ if (areSafe(affectedFiles)) {
+ if (areInteresting(affectedFiles)) {
+ logPrInfo(s"Requesting build for safe & interesting PR")
+ pusher ! PullRequestPushRequest(
+ origin = foreignRepo,
+ 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")
+ }
}
else {
- logPrInfo(s"Ignoring PR with no interesting file changes")
+ logPrInfo(s"Ignoring PR with unsafe file changes")
}
}
- else {
- logPrInfo(s"Ignoring PR with unsafe file changes")
- }
}
}
}
}
+ else {
+ logPrInfo(s"Ignoring since PR targets the ${destBranch} branch")
+ }
}
- case _ => logPrInfo(s"Ignoring since PR targets the ${destBranch} branch")
}
}
case Some(otherRepo) => log.error(s"Received event from GitHub about irrelevant repository: ${otherRepo}")
diff --git a/src/main/scala/com/getbootstrap/savage/server/Settings.scala b/src/main/scala/com/getbootstrap/savage/server/Settings.scala
index d01c62d..a5e2020 100644
--- a/src/main/scala/com/getbootstrap/savage/server/Settings.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/Settings.scala
@@ -10,6 +10,7 @@ import akka.actor.ExtensionIdProvider
import akka.actor.ExtendedActorSystem
import akka.util.ByteString
import org.eclipse.egit.github.core.RepositoryId
+import com.getbootstrap.savage.github.Branch
import com.getbootstrap.savage.util.{FilePathWhitelist,FilePathWatchlist,Utf8String,RichConfig}
class SettingsImpl(config: Config) extends Extension {
@@ -26,6 +27,7 @@ class SettingsImpl(config: Config) extends Extension {
val Watchlist: FilePathWatchlist = new FilePathWatchlist(config.getStringList("savage.file-watchlist").asScala)
val BranchPrefix: String = config.getString("savage.branch-prefix")
val IgnoreBranchesFromMainRepo: Boolean = config.getBoolean("savage.ignore-branches-from-watched-repo")
+ val AllowedBaseBranches: Set[Branch] = config.getStringList("savage.allowed-base-branches").asScala.flatMap{ Branch(_) }.toSet
val TrustedOrganizations: Set[String] = config.getStringList("savage.trusted-orgs").asScala.toSet
val SetCommitStatus: Boolean = config.getBoolean("savage.set-commit-status")
val TravisTimeout: FiniteDuration = config.getFiniteDuration("savage.travis-timeout")