Skip to content

Commit

Permalink
git ls-remote may return null when finding PR num (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
definite authored Nov 15, 2017
1 parent 9c54e1a commit 5c612d8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/org/zanata/jenkins/ScmGit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ScmGit implements Serializable {

// Find PR Num
if (!pullGitLsRemoteLines) {
// git ls-remote may return null here
pullGitLsRemoteLines = steps.sh([
returnStdout: true,
script: "git ls-remote $repoUrl refs/pull/*/head",
Expand Down Expand Up @@ -95,6 +96,11 @@ class ScmGit implements Serializable {
for (int i = 0; i < gitLsRemoteLines.length; i++) {
// split each line by whitespace
String[] tokens = gitLsRemoteLines[i].split()
if (tokens.length < 2) {
// It is possible gitLsRemoteLines contains [''],
// an array that contains one empty string
continue
}
if (tokens[0] == commitId) {
// format to search is refs/heads/<branch>
return tokens[1].split('/')[2]
Expand Down

0 comments on commit 5c612d8

Please sign in to comment.