@@ -616,29 +616,30 @@ def resolveBranchNo(String featureBranchPRMinusNo) {
616
616
}
617
617
618
618
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)
625
620
626
621
// curl the repo based on the feature branch no to get the branch information
627
622
// / 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
633
627
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
+ }
638
630
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()
641
635
642
- return branch
636
+ String prNo = branchNoMatcher[0 ][1 ]
637
+ log(" i" , " PR number: " + prNo + " of class " + prNo. getClass())
638
+ return prNo
639
+ }
643
640
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
644
645
}
0 commit comments