Skip to content

Commit

Permalink
Adds options to filter labels and bumps node version to 16 (#13)
Browse files Browse the repository at this point in the history
* Adds options to filter labels and bumps node version to 16

Signed-off-by: Darshit Chanpura <[email protected]>

* Changes variable name, updates version references and applies formatting

Signed-off-by: Darshit Chanpura <[email protected]>

---------

Signed-off-by: Darshit Chanpura <[email protected]>
Co-authored-by: Michal Vanko <[email protected]>
  • Loading branch information
DarshitChanpura and michalvankodev authored Sep 12, 2023
1 parent f36c2bd commit 08977ef
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/copy-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
name: Copy labels from linked issues
steps:
- name: copy-labels
uses: michalvankodev/copy-issue-labels@v1.2.0
uses: michalvankodev/copy-issue-labels@v1.3.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
custom-keywords: |
Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: Copy labels from linked issues
steps:
- name: copy-labels
uses: michalvankodev/copy-issue-labels@v1.2.1
uses: michalvankodev/copy-issue-labels@v1.3.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
```
Expand All @@ -29,7 +29,7 @@ There is also support for different workflows to trigger sync of the labels with
```yml
steps:
- name: copy-labels
uses: michalvankodev/copy-issue-labels@v0.2.12
uses: michalvankodev/copy-issue-labels@v1.3.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.inputs.issue }}
Expand Down Expand Up @@ -59,12 +59,31 @@ You can provide from-title = true to parse the issue numbers from title
```yml
steps:
- name: copy-labels
uses: michalvankodev/copy-issue-labels@v1.2.1
uses: michalvankodev/copy-issue-labels@v1.3.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
from-title: true
```

## Include-Exclude labels

You can provide an inclusion/exclusion list to filter linked issue labels before copying them to the PR

```yml
steps:
- name: copy-labels
uses: michalvankodev/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
labels-to-include: |
documentation
enhancement
labels-to-exclude: |
untriaged
triaged
```


## Development

The deployed code is stored in the repository as that's how github action runner is able to run the action with _runners_.
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ inputs:
from-title:
description: 'To parse the issue numbers from title, a boolean'
required: false
labels-to-include:
description: 'List of labels that should be included when copying'
required: false
labels-to-exclude:
description: 'List of labels that should be excluded when copying'
issue-number:
description: 'Get linked issues from Pull Request number'
required: false
Expand Down
16 changes: 15 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
const token = core.getInput('repo-token', { required: true });
const customKeywords = getInputAsArray('custom-keywords', { required: false });
const labelsToCopy = getInputAsArray('labels-to-copy', { required: false });
const labelsToExclude = getInputAsArray('labels-to-exclude', { required: false });
const fromTitle = getBooleanInput('from-title', { required: false });
const issueNumber = getIssueNumber(core.getInput('issue-number', { required: false }));
if (issueNumber === undefined) {
Expand Down Expand Up @@ -87,7 +89,19 @@ function run() {
})));
const labels = issue_parser_1.uniq(connectedLabelsResponses.reduce((acc, response) => {
const issueLabels = response.data.map((label) => label.name);
return [...acc, ...issueLabels];
// Filter out unwanted labels and keep only the ones that are needed
const filteredLabels = issueLabels.filter(label => {
if (labelsToCopy.length > 0 && !labelsToCopy.includes(label)) {
// Label not in labelsToCopy
return false;
}
if (labelsToExclude.length > 0 && labelsToExclude.includes(label)) {
// Label in labelsToExclude
return false;
}
return true;
});
return [...acc, ...filteredLabels];
}, []));
labels.length > 0 && (yield client.issues.addLabels({
owner: github.context.repo.owner,
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copy-issue-labels",
"version": "1.0.0",
"version": "1.3.0",
"description": "Github action for copying labels of linked issues",
"main": "lib/index.js",
"scripts": {
Expand Down
19 changes: 17 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function getBooleanInput(name: string, options?: core.InputOptions, defaultValue
async function run() {
const token = core.getInput('repo-token', { required: true })
const customKeywords = getInputAsArray('custom-keywords', { required: false })
const labelsToInclude = getInputAsArray('labels-to-include', { required: false });
const labelsToExclude = getInputAsArray('labels-to-exclude', { required: false });
const fromTitle = getBooleanInput('from-title', { required: false })

const issueNumber = getIssueNumber(
Expand Down Expand Up @@ -75,8 +77,21 @@ async function run() {

const labels = uniq(
connectedLabelsResponses.reduce<string[]>((acc, response) => {
const issueLabels = response.data.map((label) => label.name)
return [...acc, ...issueLabels]
const issueLabels = response.data.map((label) => label.name);
// Filter out unwanted labels and keep only the ones that are needed
const filteredLabels = issueLabels.filter(label => {
if (labelsToInclude.length > 0 && !labelsToInclude.includes(label)) {
// Label not in `labelsToInclude`
return false;
}
if (labelsToExclude.length > 0 && labelsToExclude.includes(label)) {
// Label in `labelsToExclude`
return false;
}
return true;
});

return [...acc, ...filteredLabels]
}, [])
)

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"target": "es2016" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
Expand Down

0 comments on commit 08977ef

Please sign in to comment.