Skip to content

Commit

Permalink
Fix feature branch name determination in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ckittl committed Apr 21, 2021
1 parent 004d131 commit f7102b1
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit f7102b1

Please sign in to comment.