Skip to content

Commit ac06c69

Browse files
author
Vaughn Dice
authored
Merge pull request #153 from vdice/get-actual-pr-commit
feat(Jenkinsfile): get actual PR commit, if PR
2 parents c655ea0 + fb6ed28 commit ac06c69

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Jenkinsfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ node('linux') {
9090
sh 'git rev-parse HEAD > tmp/GIT_COMMIT'
9191
git_branch = readFile('tmp/GIT_BRANCH').trim()
9292
git_commit = readFile('tmp/GIT_COMMIT').trim()
93+
94+
if (git_branch != "remotes/origin/master") {
95+
// Determine actual PR commit, if necessary
96+
sh 'git rev-parse HEAD | git log --pretty=%P -n 1 --date-order > tmp/MERGE_COMMIT_PARENTS'
97+
sh 'cat tmp/MERGE_COMMIT_PARENTS'
98+
merge_commit_parents = readFile('tmp/MERGE_COMMIT_PARENTS').trim()
99+
if (merge_commit_parents.length() > 40) {
100+
echo 'More than one merge commit parent signifies that the merge commit is not the PR commit'
101+
echo "Changing git_commit from '${git_commit}' to '${merge_commit_parents.take(40)}'"
102+
git_commit = merge_commit_parents.take(40)
103+
} else {
104+
echo 'Only one merge commit parent signifies that the merge commit is also the PR commit'
105+
echo "Keeping git_commit as '${git_commit}'"
106+
}
107+
}
93108
}
94109
}
95110

0 commit comments

Comments
 (0)