5
5
types : [closed]
6
6
pull_request :
7
7
types : [closed]
8
+ pull_request_target :
9
+ types : [closed]
10
+ workflow_run :
11
+ workflows : ["*"]
12
+ types : [completed]
8
13
9
14
jobs :
10
15
remove-labels-and-assignees :
@@ -15,43 +20,67 @@ jobs:
15
20
with :
16
21
github-token : ${{ secrets.GITHUB_TOKEN }}
17
22
script : |
18
- const issue = context.payload.issue || context.payload.pull_request;
19
23
const { owner, repo } = context.repo;
20
24
21
- try {
22
- const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
23
- owner,
24
- repo,
25
- issue_number: issue.number
26
- });
25
+ async function processIssue(issueNumber) {
26
+ try {
27
+ const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
28
+ owner,
29
+ repo,
30
+ issue_number: issueNumber
31
+ });
27
32
28
- const labelsToKeep = currentLabels
29
- .filter(label => label.name === '⏱︎ Stale')
30
- .map(label => label.name);
33
+ const labelsToKeep = currentLabels
34
+ .filter(label => label.name === '⏱︎ Stale')
35
+ .map(label => label.name);
31
36
32
- await github.rest.issues.setLabels({
33
- owner,
34
- repo,
35
- issue_number: issue.number,
36
- labels: labelsToKeep
37
- });
38
- } catch (error) {
39
- if (error.status !== 404) {
40
- throw error;
41
- }
42
- }
43
-
44
- if (issue.assignees && issue.assignees.length > 0) {
45
- try {
46
- await github.rest.issues.removeAssignees({
37
+ await github.rest.issues.setLabels({
47
38
owner,
48
39
repo,
49
- issue_number: issue.number ,
50
- assignees: issue.assignees.map(assignee => assignee.login)
40
+ issue_number: issueNumber ,
41
+ labels: labelsToKeep
51
42
});
43
+
44
+ const { data: issue } = await github.rest.issues.get({
45
+ owner,
46
+ repo,
47
+ issue_number: issueNumber
48
+ });
49
+
50
+ if (issue.assignees && issue.assignees.length > 0) {
51
+ await github.rest.issues.removeAssignees({
52
+ owner,
53
+ repo,
54
+ issue_number: issueNumber,
55
+ assignees: issue.assignees.map(assignee => assignee.login)
56
+ });
57
+ }
52
58
} catch (error) {
53
59
if (error.status !== 404) {
54
- throw error;
60
+ console.error(`Error processing issue ${issueNumber}:`, error) ;
55
61
}
56
62
}
57
63
}
64
+
65
+ if (context.eventName === 'issues' || context.eventName === 'pull_request' || context.eventName === 'pull_request_target') {
66
+ const issue = context.payload.issue || context.payload.pull_request;
67
+ await processIssue(issue.number);
68
+ } else if (context.eventName === 'workflow_run') {
69
+ const { data: closedIssues } = await github.rest.search.issuesAndPullRequests({
70
+ q: `repo:${owner}/${repo} is:issue is:closed closed:${context.payload.workflow_run.updated_at}`,
71
+ per_page: 100
72
+ });
73
+ for (const issue of closedIssues.items) {
74
+ await processIssue(issue.number);
75
+ }
76
+ }
77
+
78
+ if (context.eventName === 'pull_request' || context.eventName === 'pull_request_target') {
79
+ const { data: closedIssues } = await github.rest.search.issuesAndPullRequests({
80
+ q: `repo:${owner}/${repo} is:issue is:closed linked:${context.payload.pull_request.number}`,
81
+ per_page: 100
82
+ });
83
+ for (const issue of closedIssues.items) {
84
+ await processIssue(issue.number);
85
+ }
86
+ }
0 commit comments