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 6 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
25 changes: 19 additions & 6 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,32 @@ 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]')
pr_number=${{ github.event.pull_request.number }}
approvals=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos${{ github.owner }}/${{ github.repository }}/pulls/${pr_number}/reviews" | \
jq -r '.[] | select(.state == "APPROVED").user.login')

if [[ -n "$approvals" ]]; then
echo "PR has been approved, merging..."
gh pr merge $pr_number --auto --squash --delete-branch
for user in $approvals; do
# Check if the user is a code owner for the modified files
if gh pr review $pr_number --json event,html_url --jq \
'.[] | select(.user.login == $user and .state == "APPROVED") | .html_url' \
--arg user "$user" | grep -qFf - <(gh pr diff $pr_number --json changes --jq '.changes[].blob_url'); then
echo "PR has been approved by code owner, merging..."
gh pr merge $pr_number --auto --squash --delete-branch
break
fi
done
else
echo "PR has not been approved."
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.