surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | name: "Lock Stale Issues" |
| 2 | |
| 3 | on: |
| 4 | schedule: |
| 5 | # 8am Pacific = 1pm UTC (2pm UTC during DST) |
| 6 | - cron: "0 14 * * *" |
| 7 | workflow_dispatch: |
| 8 | |
| 9 | permissions: |
| 10 | issues: write |
| 11 | |
| 12 | concurrency: |
| 13 | group: lock-threads |
| 14 | |
| 15 | jobs: |
| 16 | lock-closed-issues: |
| 17 | runs-on: ubuntu-latest |
| 18 | steps: |
| 19 | - name: Lock closed issues after 7 days of inactivity |
| 20 | uses: actions/github-script@v7 |
| 21 | with: |
| 22 | script: | |
| 23 | const sevenDaysAgo = new Date(); |
| 24 | sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7); |
| 25 | |
| 26 | const lockComment = `This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.`; |
| 27 | |
| 28 | let page = 1; |
| 29 | let hasMore = true; |
| 30 | let totalLocked = 0; |
| 31 | |
| 32 | while (hasMore) { |
| 33 | // Get closed issues (pagination) |
| 34 | const { data: issues } = await github.rest.issues.listForRepo({ |
| 35 | owner: context.repo.owner, |
| 36 | repo: context.repo.repo, |
| 37 | state: 'closed', |
| 38 | sort: 'updated', |
| 39 | direction: 'asc', |
| 40 | per_page: 100, |
| 41 | page: page |
| 42 | }); |
| 43 | |
| 44 | if (issues.length === 0) { |
| 45 | hasMore = false; |
| 46 | break; |
| 47 | } |
| 48 | |
| 49 | for (const issue of issues) { |
| 50 | // Skip if already locked |
| 51 | if (issue.locked) continue; |
| 52 | |
| 53 | // Skip pull requests |
| 54 | if (issue.pull_request) continue; |
| 55 | |
| 56 | // Check if updated more than 7 days ago |
| 57 | const updatedAt = new Date(issue.updated_at); |
| 58 | if (updatedAt > sevenDaysAgo) { |
| 59 | // Since issues are sorted by updated_at ascending, |
| 60 | // once we hit a recent issue, all remaining will be recent too |
| 61 | hasMore = false; |
| 62 | break; |
| 63 | } |
| 64 | |
| 65 | try { |
| 66 | // Add comment before locking |
| 67 | await github.rest.issues.createComment({ |
| 68 | owner: context.repo.owner, |
| 69 | repo: context.repo.repo, |
| 70 | issue_number: issue.number, |
| 71 | body: lockComment |
| 72 | }); |
| 73 | |
| 74 | // Lock the issue |
| 75 | await github.rest.issues.lock({ |
| 76 | owner: context.repo.owner, |
| 77 | repo: context.repo.repo, |
| 78 | issue_number: issue.number, |
| 79 | lock_reason: 'resolved' |
| 80 | }); |
| 81 | |
| 82 | totalLocked++; |
| 83 | console.log(`Locked issue #${issue.number}: ${issue.title}`); |
| 84 | } catch (error) { |
| 85 | console.error(`Failed to lock issue #${issue.number}: ${error.message}`); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | page++; |
| 90 | } |
| 91 | |
| 92 | console.log(`Total issues locked: ${totalLocked}`); |