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 | const cutoff = sevenDaysAgo.toISOString().split('T')[0]; |
| 26 | |
| 27 | 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.`; |
| 28 | |
| 29 | const query = `repo:${context.repo.owner}/${context.repo.repo} is:issue is:closed is:unlocked updated:<${cutoff}`; |
| 30 | console.log(`Search query: ${query}`); |
| 31 | |
| 32 | const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); |
| 33 | const MAX_PER_RUN = 250; |
| 34 | const processed = new Set(); |
| 35 | let totalLocked = 0; |
| 36 | |
| 37 | while (totalLocked < MAX_PER_RUN) { |
| 38 | const { data } = await github.rest.search.issuesAndPullRequests({ |
| 39 | q: query, |
| 40 | sort: 'updated', |
| 41 | order: 'asc', |
| 42 | per_page: 100, |
| 43 | }); |
| 44 | |
| 45 | if (totalLocked === 0) { |
| 46 | console.log(`Total candidates: ${data.total_count}`); |
| 47 | } |
| 48 | |
| 49 | const fresh = data.items.filter((i) => !processed.has(i.number)); |
| 50 | if (fresh.length === 0) break; |
| 51 | |
| 52 | for (const issue of fresh) { |
| 53 | if (totalLocked >= MAX_PER_RUN) break; |
| 54 | processed.add(issue.number); |
| 55 | try { |
| 56 | await github.rest.issues.createComment({ |
| 57 | owner: context.repo.owner, |
| 58 | repo: context.repo.repo, |
| 59 | issue_number: issue.number, |
| 60 | body: lockComment, |
| 61 | }); |
| 62 | await github.rest.issues.lock({ |
| 63 | owner: context.repo.owner, |
| 64 | repo: context.repo.repo, |
| 65 | issue_number: issue.number, |
| 66 | lock_reason: 'resolved', |
| 67 | }); |
| 68 | totalLocked++; |
| 69 | console.log(`Locked issue #${issue.number}: ${issue.title}`); |
| 70 | await sleep(1000); |
| 71 | } catch (error) { |
| 72 | console.error(`Failed to lock issue #${issue.number}: ${error.message}`); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | console.log(`Total issues locked: ${totalLocked}`); |