Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Auto Merge #1

Merged
merged 9 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading