Skip to content

Commit

Permalink
Merge pull request #178 from openshift-kni/refine-verify-commit-check
Browse files Browse the repository at this point in the history
[KNI] ghactions: refine verify-commit.sh
  • Loading branch information
ffromani authored Mar 8, 2024
2 parents ae2cf4a + cacef6c commit bc192d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
run: |
TRIGGER_BRANCH=${{ env.SOURCE_BRANCH_NAME }} \
UPSTREAM_BRANCH=${{ env.TARGET_BRANCH_NAME }} \
COMMITS=${{ github.event.pull_request.commits }} \
./hack-kni/verify-commits.sh
integration-test:
Expand Down
32 changes: 4 additions & 28 deletions hack-kni/verify-commits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,18 @@ if [[ "$TRIGGER_BRANCH" == resync-* ]]; then
exit 0
fi

if [[ -z "$UPSTREAM_COMMIT" ]]; then
# CI=true is set by prow as a way to detect we are running under the ci
if [[ -n "$CI" ]]; then
latest_upstream_commit=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/openshift-kni/scheduler-plugins/commits?per_page=1 | jq -r '.[0].sha')
else
if [[ -z "$UPSTREAM_BRANCH" ]]; then
latest_upstream_commit="origin/master"
else
latest_upstream_commit=$UPSTREAM_BRANCH
fi

if [[ ! $(git branch --list --all "$latest_upstream_commit") ]]; then
echo WARN: could not find "$latest_upstream_commit", consider using a different UPSTREAM_BRANCH value
fi

fi
else
latest_upstream_commit="$UPSTREAM_COMMIT"
if [[ ! $(git cat-file -t "$UPSTREAM_COMMIT") == "commit" ]]; then
echo WARN: "$UPSTREAM_COMMIT" commitish could not be found in repo
fi
fi

commits_diff_count=$(git log --oneline "$latest_upstream_commit"..HEAD | wc -l)
if [[ $commits_diff_count -eq 0 ]]; then
if (( $COMMITS <= 0 )); then
echo "WARN: no changes detected"
exit 0
fi

echo commits between "$latest_upstream_commit"..HEAD:
echo "considering ${COMMITS} commits in PR whose head is $TRIGGER_BRANCH (into $UPSTREAM_BRANCH):"
echo "---"
git log --oneline --no-merges "$latest_upstream_commit"..HEAD
git log --oneline --no-merges -n ${COMMITS}
echo "---"

# list commits
for commitish in $( git log --oneline --no-merges "$latest_upstream_commit"..HEAD | cut -d' ' -f 1); do
for commitish in $( git log --oneline --no-merges -n ${COMMITS} | cut -d' ' -f 1); do
echo "CHECK: $commitish"
.github/hooks/commit-msg $( git log --format=%s -n 1 "$commitish" )
if [[ "$?" != "0" ]]; then
Expand Down

0 comments on commit bc192d9

Please sign in to comment.