+pro enable validatePullRequest locally
This commit is contained in:
parent
55425e5ef3
commit
dd1bf6a1ee
3 changed files with 63 additions and 6 deletions
|
|
@ -65,6 +65,8 @@ object ValidatePullRequest extends AutoPlugin {
|
|||
val SourcePullIdJenkinsEnvVarName = "ghprbPullId" // used to obtain branch name in form of "pullreq/17397"
|
||||
val sourceBranch = settingKey[String]("Branch containing the changes of this PR")
|
||||
|
||||
val targetBranch = settingKey[String]("Target branch of this PR, defaults to `master`")
|
||||
|
||||
// asking github comments if this PR should be PLS BUILD ALL
|
||||
val githubEnforcedBuildAll = taskKey[Option[BuildMode]]("Checks via GitHub API if comments included the PLS BUILD ALL keyword")
|
||||
val buildAllKeyword = taskKey[Regex]("Magic phrase to be used to trigger building of the entire project instead of analysing dependencies")
|
||||
|
|
@ -97,6 +99,11 @@ object ValidatePullRequest extends AutoPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
def localTargetBranch: Option[String] = sys.env.get("PR_TARGET_BRANCH")
|
||||
def jenkinsTargetBranch: Option[String] = sys.env.get("ghprbTargetBranch")
|
||||
def runningOnJenkins: Boolean = jenkinsTargetBranch.isDefined
|
||||
def runningLocally: Boolean = !runningOnJenkins
|
||||
|
||||
override lazy val buildSettings = Seq(
|
||||
sourceBranch in Global in ValidatePR := {
|
||||
sys.env.get(SourceBranchEnvVarName) orElse
|
||||
|
|
@ -104,6 +111,14 @@ object ValidatePullRequest extends AutoPlugin {
|
|||
"HEAD"
|
||||
},
|
||||
|
||||
targetBranch in Global in ValidatePR := {
|
||||
(localTargetBranch, jenkinsTargetBranch) match {
|
||||
case (Some(local), _) => local // local override
|
||||
case (None, Some(branch)) => s"origin/$branch" // usually would be "master" or "release-2.3" etc
|
||||
case (None, None) => "origin/master" // defaulting to diffing with "master"
|
||||
}
|
||||
},
|
||||
|
||||
buildAllKeyword in Global in ValidatePR := """PLS BUILD ALL""".r,
|
||||
|
||||
githubEnforcedBuildAll in Global in ValidatePR := {
|
||||
|
|
@ -134,18 +149,34 @@ object ValidatePullRequest extends AutoPlugin {
|
|||
|
||||
val prId = (sourceBranch in ValidatePR).value
|
||||
|
||||
val target = (targetBranch in ValidatePR).value
|
||||
|
||||
// TODO could use jgit
|
||||
log.info(s"Diffing [$prId] to determine changed modules in PR...")
|
||||
val gitOutput = "git diff HEAD^ --name-only".!!.split("\n")
|
||||
|
||||
val moduleNames =
|
||||
gitOutput
|
||||
val diffOutput = s"git diff $target --name-only".!!.split("\n")
|
||||
val diffedModuleNames =
|
||||
diffOutput
|
||||
.map(l ⇒ l.trim.takeWhile(_ != '/'))
|
||||
.filter(dir => dir.startsWith("akka-") || dir == "project")
|
||||
.toSet
|
||||
|
||||
log.info("Detected changes in directories: " + moduleNames.mkString("[", ", ", "]"))
|
||||
moduleNames
|
||||
val dirtyModuleNames: Set[String] =
|
||||
if (runningOnJenkins) Set.empty
|
||||
else {
|
||||
val statusOutput = s"git status --short".!!.split("\n")
|
||||
val dirtyDirectories = statusOutput
|
||||
.map(l ⇒ l.trim.dropWhile(_ != ' ').drop(1))
|
||||
.map(_.takeWhile(_ != '/'))
|
||||
.filter(dir => dir.startsWith("akka-") || dir == "project")
|
||||
.toSet
|
||||
log.info("Detected uncomitted changes in directories (including in dependency analysis): " + dirtyDirectories.mkString("[", ",", "]"))
|
||||
dirtyDirectories
|
||||
}
|
||||
|
||||
|
||||
val allModuleNames = dirtyModuleNames ++ diffedModuleNames
|
||||
log.info("Detected changes in directories: " + allModuleNames.mkString("[", ", ", "]"))
|
||||
allModuleNames
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue