Skip to content

Commit

Permalink
make getCheckoutInfo more reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed May 19, 2020
1 parent 281de65 commit 0f3d061
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
32 changes: 15 additions & 17 deletions vars/getCheckoutInfo.groovy
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
def call() {

def repoInfo = [
branch: env.ghprbSourceBranch ?: params.branch_specifier ?: 'missing branch_specifier',
branch: env.ghprbSourceBranch ?: params.branch_specifier ?: null,
targetBranch: env.ghprbTargetBranch,
]

dir("kibana") {
repoInfo.commit = sh(
script: "git rev-parse HEAD",
label: "determining checked out sha",
repoInfo.commit = sh(
script: "git rev-parse HEAD",
label: "determining checked out sha",
returnStdout: true
).trim()

if (repoInfo.targetBranch) {
sh(
script: "git fetch origin ${repoInfo.targetBranch}",
label: "fetch latest from '${repoInfo.targetBranch}' at origin"
)
repoInfo.mergeBase = sh(
script: "git merge-base HEAD FETCH_HEAD",
label: "determining merge point with '${repoInfo.targetBranch}' at origin",
returnStdout: true
).trim()

if (repoInfo.targetBranch) {
sh(
script: "git fetch https://github.com/elastic/kibana.git ${repoInfo.targetBranch}",
label: "fetch latest from '${repoInfo.targetBranch}' at https://github.com/elastic/kibana.git"
)
repoInfo.mergeBase = sh(
script: "git merge-base HEAD FETCH_HEAD",
label: "determining merge point with '${repoInfo.targetBranch}' at https://github.com/elastic/kibana.git",
returnStdout: true
).trim()
}
}

print "repoInfo: ${repoInfo}"
Expand Down
6 changes: 5 additions & 1 deletion vars/workers.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def base(Map params, Closure closure) {
checkout scm
}

checkoutInfo = getCheckoutInfo()
def checkoutInfo
dir("kibana") {
checkoutInfo = getCheckoutInfo()
}

ciStats.reportGitInfo(
checkoutInfo.branch,
checkoutInfo.commit,
Expand Down

0 comments on commit 0f3d061

Please sign in to comment.