Skip to content

Commit f7102b1

Browse files
committed
Fix feature branch name determination in CI
1 parent 004d131 commit f7102b1

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Jenkinsfile

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -616,29 +616,30 @@ def resolveBranchNo(String featureBranchPRMinusNo) {
616616
}
617617

618618
def resolveBranchName(String featureBranchPRMinusNo, String orgName, String repoName) {
619-
620-
// get pull request number
621-
def branchNoMatcher = featureBranchPRMinusNo =~ /PR-(.*)/
622-
assert branchNoMatcher.find()
623-
624-
def prNo = branchNoMatcher[0][1]
619+
def prNo = extractPrNumber(featureBranchPRMinusNo)
625620

626621
// curl the repo based on the feature branch no to get the branch information
627622
/// Note: only works for public repos! Otherwise credentials needs to be passed
628-
def curlUrl = "curl https://api.github.com/repos/" + orgName + "/" + repoName + "/pulls/" + prNo
629-
def response = curlUrl.execute().text
630-
def matcher = response =~ /\"label\":\s\"(.+)\"/
631-
632-
assert matcher.find()
623+
String response = curlByPR(prNo, orgName, repoName)
624+
log("i", "API response:" + response)
625+
def jsonResponse = readJSON text: response
626+
def branchName = jsonResponse.head.ref
633627

634-
// get split the label to account for PRs from forks
635-
def split = matcher[0][1] =~ /(.*):(.*)/
636-
637-
assert matcher.find()
628+
return branchName
629+
}
638630

639-
def username = split[0][1]
640-
def branch = split[0][2]
631+
def extractPrNumber(String featureBranchPRMinusNo) {
632+
// get pull request number
633+
def branchNoMatcher = featureBranchPRMinusNo =~ /PR-(.*)/
634+
assert branchNoMatcher.find()
641635

642-
return branch
636+
String prNo = branchNoMatcher[0][1]
637+
log("i", "PR number: " + prNo + " of class " + prNo.getClass())
638+
return prNo
639+
}
643640

641+
def curlByPR(String prId, String orgName, String repoName) {
642+
def curlUrl = "set +x && curl -s https://api.github.com/repos/" + orgName + "/" + repoName + "/pulls/" + prId
643+
String jsonResponseString = sh(script: curlUrl, returnStdout: true)
644+
return jsonResponseString
644645
}

0 commit comments

Comments
 (0)