Skip to content

Commit dd3633c

Browse files
committed
feat: add global contributor removal
1 parent bc7eee9 commit dd3633c

File tree

4 files changed

+135
-17
lines changed

4 files changed

+135
-17
lines changed

README.md

+67-10
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@
88

99
## Features
1010

11-
-Keep control of your triggers
12-
-Keep control of your triggers
13-
-Keep control of your triggers
11+
-open or close issues and pull requests
12+
-add or update comments
13+
-manage the contributors list
1414

1515

1616
## Inputs
1717

1818
| Input | Required | Description | Default |
1919
| ---------------------- | ------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------- |
2020
| token | `true` | GitHub Personal Access Token | |
21-
| addedLabels | `false` | labels to add | |
22-
| removedLabels | `false` | labels to remove |
21+
| addedLabels | `false` | comma seperated stringified list of labels to add | |
22+
| removedLabels | `false` | comma seperated stringified of labels to remove |
2323
| reply | `false` | reply |
24-
| assigneesAdded | `false` | list of assignees to add |
25-
| assigneesRemoved | `false` | list of assignees to remove |
26-
| reviewersAdded | `false` | list of reviewers to add |
27-
| reviewersRemoved | `false` | list of reviewers to remove |
24+
| assigneesAdded | `false` | comma seperated stringified list of assignees to add |
25+
| assigneesRemoved | `false` | comma seperated stringified list of assignees to remove |
26+
| reviewersAdded | `false` | comma seperated stringified list of reviewers to add |
27+
| reviewersRemoved | `false` | comma seperated stringified list of reviewers to remove |
2828
| action | `false` | action to perform (add or update). default to add | `add`
2929
| state | `false` | new issue state (open or closed) |
30+
| clearLabels | `false` | clear existing labels (expected value: `'true'`) |
31+
| clearAssignees | `false` | clear existing assignees (expected value: `'true'`) |
32+
| clearReviewers | `false` | clear existing reviewers (expected value: `'true'`) |
3033

3134

