mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
f
This commit is contained in:
parent
e9c540aa00
commit
e6f04230c3
55
.github/workflows/auto_merge_approved_prs.yml
vendored
55
.github/workflows/auto_merge_approved_prs.yml
vendored
@ -37,24 +37,31 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Get repository owner
|
- name: Get organization info
|
||||||
id: repo_info
|
id: org_info
|
||||||
if: steps.check_workflows.outputs.should_continue == 'true'
|
if: steps.check_workflows.outputs.should_continue == 'true'
|
||||||
run: |
|
run: |
|
||||||
repo_owner=$(gh repo view --json owner --jq '.owner.login')
|
repo_info=$(gh repo view --json owner)
|
||||||
echo "repo_owner=$repo_owner" >> $GITHUB_OUTPUT
|
org_name=$(echo "$repo_info" | jq -r '.owner.login')
|
||||||
|
echo "org_name=$org_name" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# Get all organization members with admin role
|
||||||
|
echo "Getting organization admins..."
|
||||||
|
admins=$(gh api "orgs/$org_name/members?role=admin" --jq '.[].login' | tr '\n' ' ')
|
||||||
|
echo "org_admins=$admins" >> $GITHUB_OUTPUT
|
||||||
|
echo "Organization admins: $admins"
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Find and merge approved PRs
|
- name: Find and merge approved PRs
|
||||||
if: steps.check_workflows.outputs.should_continue == 'true'
|
if: steps.check_workflows.outputs.should_continue == 'true'
|
||||||
run: |
|
run: |
|
||||||
repo_owner="${{ steps.repo_info.outputs.repo_owner }}"
|
org_admins="${{ steps.org_info.outputs.org_admins }}"
|
||||||
merged_count=0
|
merged_count=0
|
||||||
max_merges=2
|
max_merges=2
|
||||||
|
|
||||||
echo "Repository owner: $repo_owner"
|
echo "Organization admins: $org_admins"
|
||||||
echo "Looking for PRs with 'merge' comment from owner..."
|
echo "Looking for PRs with exact comment 'bot merge please' from any org admin..."
|
||||||
|
|
||||||
# Get all open PRs
|
# Get all open PRs
|
||||||
prs=$(gh pr list --state open --json number,title,url)
|
prs=$(gh pr list --state open --json number,title,url)
|
||||||
@ -79,17 +86,30 @@ jobs:
|
|||||||
echo "Checking PR #$pr_number: $pr_title"
|
echo "Checking PR #$pr_number: $pr_title"
|
||||||
|
|
||||||
# Get all comments for this PR
|
# Get all comments for this PR
|
||||||
comments=$(gh pr view "$pr_number" --json comments --jq '.comments[] | select(.author.login == "'"$repo_owner"'") | .body')
|
comments=$(gh pr view "$pr_number" --json comments --jq '.comments[]')
|
||||||
|
|
||||||
# Check if any comment from the owner contains the word "merge"
|
# Print all comment authors for debugging
|
||||||
|
echo "Comments in PR #$pr_number:"
|
||||||
|
echo "$comments" | jq -r '" - Author: " + .author.login + " | Comment: " + (.body | split("\n")[0] | .[0:100])'
|
||||||
|
|
||||||
|
# Check if any comment from an org admin contains exactly "bot merge please"
|
||||||
has_merge_comment=false
|
has_merge_comment=false
|
||||||
while IFS= read -r comment; do
|
echo "$comments" | jq -r '.author.login + "|" + .body' | while IFS='|' read -r comment_author comment_body; do
|
||||||
if echo "$comment" | grep -qi "merge"; then
|
# Check if the comment author is in the list of org admins
|
||||||
has_merge_comment=true
|
if echo "$org_admins" | grep -wq "$comment_author"; then
|
||||||
echo "Found 'merge' comment from owner in PR #$pr_number"
|
# Check for exact match "bot merge please" (case-insensitive)
|
||||||
break
|
if echo "$comment_body" | grep -iExq "bot merge please"; then
|
||||||
|
echo "Found exact 'bot merge please' comment from org admin '$comment_author' in PR #$pr_number"
|
||||||
|
echo "true" > /tmp/has_merge_comment_$pr_number
|
||||||
|
break
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done <<< "$comments"
|
done
|
||||||
|
|
||||||
|
# Check if merge comment was found
|
||||||
|
if [ -f "/tmp/has_merge_comment_$pr_number" ]; then
|
||||||
|
has_merge_comment=true
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$has_merge_comment" = true ]; then
|
if [ "$has_merge_comment" = true ]; then
|
||||||
echo "Attempting to merge PR #$pr_number..."
|
echo "Attempting to merge PR #$pr_number..."
|
||||||
@ -109,8 +129,11 @@ jobs:
|
|||||||
echo "PR #$pr_number is not mergeable (status: $pr_mergeable)"
|
echo "PR #$pr_number is not mergeable (status: $pr_mergeable)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "No 'merge' comment found from owner in PR #$pr_number"
|
echo "No exact 'bot merge please' comment found from any org admin in PR #$pr_number"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clean up temp file
|
||||||
|
rm -f "/tmp/has_merge_comment_$pr_number"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Auto-merge process completed. Merged $merged_count PRs."
|
echo "Auto-merge process completed. Merged $merged_count PRs."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user