diff --git a/Jenkinsfile b/Jenkinsfile index 45254f2..863cee5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -616,29 +616,30 @@ def resolveBranchNo(String featureBranchPRMinusNo) { } def resolveBranchName(String featureBranchPRMinusNo, String orgName, String repoName) { - - // get pull request number - def branchNoMatcher = featureBranchPRMinusNo =~ /PR-(.*)/ - assert branchNoMatcher.find() - - def prNo = branchNoMatcher[0][1] + def prNo = extractPrNumber(featureBranchPRMinusNo) // curl the repo based on the feature branch no to get the branch information /// Note: only works for public repos! Otherwise credentials needs to be passed - def curlUrl = "curl https://api.github.com/repos/" + orgName + "/" + repoName + "/pulls/" + prNo - def response = curlUrl.execute().text - def matcher = response =~ /\"label\":\s\"(.+)\"/ - - assert matcher.find() + String response = curlByPR(prNo, orgName, repoName) + log("i", "API response:" + response) + def jsonResponse = readJSON text: response + def branchName = jsonResponse.head.ref - // get split the label to account for PRs from forks - def split = matcher[0][1] =~ /(.*):(.*)/ - - assert matcher.find() + return branchName +} - def username = split[0][1] - def branch = split[0][2] +def extractPrNumber(String featureBranchPRMinusNo) { + // get pull request number + def branchNoMatcher = featureBranchPRMinusNo =~ /PR-(.*)/ + assert branchNoMatcher.find() - return branch + String prNo = branchNoMatcher[0][1] + log("i", "PR number: " + prNo + " of class " + prNo.getClass()) + return prNo +} +def curlByPR(String prId, String orgName, String repoName) { + def curlUrl = "set +x && curl -s https://api.github.com/repos/" + orgName + "/" + repoName + "/pulls/" + prId + String jsonResponseString = sh(script: curlUrl, returnStdout: true) + return jsonResponseString } \ No newline at end of file