Skip to content

Commit a03cf09

Browse files
author
Vaughn Dice
authored
Merge pull request #50 from vdice/actual-commit-issue-45
fix(Jenkinsfile): better way to determine actual PR commit
2 parents 6f9a09c + bc4e539 commit a03cf09

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

Jenkinsfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,18 @@ node('linux') {
6666
go_repo = readFile('tmp/GO_LIST').trim()
6767

6868
if (git_branch != "remotes/origin/master") {
69-
// HACK: get actual PR commit (https://github.com/deis/controller-sdk-go/issues/45)
70-
sh 'git rev-parse HEAD | git log --pretty=%P -n 1 | cut -c1-40 > tmp/ACTUAL_COMMIT'
71-
git_commit = readFile('tmp/ACTUAL_COMMIT').trim()
69+
// Determine actual PR commit, if necessary
70+
sh 'git rev-parse HEAD | git log --pretty=%P -n 1 --date-order > tmp/MERGE_COMMIT_PARENTS'
71+
sh 'cat tmp/MERGE_COMMIT_PARENTS'
72+
merge_commit_parents = readFile('tmp/MERGE_COMMIT_PARENTS').trim()
73+
if (merge_commit_parents.length() > 40) {
74+
echo 'More than one merge commit parent signifies that the merge commit is not the PR commit'
75+
echo "Changing git_commit from '${git_commit}' to '${merge_commit_parents.take(40)}'"
76+
git_commit = merge_commit_parents.take(40)
77+
} else {
78+
echo 'Only one merge commit parent signifies that the merge commit is also the PR commit'
79+
echo "Keeping git_commit as '${git_commit}'"
80+
}
7281
// convert 'github.com/deis/controller-sdk-go' to 'github.com/${env.CHANGE_AUTHOR}/controller-sdk-go'
7382
go_repo = go_repo.replace('deis', env.CHANGE_AUTHOR)
7483
}

0 commit comments

Comments
 (0)