3235
## Examples
@@ -42,9 +45,63 @@ jobs:
4245
runs-on: ubuntu-latest
4346
steps:
4447
- name: add triage label
45-
uses: kerhub/saved-replies@v0.3.0
48+
uses: kerhub/saved-replies@v1.0.0
4649
with:
4750
token: ${{ secrets.GITHUB_TOKEN }}
4851
addedLabels: 'triage'
52+
```
53+
54+
Add a list of assignees on `scope: core` label addition and remove the `triage` label
55+
56+
```yaml
57+
on:
58+
issues:
59+
types: [labeled]
60+
jobs:
61+
scopeCore:
62+
if ${{ github.event.label.name }} == 'scope: core'
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: add core scope
66+
uses: kerhub/[email protected]
67+
with:
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
removedLabels: 'triage'
70+
assigneesAdded: 'geromegrignon'
71+
```
4972

73+
Greet the author on a pull request creation
74+
75+
```yaml
76+
on:
77+
pull_request:
78+
types: [opened]
79+
jobs:
80+
greetings:
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: greet the author
84+
uses: kerhub/[email protected]
85+
with:
86+
token: ${{ secrets.GITHUB_TOKEN }}
87+
reply: 'Hi @${{ github.event.pull_request.user.login }}, thanks for contributing to this project!'
88+
```
89+
90+
Close an pull request on a label addition
91+
92+
```yaml
93+
on:
94+
pull_request:
95+
types: [labeled]
96+
jobs:
97+
closePR:
98+
if: "${{github.event.label.name == 'out of scope' }}"
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: close the pull request
102+
uses: kerhub/[email protected]
103+
with:
104+
token: ${{ secrets.GITHUB_TOKEN }}
105+
state: 'closed'
106+
reply: 'The content of this contribution is out of the scope of the project'
50107
```

action.yml

+15-6
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ inputs:
66
description: 'GitHub Personal Access Token'
77
required: true
88
addedLabels:
9-
description: 'labels to add'
9+
description: 'comma seperated stringified list of labels to add'
1010
required: false
1111
removedLabels:
12-
description: 'labels to remove'
12+
description: 'comma seperated stringified of labels to remove'
1313
required: false
1414
reply:
1515
description: 'reply'
1616
required: false
1717
assigneesAdded:
18-
description: 'list of assignees to add'
18+
description: 'comma seperated stringified list of assignees to add'
1919
required: false
2020
assigneesRemoved:
21-
description: 'list of assignees to remove'
21+
description: 'comma seperated stringified list of assignees to remove'
2222
required: false
2323
reviewersAdded:
24-
description: 'list of reviewers to add'
24+
description: 'comma seperated stringified list of reviewers to add'
2525
required: false
2626
reviewersRemoved:
27-
description: 'list of reviewers to remove'
27+
description: 'comma seperated stringified list of reviewers to remove'
2828
required: false
2929
action:
3030
description: 'action to perform (add or update). default to add'
@@ -33,6 +33,15 @@ inputs:
3333
state:
3434
description: 'new issue state (open or closed)'
3535
required: false
36+
clearLabels:
37+
description: 'comma seperated stringified list of assignees to remove'
38+
required: false
39+
clearAssignees:
40+
description: 'comma seperated stringified list of assignees to remove'
41+
required: false
42+
clearReviewers:
43+
description: 'comma seperated stringified list of assignees to remove'
44+
required: false
3645
runs:
3746
using: 'node12'
3847
main: 'index.js'

index.js

+52
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,42 @@ const removeReviewers = async (reviewers) => {
9696
});
9797
}
9898

99+
const clearAllLabels = async () => {
100+
await octokit.rest.issues.removeAllLabels({
101+
owner: github.context.repo.owner,
102+
repo: github.context.repo.repo,
103+
issue_number: github.context.issue.number,
104+
});
105+
}
106+
107+
const clearAllAssignees = async () => {
108+
const { assignees } = await octokit.rest.issues.get({
109+
owner: github.context.repo.owner,
110+
repo: github.context.repo.repo,
111+
issue_number: github.context.issue.number,
112+
});
113+
await octokit.rest.issues.removeAssignees({
114+
owner: github.context.repo.owner,
115+
repo: github.context.repo.repo,
116+
issue_number: github.context.issue.number,
117+
assignees: assignees.map(assignee => assignee.login)
118+
});
119+
}
120+
121+
const clearAllReviewers = async () => {
122+
const { requested_reviewers } = await octokit.rest.pulls.get({
123+
owner: github.context.repo.owner,
124+
repo: github.context.repo.repo,
125+
pull_number: github.context.issue.number,
126+
});
127+
await octokit.rest.pulls.removeRequestedReviewers({
128+
owner: github.context.repo.owner,
129+
repo: github.context.repo.repo,
130+
pull_number: github.context.issue.number,
131+
reviewers: requested_reviewers.map(reviewer => reviewer.login)
132+
});
133+
}
134+
99135
const formatInputList = (input) => {
100136
return input.split(',').filter(item => item.trim().length);
101137
}
@@ -112,6 +148,10 @@ try {
112148
const reviewersAdded = formatInputList(core.getInput('reviewersAdded'));
113149
const reviewersRemoved = formatInputList(core.getInput('reviewersRemoved'));
114150

151+
const clearLabels = core.getInput('clearLabels');
152+
const clearAssignees = core.getInput('clearAssignees');
153+
const clearReviewers = core.getInput('clearReviewers');
154+
115155
if (!addedLabels && !removedLabels && !reply && !assigneesAdded && !assigneesRemoved && !reviewersAdded && !reviewersRemoved && !state) {
116156
throw new Error('No action specified');
117157
}
@@ -138,6 +178,18 @@ try {
138178
throw new Error(`Invalid state: ${state}`);
139179
}
140180

181+
if (clearLabels === 'true') {
182+
clearAllLabels();
183+
}
184+
185+
if (clearAssignees === 'true') {
186+
clearAllAssignees();
187+
}
188+
189+
if (clearReviewers === 'true') {
190+
clearAllReviewers();
191+
}
192+
141193
if (addedLabels.length) {
142194
addLabels(addedLabels);
143195
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "saved-replies",
3-
"version": "0.3.0",
3+
"version": "1.0.0",
44
"description": "Github Action triggering comment replies",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)