Skip to content

Commit 3a16293

Browse files
hi-ogawacodex
andauthored
ci: replace issues-helper action with inline script (#1237)
Co-authored-by: Codex <noreply@openai.com>
1 parent 5e62127 commit 3a16293

3 files changed

Lines changed: 114 additions & 22 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Issues Helper
2+
description: Create comments or close stale issues by label.
3+
inputs:
4+
actions:
5+
required: true
6+
description: One of `create-comment`, `close-issues`.
7+
token:
8+
required: true
9+
description: GitHub token.
10+
issue-number:
11+
required: false
12+
description: Issue number. Required for `create-comment`.
13+
labels:
14+
required: false
15+
description: Comma-separated label names. Required for `close-issues`.
16+
body:
17+
required: false
18+
description: Comment body. Required for `create-comment`.
19+
inactive-day:
20+
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`.
22+
23+
runs:
24+
using: composite
25+
steps:
26+
- name: Create comment
27+
if: inputs.actions == 'create-comment'
28+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
29+
env:
30+
INPUT_ISSUE_NUMBER: ${{ inputs.issue-number }}
31+
INPUT_BODY: ${{ inputs.body }}
32+
with:
33+
github-token: ${{ inputs.token }}
34+
script: |
35+
await github.rest.issues.createComment({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
issue_number: Number(process.env.INPUT_ISSUE_NUMBER),
39+
body: process.env.INPUT_BODY,
40+
})
41+
42+
- name: Close stale issues
43+
if: inputs.actions == 'close-issues'
44+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
45+
env:
46+
INPUT_LABELS: ${{ inputs.labels }}
47+
INPUT_INACTIVE_DAY: ${{ inputs.inactive-day }}
48+
with:
49+
github-token: ${{ inputs.token }}
50+
script: |
51+
const labels = process.env.INPUT_LABELS
52+
const inactiveDay = Number(process.env.INPUT_INACTIVE_DAY)
53+
const cutoff = new Date(Date.now() - inactiveDay * 24 * 60 * 60 * 1000)
54+
const labelSet = new Set(labels.split(',').map(label => label.trim()).filter(Boolean))
55+
56+
const issues = await github.paginate(github.rest.issues.listForRepo, {
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
state: 'open',
60+
labels,
61+
per_page: 100,
62+
})
63+
64+
let closed = 0
65+
for (const issue of issues) {
66+
if (issue.pull_request) continue
67+
if (new Date(issue.updated_at) > cutoff) continue
68+
69+
const events = await github.paginate(github.rest.issues.listEvents, {
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
issue_number: issue.number,
73+
per_page: 100,
74+
})
75+
const labeledAt = events
76+
.filter(event => event.event === 'labeled' && labelSet.has(event.label?.name))
77+
.at(-1)?.created_at
78+
79+
if (!labeledAt || new Date(labeledAt) > cutoff) continue
80+
81+
console.log(`Closing #${issue.number}, labeled at ${labeledAt}, updated at ${issue.updated_at}`)
82+
await github.rest.issues.update({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
issue_number: issue.number,
86+
state: 'closed',
87+
})
88+
closed++
89+
}
90+
91+
if (closed === 0) {
92+
console.log(`No stale items with label "${labels}" found`)
93+
}

.github/workflows/issue-close-require.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ jobs:
99
if: github.repository == 'vitejs/vite-plugin-react'
1010
runs-on: ubuntu-latest
1111
permissions:
12-
issues: write # for actions-cool/issues-helper to update issues
13-
pull-requests: write # for actions-cool/issues-helper to update PRs
12+
contents: read # to check out the repo for local actions
13+
issues: write # to close stale issues
1414
steps:
15+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
16+
with:
17+
persist-credentials: false
18+
ref: main
19+
1520
- name: need reproduction
16-
uses: actions-cool/issues-helper@200c78641dbf33838311e5a1e0c31bbdb92d7cf0 # v3
21+
uses: ./.github/actions/issues-helper
1722
with:
18-
actions: 'close-issues'
23+
actions: close-issues
1924
token: ${{ secrets.GITHUB_TOKEN }}
20-
labels: 'need reproduction'
25+
labels: need reproduction
2126
inactive-day: 3

.github/workflows/issue-labeled.yml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,30 @@ jobs:
99
if: github.repository == 'vitejs/vite-plugin-react'
1010
runs-on: ubuntu-latest
1111
permissions:
12-
issues: write # for actions-cool/issues-helper to update issues
13-
pull-requests: write # for actions-cool/issues-helper to update PRs
12+
contents: read # to check out the repo for local actions
13+
issues: write # to comment on issues
1414
steps:
15+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
16+
with:
17+
persist-credentials: false
18+
ref: main
19+
1520
- name: contribution welcome
1621
if: github.event.label.name == 'contribution welcome' || github.event.label.name == 'help wanted'
17-
uses: actions-cool/issues-helper@200c78641dbf33838311e5a1e0c31bbdb92d7cf0 # v3
22+
uses: ./.github/actions/issues-helper
1823
with:
19-
actions: 'create-comment, remove-labels'
24+
actions: create-comment
2025
token: ${{ secrets.GITHUB_TOKEN }}
2126
issue-number: ${{ github.event.issue.number }}
2227
body: |
2328
Hello @${{ github.event.issue.user.login }}. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
24-
labels: 'pending triage, need reproduction'
25-
26-
- name: remove pending
27-
if: (github.event.label.name == 'enhancement' || contains(github.event.label.description, '(priority)')) && contains(github.event.issue.labels.*.name, 'pending triage')
28-
uses: actions-cool/issues-helper@200c78641dbf33838311e5a1e0c31bbdb92d7cf0 # v3
29-
with:
30-
actions: 'remove-labels'
31-
token: ${{ secrets.GITHUB_TOKEN }}
32-
issue-number: ${{ github.event.issue.number }}
33-
labels: 'pending triage'
3429
3530
- name: need reproduction
3631
if: github.event.label.name == 'need reproduction'
37-
uses: actions-cool/issues-helper@200c78641dbf33838311e5a1e0c31bbdb92d7cf0 # v3
32+
uses: ./.github/actions/issues-helper
3833
with:
39-
actions: 'create-comment, remove-labels'
34+
actions: create-comment
4035
token: ${{ secrets.GITHUB_TOKEN }}
4136
issue-number: ${{ github.event.issue.number }}
4237
body: |
4338
Hello @${{ github.event.issue.user.login }}. Please provide a [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) using a GitHub repository or [StackBlitz](https://vite.new). Issues marked with `need reproduction` will be closed if they have no activity within 3 days.
44-
labels: 'pending triage'

0 commit comments

Comments
 (0)