Skip to content

Commit 1c58f6e

Browse files
hi-ogawacodex
andauthored
ci: replace lock threads action with inline script (#1238)
Co-authored-by: Codex <noreply@openai.com>
1 parent 3a16293 commit 1c58f6e

2 files changed

Lines changed: 51 additions & 12 deletions

File tree

.github/actions/issues-helper/action.yml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Issues Helper
2-
description: Create comments or close stale issues by label.
2+
description: Create comments, close stale issues by label, or lock inactive closed issues.
33
inputs:
44
actions:
55
required: true
6-
description: One of `create-comment`, `close-issues`.
6+
description: One of `create-comment`, `close-issues`, `lock-closed-issues`.
77
token:
88
required: true
99
description: GitHub token.
@@ -18,7 +18,7 @@ inputs:
1818
description: Comment body. Required for `create-comment`.
1919
inactive-day:
2020
required: false
21-
description: Close issues whose matching label was added at least this many days ago and have had no activity since then. Required for `close-issues`.
21+
description: Close or lock issues that have had no activity for this many days. Required for `close-issues` and `lock-closed-issues`.
2222

2323
runs:
2424
using: composite
@@ -91,3 +91,41 @@ runs:
9191
if (closed === 0) {
9292
console.log(`No stale items with label "${labels}" found`)
9393
}
94+
95+
- name: Lock inactive closed issues
96+
if: inputs.actions == 'lock-closed-issues'
97+
# Mirrors the issue-only behavior previously used from:
98+
# https://github.com/dessant/lock-threads/blob/7266a7ce5c1df01b1c6db85bf8cd86c737dadbe7/src/index.js
99+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
100+
env:
101+
INPUT_INACTIVE_DAY: ${{ inputs.inactive-day }}
102+
with:
103+
github-token: ${{ inputs.token }}
104+
script: |
105+
const inactiveDay = Number(process.env.INPUT_INACTIVE_DAY)
106+
const cutoff = new Date(Date.now() - inactiveDay * 24 * 60 * 60 * 1000)
107+
const cutoffTimestamp = cutoff.toISOString().split('.')[0] + 'Z'
108+
const query = `repo:${context.repo.owner}/${context.repo.repo} updated:<${cutoffTimestamp} is:closed is:unlocked is:issue`
109+
110+
const { data } = await github.rest.search.issuesAndPullRequests({
111+
q: query,
112+
sort: 'updated',
113+
order: 'desc',
114+
per_page: 50,
115+
})
116+
const issues = data.items.filter(issue => !issue.locked)
117+
118+
let locked = 0
119+
for (const issue of issues) {
120+
console.log(`Locking #${issue.number}, updated at ${issue.updated_at}`)
121+
await github.rest.issues.lock({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
issue_number: issue.number,
125+
})
126+
locked++
127+
}
128+
129+
if (locked === 0) {
130+
console.log(`No inactive closed issues found`)
131+
}

.github/workflows/lock-closed-issues.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ on:
55
- cron: '0 0 * * *'
66

77
permissions:
8+
contents: read # to check out the repo for local actions
89
issues: write
910

1011
jobs:
1112
action:
1213
if: github.repository == 'vitejs/vite-plugin-react'
1314
runs-on: ubuntu-latest
1415
steps:
15-
- uses: dessant/lock-threads@7266a7ce5c1df01b1c6db85bf8cd86c737dadbe7 # v6
16+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
1617
with:
17-
github-token: ${{ secrets.GITHUB_TOKEN }}
18-
issue-inactive-days: '14'
19-
#issue-comment: |
20-
# This issue has been locked since it has been closed for more than 14 days.
21-
#
22-
# If you have found a concrete bug or regression related to it, please open a new [bug report](https://github.com/vitejs/vite-plugin-react/issues/new/choose) with a reproduction against the latest Vite version. If you have any other comments you should join the chat at [Vite Land](https://chat.vite.dev) or create a new [discussion](https://github.com/vitejs/vite-plugin-react/discussions).
23-
issue-lock-reason: ''
24-
process-only: 'issues'
18+
persist-credentials: false
19+
ref: main
20+
21+
- uses: ./.github/actions/issues-helper
22+
with:
23+
actions: lock-closed-issues
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
inactive-day: 14

0 commit comments

Comments
 (0)