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

Replace lock-threads action with GitHub Script (#5330)Browse files
Replaces the dessant/lock-threads action with a direct GitHub Script
implementation to avoid the deprecated search/issues API endpoint warning.
The new implementation:
- Uses github.rest.issues.listForRepo() instead of the deprecated search API
- Maintains the same 7-day inactivity threshold
- Adds the same comment before locking
- Uses 'resolved' as the lock reason
- Handles pagination properly for large repositories

馃 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
Ashwin Bhat authored on Aug 8, 2025 路 GitHub committed on Aug 8, 2025 parent 6059607 路 commit f0042afb3bf3
1 changed file+75 -10compared with 6059607
M.github/workflows/lock-closed-issues.yml
@@ -13,16 +13,81 @@
1313 group: lock-threads
1414
1515 jobs:
16- lock-threads:
16+ lock-closed-issues:
1717 runs-on: ubuntu-latest
18+ timeout-minutes: 10
1819 steps:
19- - uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771 # v5.0.1
20+ - name: Lock closed issues after 7 days of inactivity
21+ uses: actions/github-script@v7
2022 with:
21- issue-inactive-days: "7"
22- process-only: "issues"
23- log-output: true
24- issue-comment: >
25- This issue has been automatically locked since it was
26- closed and has not had any activity for 7 days.
27- If you're experiencing a similar issue, please file a new issue
28- and reference this one if it's relevant.
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}`);