-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TMP-1717): Add PR validation check (#4013)
* added check-pr-branch to circleci yaml * added check-pr-branch.sh * fixed executor to node * updated logic of CircleCI PR branch check * removed 20-30s unnecessary checkout * replaced job with inline command run * changed order of check PR * removed unintended newline on cci yaml file
- Loading branch information
1 parent
17e8a41
commit aef6c61
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
if [[ "$CIRCLE_BRANCH" == "master" ]]; | ||
then | ||
echo "Skipping PR branch check for master branch" | ||
exit 0 | ||
fi | ||
|
||
echo "Checking PR branch is up to date with master branch" | ||
|
||
current_branch=$(git branch --show-current) | ||
merge_base=$(git merge-base $current_branch master) | ||
recommend_rebase="rebase your branch on the master branch." | ||
|
||
# checking if PR branch is up to date | ||
if ! git diff -s --exit-code $current_branch...master ; then | ||
echo "Branch ${current_branch} is not up-to-date with master. Please, ${recommend_rebase}" | ||
exit 1 | ||
fi | ||
|
||
# checking if there is no new merge commit | ||
current_commit=$(git show-ref --heads -s $current_branch) | ||
for commit in $(git log $current_commit...$merge_base --format="%h"); do | ||
parent_count=$(git cat-file -p $commit | grep parent | wc -l) | ||
if [ "${parent_count}" != 1 ]; then | ||
commit_msg=$(git log $commit -1 --format="%s") | ||
echo "Merge commits like ${commit} (${commit_msg}) are not allowed. Please ${recommend_rebase}" | ||
exit 1 | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters