Skip to content

Commit

Permalink
Merge Conflict Job added in merge-conflict-check.yml file (Palisadoes…
Browse files Browse the repository at this point in the history
…Foundation#3147)

* added merge conflict check

* changed checkout repo

* added max tries feature

* added needs condition

* added pr target synchronize to trigger workflow

* added mergeconflictchecker.yml

* switched to gh api

* fixed indentation
  • Loading branch information
Aad1tya27 authored Jan 5, 2025
1 parent f7bcc58 commit 4798179
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 54 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/merge-conflict-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Merge Conflict Check Workflow

on:
pull_request:
branches:
- '**'
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check Mergeable Status via Github API
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
max_retries=3
retry_delay=5
for ((i=1; i<=max_retries; i++)); do
echo "Attempt $i of $max_retries"
if ! response=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" --jq '.mergeable'); then
if [[ $response == *"rate limit exceeded"* ]]; then
echo "Rate limit exceeded. Waiting before retry..."
sleep 60 # Wait longer for rate limit
else
echo "Failed to call GitHub API: $response"
if [ $i -eq $max_retries ]; then
echo "Maximum retries reached. Exiting."
exit 1
fi
sleep $retry_delay
fi
continue
fi
case "$response" in
"true")
echo "No conflicts detected."
exit 0
;;
"false")
echo "Merge conflicts detected."
exit 1
;;
*)
echo "Mergeable status unknown: $response"
if [ $i -eq $max_retries ]; then
echo "Maximum retries reached. Exiting."
exit 1
fi
sleep $retry_delay
;;
esac
done
54 changes: 0 additions & 54 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ on:
pull_request:
branches:
- '**'
types:
- opened
- reopened
- synchronize
- ready_for_review
pull_request_target:
types:
- synchronize

env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}
Expand Down Expand Up @@ -457,49 +449,3 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPOSITORY: ${{ github.repository }}

Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks]
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check Mergeable Status via API
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
max_retries=3
retry_delay=5
for ((i=1; i<=max_retries; i++)); do
echo "Attempt $i of $max_retries"
response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
if [ $? -ne 0 ]; then
echo "Failed to call GitHub API"
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
continue
fi
mergeable=$(echo "$response" | jq -r '.mergeable')
if [ "$mergeable" == "true" ]; then
echo "No conflicts detected."
exit 0
elif [ "$mergeable" == "false" ]; then
echo "Merge conflicts detected."
exit 1
else
echo "Mergeable status unknown."
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
fi
done

0 comments on commit 4798179

Please sign in to comment.