Skip to content

Commit 0a0976f

Browse files
committed
feat: lock discussions
BREAKING CHANGE: Discussions are also processed by default, set the `process-only` input parameter to preserve the old behavior ```yaml steps: - uses: dessant/lock-threads@v5 with: process-only: 'issues, prs' ``` Closes #25.
1 parent 53f3f0c commit 0a0976f

File tree

6 files changed

+510
-132
lines changed

6 files changed

+510
-132
lines changed

README.md

Lines changed: 122 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Lock Threads
22

3-
Lock Threads is a GitHub Action that locks closed issues
4-
and pull requests after a period of inactivity.
3+
Lock Threads is a GitHub Action that locks closed issues,
4+
pull requests and discussions after a period of inactivity.
55

6-
<img width="800" src="https://raw.githubusercontent.com/dessant/lock-threads/master/assets/screenshot.png">
6+
<img width="800" src="https://raw.githubusercontent.com/dessant/lock-threads/main/assets/screenshot.png">
77

88
## Supporting the Project
99

@@ -16,13 +16,13 @@ please consider contributing with
1616

1717
## Usage
1818

19-
Create the `lock.yml` workflow file in the `.github/workflows` directory,
20-
use one of the [example workflows](#examples) to get started.
19+
Create the `lock-threads.yml` workflow file in the `.github/workflows`
20+
directory, use one of the [example workflows](#examples) to get started.
2121

2222
### Inputs
2323

2424
<!-- prettier-ignore -->
25-
The action can be configured using [input parameters](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith).
25+
The action can be configured using [input parameters](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepswith).
2626

2727
- **`github-token`**
2828
- GitHub access token, value must be `${{ github.token }}` or an encrypted
@@ -146,9 +146,65 @@ The action can be configured using [input parameters](https://docs.github.com/en
146146
- Reason for locking a pull request, value must be one
147147
of `resolved`, `off-topic`, `too heated`, `spam` or `''`
148148
- Optional, defaults to `resolved`
149+
- **`discussion-inactive-days`**
150+
- Number of days of inactivity before a closed discussion is locked
151+
- Optional, defaults to `365`
152+
- **`exclude-discussion-created-before`**
153+
- Do not lock discussions created before a given date,
154+
value must follow ISO 8601, ignored
155+
when `exclude-discussion-created-between` is set
156+
- Optional, defaults to `''`
157+
- **`exclude-discussion-created-after`**
158+
- Do not lock discussions created after a given date,
159+
value must follow ISO 8601, ignored
160+
when `exclude-discussion-created-between` is set
161+
- Optional, defaults to `''`
162+
- **`exclude-discussion-created-between`**
163+
- Do not lock discussions created in a given time interval,
164+
value must follow ISO 8601
165+
- Optional, defaults to `''`
166+
- **`exclude-discussion-closed-before`**
167+
- Do not lock discussions closed before a given date,
168+
value must follow ISO 8601, ignored
169+
when `exclude-discussion-closed-between` is set
170+
- Optional, defaults to `''`
171+
- **`exclude-discussion-closed-after`**
172+
- Do not lock discussions closed after a given date,
173+
value must follow ISO 8601, ignored
174+
when `exclude-discussion-closed-between` is set
175+
- Optional, defaults to `''`
176+
- **`exclude-discussion-closed-between`**
177+
- Do not lock discussions closed in a given time interval,
178+
value must follow ISO 8601
179+
- Optional, defaults to `''`
180+
- **`include-any-discussion-labels`**
181+
- Only lock discussions with any of these labels, value must be
182+
a comma separated list of labels or `''`, ignored
183+
when `include-all-discussion-labels` is set
184+
- Optional, defaults to `''`
185+
- **`include-all-discussion-labels`**
186+
- Only lock discussions with all these labels, value must be
187+
a comma separated list of labels or `''`
188+
- Optional, defaults to `''`
189+
- **`exclude-any-discussion-labels`**
190+
- Do not lock discussions with any of these labels, value must be
191+
a comma separated list of labels or `''`
192+
- Optional, defaults to `''`
193+
- **`add-discussion-labels`**
194+
- Labels to add before locking a discussion, value must be
195+
a comma separated list of labels or `''`
196+
- Optional, defaults to `''`
197+
- **`remove-discussion-labels`**
198+
- Labels to remove before locking a discussion, value must be
199+
a comma separated list of labels or `''`
200+
- Optional, defaults to `''`
201+
- **`discussion-comment`**
202+
- Comment to post before locking a discussion
203+
- Optional, defaults to `''`
149204
- **`process-only`**
150-
- Limit locking to only issues or pull requests, value must be
151-
one of `issues`, `prs` or `''`
205+
- Only lock issues, pull requests or discussions,
206+
value must be a comma separated list, list items must be
207+
one of `issues`, `prs` or `discussions`
152208
- Optional, defaults to `''`
153209
- **`log-output`**
154210
- Log output parameters, value must be either `true` or `false`
@@ -165,11 +221,15 @@ The action can be configured using [input parameters](https://docs.github.com/en
165221
- Pull requests that have been locked, value is a JSON string in the form
166222
of `[{"owner": "actions", "repo": "toolkit", "issue_number": 1}]`
167223
- Defaults to `''`
224+
- **`discussions`**
225+
- Discussions that have been locked, value is a JSON string in the form
226+
of `[{"owner": "actions", "repo": "toolkit", "discussion_number": 1}]`
227+
- Defaults to `''`
168228

169229
## Examples
170230

171-
The following workflow will search once an hour for closed issues
172-
and pull requests that have not had any activity
231+
The following workflow will search once an hour for closed issues,
232+
pull requests and discussions that have not had any activity
173233
in the past year and can be locked.
174234

175235
<!-- prettier-ignore -->
@@ -184,19 +244,20 @@ on:
184244
permissions:
185245
issues: write
186246
pull-requests: write
247+
discussions: write
187248

188249
concurrency:
189-
group: lock
250+
group: lock-threads
190251

191252
jobs:
192253
action:
193254
runs-on: ubuntu-latest
194255
steps:
195-
- uses: dessant/lock-threads@v4
256+
- uses: dessant/lock-threads@v5
196257
```
197258
198-
Edit the workflow after the initial backlog of issues and pull requests
199-
has been processed to reduce the frequency of scheduled runs.
259+
Edit the workflow after the initial backlog of issues, pull requests
260+
and discussions has been processed to reduce the frequency of scheduled runs.
200261
Running the workflow only once a day helps reduce resource usage.
201262
202263
<!-- prettier-ignore -->
@@ -223,15 +284,16 @@ on:
223284
permissions:
224285
issues: write
225286
pull-requests: write
287+
discussions: write
226288

227289
concurrency:
228-
group: lock
290+
group: lock-threads
229291

230292
jobs:
231293
action:
232294
runs-on: ubuntu-latest
233295
steps:
234-
- uses: dessant/lock-threads@v4
296+
- uses: dessant/lock-threads@v5
235297
with:
236298
github-token: ${{ github.token }}
237299
issue-inactive-days: '365'
@@ -262,19 +324,32 @@ jobs:
262324
remove-pr-labels: ''
263325
pr-comment: ''
264326
pr-lock-reason: 'resolved'
327+
discussion-inactive-days: '365'
328+
exclude-discussion-created-before: ''
329+
exclude-discussion-created-after: ''
330+
exclude-discussion-created-between: ''
331+
exclude-discussion-closed-before: ''
332+
exclude-discussion-closed-after: ''
333+
exclude-discussion-closed-between: ''
334+
include-any-discussion-labels: ''
335+
include-all-discussion-labels: ''
336+
exclude-any-discussion-labels: ''
337+
add-discussion-labels: ''
338+
remove-discussion-labels: ''
339+
discussion-comment: ''
265340
process-only: ''
266341
log-output: false
267342
```
268343
269-
### Filtering issues and pull requests
344+
### Filtering issues, pull requests and discussions
270345
271346
This step will lock only issues, and exclude issues created before 2018,
272347
or those with the `upstream` or `help-wanted` labels applied.
273348

274349
<!-- prettier-ignore -->
275350
```yaml
276351
steps:
277-
- uses: dessant/lock-threads@v4
352+
- uses: dessant/lock-threads@v5
278353
with:
279354
exclude-issue-created-before: '2018-01-01T00:00:00Z'
280355
exclude-any-issue-labels: 'upstream, help-wanted'
@@ -287,7 +362,7 @@ with the `wip` label applied.
287362
<!-- prettier-ignore -->
288363
```yaml
289364
steps:
290-
- uses: dessant/lock-threads@v4
365+
- uses: dessant/lock-threads@v5
291366
with:
292367
exclude-any-pr-labels: 'wip'
293368
process-only: 'prs'
@@ -299,7 +374,7 @@ or those created in 2018 and 2019.
299374
<!-- prettier-ignore -->
300375
```yaml
301376
steps:
302-
- uses: dessant/lock-threads@v4
377+
- uses: dessant/lock-threads@v5
303378
with:
304379
exclude-issue-created-between: '2018-01-01T00:00:00Z/2019-12-31T23:59:59.999Z'
305380
exclude-issue-closed-before: '2018-01-01T00:00:00Z'
@@ -313,22 +388,24 @@ labels applied.
313388
<!-- prettier-ignore -->
314389
```yaml
315390
steps:
316-
- uses: dessant/lock-threads@v4
391+
- uses: dessant/lock-threads@v5
317392
with:
318393
include-any-issue-labels: 'incomplete, invalid'
319394
include-all-pr-labels: 'qa: done, published'
395+
process-only: 'issues, prs'
320396
321397
```
322398

323-
This step will lock issues that have not had any activity in the past 180 days.
399+
This step will lock discussions that have not had any activity
400+
in the past 180 days.
324401

325402
<!-- prettier-ignore -->
326403
```yaml
327404
steps:
328-
- uses: dessant/lock-threads@v4
405+
- uses: dessant/lock-threads@v5
329406
with:
330-
issue-inactive-days: '180'
331-
process-only: 'issues'
407+
discussion-inactive-days: '180'
408+
process-only: 'discussions'
332409
333410
```
334411

@@ -340,7 +417,7 @@ and apply the `outdated` label to issues.
340417
<!-- prettier-ignore -->
341418
```yaml
342419
steps:
343-
- uses: dessant/lock-threads@v4
420+
- uses: dessant/lock-threads@v5
344421
with:
345422
add-issue-labels: 'outdated'
346423
issue-comment: >
@@ -351,6 +428,7 @@ and apply the `outdated` label to issues.
351428
This pull request has been automatically locked since there
352429
has not been any recent activity after it was closed.
353430
Please open a new issue for related bugs.
431+
process-only: 'issues, prs'
354432
```
355433

356434
This step will apply the `qa: done` and `archived` labels,
@@ -360,10 +438,11 @@ before locking issues.
360438
<!-- prettier-ignore -->
361439
```yaml
362440
steps:
363-
- uses: dessant/lock-threads@v4
441+
- uses: dessant/lock-threads@v5
364442
with:
365443
add-issue-labels: 'qa: done, archived'
366444
remove-issue-labels: 'qa: primary, needs: user feedback'
445+
process-only: 'issues'
367446
```
368447

369448
### Using a personal access token
@@ -372,39 +451,38 @@ The action uses an installation access token by default to interact with GitHub.
372451
You may also authenticate with a personal access token to perform actions
373452
as a GitHub user instead of the `github-actions` app.
374453

375-
Create a [personal access token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token)
454+
Create a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)
376455
with the `repo` or `public_repo` scopes enabled, and add the token as an
377-
[encrypted secret](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)
456+
[encrypted secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository)
378457
for the repository or organization, then provide the action with the secret
379458
using the `github-token` input parameter.
380459

381460
<!-- prettier-ignore -->
382461
```yaml
383462
steps:
384-
- uses: dessant/lock-threads@v4
463+
- uses: dessant/lock-threads@v5
385464
with:
386465
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
387466
```
388467

389-
## How are issues and pull requests determined to be inactive?
468+
## How are issues, pull requests and discussions determined to be inactive?
390469

391-
The action uses GitHub's [updated](https://help.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-by-when-an-issue-or-pull-request-was-created-or-last-updated)
392-
search qualifier to determine inactivity. Any change to an issue or pull request
393-
is considered an update, including comments, changing labels,
394-
applying or removing milestones, or pushing commits.
470+
The action uses GitHub's [updated](https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests#search-by-when-an-issue-or-pull-request-was-created-or-last-updated)
471+
search qualifier to determine inactivity. Any change to an issue, pull request
472+
or discussion is considered an update, including new comments,
473+
or changing labels.
395474

396-
An easy way to check and see which issues or pull requests will initially
397-
be locked is to add the `updated` search qualifier to either the issue
398-
or pull request search field for your repository:
475+
An easy way to see which threads will initially be locked is to add
476+
the `updated` search qualifier to the issue, pull request or discussion
477+
search field for your repository, adjust the date based on the value
478+
of the `*-inactive-days` input parameter:
399479
`is:closed is:unlocked updated:<2018-12-20`.
400-
Adjust the date to be 365 days ago (or whatever you set for `*-inactive-days`)
401-
to see which issues or pull requests will be locked.
402480

403-
## Why are only some issues and pull requests processed?
481+
## Why are only some issues, pull requests and discussions processed?
404482

405-
To avoid triggering abuse prevention mechanisms on GitHub, only 50 issues
406-
and pull requests will be handled at once. If your repository has more
407-
than that, it will just take a few hours or days to process them all.
483+
To avoid triggering abuse prevention mechanisms on GitHub, only 50 threads
484+
will be handled at a time. If your repository has more than that,
485+
it will take a few hours or days to process them all.
408486

409487
## License
410488

action.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Lock Threads'
2-
description: 'Lock closed issues and pull requests after a period of inactivity'
2+
description: 'Lock closed issues, pull requests and discussions after a period of inactivity'
33
author: 'Armin Sebastian'
44
inputs:
55
github-token:
@@ -89,8 +89,47 @@ inputs:
8989
pr-lock-reason:
9090
description: 'Reason for locking a pull request, value must be one of `resolved`, `off-topic`, `too heated` or `spam`'
9191
default: 'resolved'
92+
discussion-inactive-days:
93+
description: 'Number of days of inactivity before a closed discussion is locked'
94+
default: '365'
95+
exclude-discussion-created-before:
96+
description: 'Do not lock discussions created before a given date, value must follow ISO 8601'
97+
default: ''
98+
exclude-discussion-created-after:
99+
description: 'Do not lock discussions created after a given date, value must follow ISO 8601'
100+
default: ''
101+
exclude-discussion-created-between:
102+
description: 'Do not lock discussions created in a given time interval, value must follow ISO 8601'
103+
default: ''
104+
exclude-discussion-closed-before:
105+
description: 'Do not lock discussions closed before a given date, value must follow ISO 8601'
106+
default: ''
107+
exclude-discussion-closed-after:
108+
description: 'Do not lock discussions closed after a given date, value must follow ISO 8601'
109+
default: ''
110+
exclude-discussion-closed-between:
111+
description: 'Do not lock discussions closed in a given time interval, value must follow ISO 8601'
112+
default: ''
113+
include-any-discussion-labels:
114+
description: 'Only lock issues with any of these labels, value must be a comma separated list of labels'
115+
default: ''
116+
include-all-discussion-labels:
117+
description: 'Only lock discussions with all these labels, value must be a comma separated list of labels'
118+
default: ''
119+
exclude-any-discussion-labels:
120+
description: 'Do not lock discussions with any of these labels, value must be a comma separated list of labels'
121+
default: ''
122+
add-discussion-labels:
123+
description: 'Labels to add before locking a discussion, value must be a comma separated list of labels'
124+
default: ''
125+
remove-discussion-labels:
126+
description: 'Labels to remove before locking a discussion, value must be a comma separated list of labels'
127+
default: ''
128+
discussion-comment:
129+
description: 'Comment to post before locking a discussion'
130+
default: ''
92131
process-only:
93-
description: 'Limit locking to only issues or pull requests, value must be one of `issues` or `prs`'
132+
description: 'Only lock issues, pull requests or discussions, value must be a comma separated list, list items must be one of `issues`, `prs` or `discussions`'
94133
default: ''
95134
log-output:
96135
description: 'Log output parameters, value must be either `true` or `false`'
@@ -100,6 +139,8 @@ outputs:
100139
description: 'Issues that have been locked, value is a JSON string'
101140
prs:
102141
description: 'Pull requests that have been locked, value is a JSON string'
142+
discussions:
143+
description: 'Discussions that have been locked, value is a JSON string'
103144
runs:
104145
using: 'node20'
105146
main: 'dist/index.js'

0 commit comments

Comments
 (0)