Skip to content

Commit

Permalink
Issue #12319: validate PR number when commit is for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmancuso authored and romani committed Oct 25, 2022
1 parent e2e9792 commit 7215503
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .ci/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,21 @@ git-no-merge-commits)
fi
;;

git-check-pull-number)
COMMITS="$(git log --format=format:%B master.."$PR_HEAD_SHA")"

echo "$COMMITS" | while read -r COMMIT ; do
if [[ $COMMIT =~ 'Pull #' ]]; then
PULL_MESSAGE_NUMBER=$(echo "$COMMIT" | cut -d'#' -f 2 | cut -d':' -f 1)
if [[ $PULL_MESSAGE_NUMBER != "$PR_NUMBER" ]]; then
echo "Referenced PR and this PR number do not match."
echo "Commit message should reference $PR_NUMBER"
exit 1
fi
fi
done
;;

*)
echo "Unexpected argument: $1"
sleep 5s
Expand Down
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ jobs:
export PR_HEAD_SHA=$CIRCLE_SHA1
./.ci/validation.sh git-no-merge-commits
check-pull-number:
docker:
- image: cimg/base:2022.10
steps:
- checkout
- run:
name: Check that 'Pull#XXXX' matches PR number
command: |
export PR_HEAD_SHA=$CIRCLE_SHA1
export PR_NUMBER=$CIRCLE_PR_NUMBER
./.ci/validation.sh git-check-pull-number
workflows:
version: 2
no-exception-tests:
Expand Down Expand Up @@ -273,3 +285,4 @@ workflows:
git-validation:
jobs:
- no-merge-commits
- check-pull-number

0 comments on commit 7215503

Please sign in to comment.