spacehub

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

claude-code / .github / workflows / lock-closed-issues.yml
93 lines · 3.1 KBRaw
1name: "Lock Stale Issues"
2
3on:
4 schedule:
5 # 8am Pacific = 1pm UTC (2pm UTC during DST)
6 - cron: "0 14 * * *"
7 workflow_dispatch:
8
9permissions:
10 issues: write
11
12concurrency:
13 group: lock-threads
14
15jobs:
16 lock-closed-issues:
17 runs-on: ubuntu-latest
18 timeout-minutes: 10
19 steps:
20 - name: Lock closed issues after 7 days of inactivity
21 uses: actions/github-script@v7
22 with:
23 script: |
24 const sevenDaysAgo = new Date();
25 sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
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 let page = 1;
30 let hasMore = true;
31 let totalLocked = 0;
32
33 while (hasMore) {
34 // Get closed issues (pagination)
35 const { data: issues } = await github.rest.issues.listForRepo({
36 owner: context.repo.owner,
37 repo: context.repo.repo,
38 state: 'closed',
39 sort: 'updated',
40 direction: 'asc',
41 per_page: 100,
42 page: page
43 });
44
45 if (issues.length === 0) {
46 hasMore = false;
47 break;
48 }
49
50 for (const issue of issues) {
51 // Skip if already locked
52 if (issue.locked) continue;
53
54 // Skip pull requests
55 if (issue.pull_request) continue;
56
57 // Check if updated more than 7 days ago
58 const updatedAt = new Date(issue.updated_at);
59 if (updatedAt > sevenDaysAgo) {
60 // Since issues are sorted by updated_at ascending,
61 // once we hit a recent issue, all remaining will be recent too
62 hasMore = false;
63 break;
64 }
65
66 try {
67 // Add comment before locking
68 await github.rest.issues.createComment({
69 owner: context.repo.owner,
70 repo: context.repo.repo,
71 issue_number: issue.number,
72 body: lockComment
73 });
74
75 // Lock the issue
76 await github.rest.issues.lock({
77 owner: context.repo.owner,
78 repo: context.repo.repo,
79 issue_number: issue.number,
80 lock_reason: 'resolved'
81 });
82
83 totalLocked++;
84 console.log(`Locked issue #${issue.number}: ${issue.title}`);
85 } catch (error) {
86 console.error(`Failed to lock issue #${issue.number}: ${error.message}`);
87 }
88 }
89
90 page++;
91 }
92
93 console.log(`Total issues locked: ${totalLocked}`);