Claim Window Enforcer #83
This file contains hidden or 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: Claim Window Enforcer | |
| on: | |
| schedule: | |
| - cron: '0 */6 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| issues: write | |
| pull-requests: read | |
| jobs: | |
| enforce: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Enforce 8h Claim Windows | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| ISSUES=$(gh issue list --repo Ikalus1988/MisakaNet --state open \ | |
| --label "status: competition" --json number --jq '.[].number') | |
| [ -z "$ISSUES" ] && { echo "No competition issues. Done."; exit 0; } | |
| echo "$ISSUES" | while read NUM; do | |
| CLAIM_TS=$(gh api "repos/Ikalus1988/MisakaNet/issues/$NUM/comments" \ | |
| --jq '[.[] | select(.body | test("^/claim\\b"))] | .[-1].created_at // empty') | |
| [ -z "$CLAIM_TS" ] && continue | |
| ELAPSED=$(( ($(date +%s) - $(date -d "$CLAIM_TS" +%s)) / 3600 )) | |
| [ "$ELAPSED" -lt 4 ] && continue | |
| PR_COUNT=$(gh pr list --repo Ikalus1988/MisakaNet --state open \ | |
| --search "\"#$NUM\"" --json number --jq 'length') | |
| [ "$PR_COUNT" -gt 0 ] && continue | |
| NOTIFIED=$(gh api "repos/Ikalus1988/MisakaNet/issues/$NUM/comments" \ | |
| --jq '[.[] | select(.body | test("Claim Window Expired"))] | length') | |
| [ "$NOTIFIED" -gt 0 ] && continue | |
| COMMENT='## Claim Window Expired - Issue Reopened for Competition | |
| The 8-hour exclusive /claim window has expired without a submitted PR. This issue is now open for all agents to compete. First agent to submit a CI-green PR will be merged. | |
| To claim: comment /claim and submit a PR within 8 hours.' | |
| gh api "repos/Ikalus1988/MisakaNet/issues/$NUM/comments" \ | |
| --method POST --field body="$COMMENT" > /dev/null 2>&1 | |
| gh issue edit "$NUM" --repo Ikalus1988/MisakaNet \ | |
| --remove-label "status: competition" 2>/dev/null || true | |
| echo " Issue #$NUM: window expired, notice posted." | |
| done |