mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
114 lines
3.9 KiB
YAML
114 lines
3.9 KiB
YAML
name: Auto Merge Approved PRs
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 */2 * * *' # Every 2 hours
|
|
workflow_dispatch: # Allow manual triggering
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
actions: read
|
|
|
|
jobs:
|
|
auto-merge-prs:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Check for running workflows
|
|
id: check_workflows
|
|
run: |
|
|
# Get all running workflows except this one
|
|
running_workflows=$(gh run list --status in_progress --json workflowName,name --jq '.[].name' | grep -v "Auto Merge Approved PRs" | wc -l)
|
|
echo "running_workflows=$running_workflows" >> $GITHUB_OUTPUT
|
|
|
|
if [ "$running_workflows" -gt 0 ]; then
|
|
echo "Found $running_workflows running workflows. Exiting to avoid conflicts."
|
|
exit 0
|
|
fi
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Get repository owner
|
|
id: repo_info
|
|
run: |
|
|
repo_owner=$(gh repo view --json owner --jq '.owner.login')
|
|
echo "repo_owner=$repo_owner" >> $GITHUB_OUTPUT
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Find and merge approved PRs
|
|
run: |
|
|
repo_owner="${{ steps.repo_info.outputs.repo_owner }}"
|
|
merged_count=0
|
|
max_merges=2
|
|
|
|
echo "Repository owner: $repo_owner"
|
|
echo "Looking for PRs with 👍 emoji from owner..."
|
|
|
|
# Get all open PRs
|
|
prs=$(gh pr list --state open --json number,title,url)
|
|
|
|
if [ "$prs" = "[]" ]; then
|
|
echo "No open PRs found."
|
|
exit 0
|
|
fi
|
|
|
|
# Process each PR
|
|
echo "$prs" | jq -r '.[] | @base64' | while IFS= read -r pr_data; do
|
|
if [ "$merged_count" -ge "$max_merges" ]; then
|
|
echo "Reached maximum merge limit ($max_merges). Stopping."
|
|
break
|
|
fi
|
|
|
|
pr_info=$(echo "$pr_data" | base64 --decode)
|
|
pr_number=$(echo "$pr_info" | jq -r '.number')
|
|
pr_title=$(echo "$pr_info" | jq -r '.title')
|
|
pr_url=$(echo "$pr_info" | jq -r '.url')
|
|
|
|
echo "Checking PR #$pr_number: $pr_title"
|
|
|
|
# Get all comments for this PR
|
|
comments=$(gh pr view "$pr_number" --json comments --jq '.comments[] | select(.author.login == "'"$repo_owner"'") | .body')
|
|
|
|
# Check if any comment from the owner contains the 👍 emoji
|
|
has_thumbs_up=false
|
|
while IFS= read -r comment; do
|
|
if echo "$comment" | grep -q "👍"; then
|
|
has_thumbs_up=true
|
|
echo "Found 👍 emoji from owner in PR #$pr_number"
|
|
break
|
|
fi
|
|
done <<< "$comments"
|
|
|
|
if [ "$has_thumbs_up" = true ]; then
|
|
echo "Attempting to merge PR #$pr_number..."
|
|
|
|
# Check if PR can be merged
|
|
pr_mergeable=$(gh pr view "$pr_number" --json mergeable --jq '.mergeable')
|
|
|
|
if [ "$pr_mergeable" = "MERGEABLE" ]; then
|
|
# Merge the PR
|
|
if gh pr merge "$pr_number" --merge --delete-branch; then
|
|
echo "Successfully merged PR #$pr_number: $pr_title"
|
|
merged_count=$((merged_count + 1))
|
|
else
|
|
echo "Failed to merge PR #$pr_number: $pr_title"
|
|
fi
|
|
else
|
|
echo "PR #$pr_number is not mergeable (status: $pr_mergeable)"
|
|
fi
|
|
else
|
|
echo "No 👍 emoji found from owner in PR #$pr_number"
|
|
fi
|
|
done
|
|
|
|
echo "Auto-merge process completed. Merged $merged_count PRs."
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|