Skip to content

Commit 08977ef

Browse files
Adds options to filter labels and bumps node version to 16 (#13)
* Adds options to filter labels and bumps node version to 16 Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Changes variable name, updates version references and applies formatting Signed-off-by: Darshit Chanpura <dchanp@amazon.com> --------- Signed-off-by: Darshit Chanpura <dchanp@amazon.com> Co-authored-by: Michal Vanko <mklakakilli@gmail.com>
1 parent f36c2bd commit 08977ef

8 files changed

Lines changed: 64 additions & 10 deletions

File tree

.github/workflows/copy-labels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
name: Copy labels from linked issues
77
steps:
88
- name: copy-labels
9-
uses: michalvankodev/copy-issue-labels@v1.2.0
9+
uses: michalvankodev/copy-issue-labels@v1.3.0
1010
with:
1111
repo-token: ${{ secrets.GITHUB_TOKEN }}
1212
custom-keywords: |

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
name: Copy labels from linked issues
2020
steps:
2121
- name: copy-labels
22-
uses: michalvankodev/copy-issue-labels@v1.2.1
22+
uses: michalvankodev/copy-issue-labels@v1.3.0
2323
with:
2424
repo-token: ${{ secrets.GITHUB_TOKEN }}
2525
```
@@ -29,7 +29,7 @@ There is also support for different workflows to trigger sync of the labels with
2929
```yml
3030
steps:
3131
- name: copy-labels
32-
uses: michalvankodev/copy-issue-labels@v0.2.12
32+
uses: michalvankodev/copy-issue-labels@v1.3.0
3333
with:
3434
repo-token: ${{ secrets.GITHUB_TOKEN }}
3535
issue-number: ${{ github.event.inputs.issue }}
@@ -59,12 +59,31 @@ You can provide from-title = true to parse the issue numbers from title
5959
```yml
6060
steps:
6161
- name: copy-labels
62-
uses: michalvankodev/copy-issue-labels@v1.2.1
62+
uses: michalvankodev/copy-issue-labels@v1.3.0
6363
with:
6464
repo-token: ${{ secrets.GITHUB_TOKEN }}
6565
from-title: true
6666
```
6767

68+
## Include-Exclude labels
69+
70+
You can provide an inclusion/exclusion list to filter linked issue labels before copying them to the PR
71+
72+
```yml
73+
steps:
74+
- name: copy-labels
75+
uses: michalvankodev/copy-issue-labels@v1.3.0
76+
with:
77+
repo-token: ${{ secrets.GITHUB_TOKEN }}
78+
labels-to-include: |
79+
documentation
80+
enhancement
81+
labels-to-exclude: |
82+
untriaged
83+
triaged
84+
```
85+
86+
6887
## Development
6988

7089
The deployed code is stored in the repository as that's how github action runner is able to run the action with _runners_.

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ inputs:
1111
from-title:
1212
description: 'To parse the issue numbers from title, a boolean'
1313
required: false
14+
labels-to-include:
15+
description: 'List of labels that should be included when copying'
16+
required: false
17+
labels-to-exclude:
18+
description: 'List of labels that should be excluded when copying'
1419
issue-number:
1520
description: 'Get linked issues from Pull Request number'
1621
required: false

dist/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function run() {
6060
return __awaiter(this, void 0, void 0, function* () {
6161
const token = core.getInput('repo-token', { required: true });
6262
const customKeywords = getInputAsArray('custom-keywords', { required: false });
63+
const labelsToCopy = getInputAsArray('labels-to-copy', { required: false });
64+
const labelsToExclude = getInputAsArray('labels-to-exclude', { required: false });
6365
const fromTitle = getBooleanInput('from-title', { required: false });
6466
const issueNumber = getIssueNumber(core.getInput('issue-number', { required: false }));
6567
if (issueNumber === undefined) {
@@ -87,7 +89,19 @@ function run() {
8789
})));
8890
const labels = issue_parser_1.uniq(connectedLabelsResponses.reduce((acc, response) => {
8991
const issueLabels = response.data.map((label) => label.name);
90-
return [...acc, ...issueLabels];
92+
// Filter out unwanted labels and keep only the ones that are needed
93+
const filteredLabels = issueLabels.filter(label => {
94+
if (labelsToCopy.length > 0 && !labelsToCopy.includes(label)) {
95+
// Label not in labelsToCopy
96+
return false;
97+
}
98+
if (labelsToExclude.length > 0 && labelsToExclude.includes(label)) {
99+
// Label in labelsToExclude
100+
return false;
101+
}
102+
return true;
103+
});
104+
return [...acc, ...filteredLabels];
91105
}, []));
92106
labels.length > 0 && (yield client.issues.addLabels({
93107
owner: github.context.repo.owner,

dist/index.js.map

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copy-issue-labels",
3-
"version": "1.0.0",
3+
"version": "1.3.0",
44
"description": "Github action for copying labels of linked issues",
55
"main": "lib/index.js",
66
"scripts": {

src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function getBooleanInput(name: string, options?: core.InputOptions, defaultValue
2828
async function run() {
2929
const token = core.getInput('repo-token', { required: true })
3030
const customKeywords = getInputAsArray('custom-keywords', { required: false })
31+
const labelsToInclude = getInputAsArray('labels-to-include', { required: false });
32+
const labelsToExclude = getInputAsArray('labels-to-exclude', { required: false });
3133
const fromTitle = getBooleanInput('from-title', { required: false })
3234

3335
const issueNumber = getIssueNumber(
@@ -75,8 +77,21 @@ async function run() {
7577

7678
const labels = uniq(
7779
connectedLabelsResponses.reduce<string[]>((acc, response) => {
78-
const issueLabels = response.data.map((label) => label.name)
79-
return [...acc, ...issueLabels]
80+
const issueLabels = response.data.map((label) => label.name);
81+
// Filter out unwanted labels and keep only the ones that are needed
82+
const filteredLabels = issueLabels.filter(label => {
83+
if (labelsToInclude.length > 0 && !labelsToInclude.includes(label)) {
84+
// Label not in `labelsToInclude`
85+
return false;
86+
}
87+
if (labelsToExclude.length > 0 && labelsToExclude.includes(label)) {
88+
// Label in `labelsToExclude`
89+
return false;
90+
}
91+
return true;
92+
});
93+
94+
return [...acc, ...filteredLabels]
8095
}, [])
8196
)
8297

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
3+
"target": "es2016" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
44
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
55
"outDir": "./lib" /* Redirect output structure to the directory. */,
66
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,

0 commit comments

Comments
 (0)