Skip to content

Auto-merge PRs after one week #37

Auto-merge PRs after one week

Auto-merge PRs after one week #37

Workflow file for this run

name: Auto-merge PRs after one week
on:
schedule:
- cron: '0 0 * * *' # ๋งค์ผ ์ž์ •์— ์‹คํ–‰
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
auto-merge:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check PR age and merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# ๋ชจ๋“  ์—ด๋ฆฐ PR ๊ฐ€์ ธ์˜ค๊ธฐ
prs=$(gh pr list --json number,createdAt,mergeStateStatus --state open)
# ๊ฐ PR ํ™•์ธ
echo "$prs" | jq -c '.[]' | while read pr; do
number=$(echo $pr | jq -r .number)
created_at=$(echo $pr | jq -r .createdAt)
merge_state=$(echo $pr | jq -r .mergeStateStatus)
# PR ๋‚˜์ด ๊ณ„์‚ฐ (์ผ ๋‹จ์œ„)
age=$(( ( $(date +%s) - $(date -d "$created_at" +%s) ) / 86400 ))
# 7์ผ ์ด์ƒ ๋˜์—ˆ๊ณ  ๋ณ‘ํ•ฉ ๊ฐ€๋Šฅํ•œ ์ƒํƒœ์ธ์ง€ ํ™•์ธ
if [ $age -ge 7 ] && [ "$merge_state" == "CLEAN" ]; then
echo "Merging PR #$number (age: $age days)"
gh pr merge $number --auto --merge
else
echo "PR #$number is not ready for auto-merge (age: $age days, state: $merge_state)"
fi
done