-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathgetCheckoutInfo.groovy
50 lines (41 loc) · 1.47 KB
/
getCheckoutInfo.groovy
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def call(branchOverride) {
def repoInfo = [
branch: branchOverride ?: env.ghprbSourceBranch,
targetBranch: env.ghprbTargetBranch,
targetsTrackedBranch: true
]
if (repoInfo.branch == null) {
if (!(params.branch_specifier instanceof String)) {
throw new Exception(
"Unable to determine branch automatically, either pass a branch name to getCheckoutInfo() or use the branch_specifier param."
)
}
// strip prefix from the branch specifier to make it consistent with ghprbSourceBranch
repoInfo.branch = params.branch_specifier.replaceFirst(/^(refs\/heads\/|origin\/)/, "")
}
repoInfo.commit = sh(
script: "git rev-parse HEAD",
label: "determining checked out sha",
returnStdout: true
).trim()
if (repoInfo.targetBranch) {
// Try to clone fetch from Github up to 8 times, waiting 15 secs between attempts
retryWithDelay(8, 15) {
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()
def pkgJson = readFile("package.json")
def releaseBranch = toJSON(pkgJson).branch
repoInfo.targetsTrackedBranch = releaseBranch == repoInfo.targetBranch
}
print "repoInfo: ${repoInfo}"
return repoInfo
}
return this