[create] auto merge 1 week pr #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |