-
Notifications
You must be signed in to change notification settings - Fork 13
76 lines (66 loc) · 2.82 KB
/
remove-needs-more-info.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: 'Remove Needs More Info Label'
on:
issue_comment:
types: [created]
permissions:
issues: write
contents: read
jobs:
debug-and-remove-label:
runs-on: ubuntu-latest
if: github.event.issue.pull_request == null # Ensure it runs only for issue comments
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Remove "needs-more-info" Label and Comment
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue = context.payload.issue;
const user = context.payload.sender;
// Check if the comment was made by the issue creator
if (issue.user.login === user.login) {
const issueNumber = issue.number;
const labelName = 'needs-more-info';
let labelAddedByUser = '';
// Find who added the 'needs-more-info' label
for await (const response of github.paginate.iterator(github.rest.issues.listEvents, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
})) {
const events = response.data;
const labelEvent = events.find(event => event.event === 'labeled' && event.label.name === labelName);
if (labelEvent) {
labelAddedByUser = labelEvent.actor.login;
break; // Stop at the most recent event that added the label
}
}
// Get all labels for the issue
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
// Check if the issue has the specific label
if (labels.some(label => label.name === labelName)) {
// Remove the label
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: labelName,
});
// If someone added the label, comment and tag that user
if (labelAddedByUser) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `@${labelAddedByUser}, the '${labelName}' label has been removed upon receiving further response from the original bug filer.`,
});
}
console.log(`Label "${labelName}" removed from issue #${issueNumber}.`);
}
}