Skip to content

Commit

Permalink
Test Auto Merge (#1)
Browse files Browse the repository at this point in the history
* Test Auto Merge

* Update Token

* Update Token

* Update Token

* Update Token

* Update Token

* Update script

* Update script

* Update script

---------

Co-authored-by: Ujala Singh <[email protected]>
  • Loading branch information
ujala-singh and Ujala Singh authored Jan 15, 2024
1 parent fcc490b commit 2b77b83
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/auto-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
token: ${{ secrets.DISPATCH_TOKEN }}
token: ${{ secrets.MY_PAT }}
fetch-depth: 0

- name: Check GitHub CLI version
Expand All @@ -25,19 +25,31 @@ jobs:
node-version: '14'

- name: Add Approved label
if: success()
run: |
pr_number=$(gh pr view ${{ github.event.pull_request.number }} --json number --jq '.number')
gh pr edit $pr_number --add-label "approved"
env:
GH_TOKEN: ${{ secrets.MY_PAT }}

- name: Auto Merge Approved PR
run: |
pr_number=$(gh pr view ${{ github.event.pull_request.number }} --json number --jq '.number')
approvals=$(gh pr review-list $pr_number --json state,author --jq '[.[] | select(.state == "APPROVED").author]')
if [[ -n "$approvals" ]]; then
echo "PR has been approved, merging..."
gh pr merge $pr_number --auto --squash --delete-branch
else
echo "PR has not been approved."
pr_number=${{ github.event.pull_request.number }}
review_users=$(gh pr view ${pr_number} --json reviews | jq -r '.reviews[].author.login')
# Fetch CODEOWNERS file content
CODEOWNERS_CONTENT=$(curl -s "https://api.github.com/repos${{ github.owner }}/${{ github.repository }}/contents/.github/CODEOWNERS" | jq -r '.content' | base64 -d)
if [[ -n "$review_users" ]]; then
for user in $review_users; do
echo "Checking code owner for reviewer: $user"
# Check if the reviewer is a code owner
if echo "$CODEOWNERS_CONTENT" | grep -q "$user"; then
echo "PR has been approved by code owner, merging..."
gh pr merge $pr_number --auto --squash --delete-branch
break # Exit the loop if any reviewer is a code owner
else
echo "Reviewer $user is not a code owner."
fi
done
fi
env:
GH_TOKEN: ${{ secrets.MY_PAT }}
4 changes: 2 additions & 2 deletions .github/workflows/main-branch-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
token: ${{ secrets.DISPATCH_TOKEN }}
token: ${{ secrets.MY_PAT }}
fetch-depth: 0

- name: Check GitHub CLI version
Expand Down Expand Up @@ -56,4 +56,4 @@ jobs:
fi
echo "Workflow completed successfully."
env:
GH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion hello.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hi, Hello World!
Hi, Hello World.

0 comments on commit 2b77b83

Please sign in to comment.