Skip to content

Commit

Permalink
Rename yaml_file input to yaml-file
Browse files Browse the repository at this point in the history
Rename skip_delete input to skip-delete
Rename dry_run input to dry-run
  • Loading branch information
crazy-max committed Aug 20, 2020
1 parent 1ff1894 commit a084826
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 45 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml_file: .res/labels.update.yml
skip_delete: true
dry_run: true
yaml-file: .res/labels.update.yml
skip-delete: true
dry-run: true
-
name: Labeler (exclude part 1)
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml_file: .res/labels.exclude1.yml
dry_run: true
yaml-file: .res/labels.exclude1.yml
dry-run: true
exclude: |
* d*
*enhancement
Expand All @@ -43,7 +43,7 @@ jobs:
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml_file: .res/labels.exclude2.yml
dry_run: true
yaml-file: .res/labels.exclude2.yml
dry-run: true
exclude: |
*fix
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ jobs:
uses: crazy-max/ghaction-github-labeler@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml_file: .github/labels.yml
skip_delete: false
dry_run: false
yaml-file: .github/labels.yml
skip-delete: false
dry-run: false
exclude: |
help*
*issue
Expand All @@ -97,13 +97,13 @@ With this workflow, the YAML configuration above on a [fresh repository](.res/sa

Following inputs can be used as `step.with` keys

| Name | Type | Description |
|-----------------|----------|------------------------------------------------------------------------------------|
| `github-token` | String | [GitHub Token](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
| `yaml_file` | String | Path to YAML file containing labels definitions (default `.github/labels.yml`) |
| `skip_delete` | Bool | If enabled, labels will not be deleted if not found in YAML file (default `false`) |
| `dry_run` | Bool | If enabled, changes will not be applied (default `false`) |
| `exclude` | String | Newline-delimited list of labels pattern(s)/matcher to exclude. |
| Name | Type | Default | Description |
|------------------|---------|------------------------|------------------------------------|
| `github-token` | String | `${{ github.token }}` | [GitHub Token](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
| `yaml-file` | String | `.github/labels.yml` | Path to YAML file containing labels definitions |
| `skip-delete` | Bool | `false` | If enabled, labels will not be deleted if not found in YAML file |
| `dry-run` | Bool | `false` | If enabled, changes will not be applied |
| `exclude` | List | | Comma or newline delimited list of labels pattern(s)/matcher to exclude |

## Keep up-to-date with GitHub Dependabot

Expand Down
10 changes: 7 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ branding:
icon: 'tag'

inputs:
yaml_file:
github-token:
description: 'GitHub Token as provided by secrets'
default: ${{ github.token }}
required: true
yaml-file:
description: 'Path to YAML file containing labels definitions'
default: '.github/labels.yml'
required: false
skip_delete:
skip-delete:
description: 'If enabled, labels will not be deleted if not found in YAML file'
default: 'false'
required: false
dry_run:
dry-run:
description: 'If enabled, changes will not be applied'
default: 'false'
required: false
Expand Down
33 changes: 22 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@ export interface Inputs {
yamlFile: fs.PathLike;
skipDelete: boolean;
dryRun: boolean;
exclude: string[];
}

export async function getInputs(): Promise<Inputs> {
return {
githubToken: core.getInput('github-token'),
yamlFile: path.join(core.getInput('yaml_file') || '.github/labels.yml'),
skipDelete: /true/i.test(core.getInput('skip_delete')),
dryRun: /true/i.test(core.getInput('dry_run'))
yamlFile: path.join(core.getInput('yaml-file') || '.github/labels.yml'),
skipDelete: /true/i.test(core.getInput('skip-delete')),
dryRun: /true/i.test(core.getInput('dry-run')),
exclude: await getInputList('exclude')
};
}

export async function getInputList(name: string): Promise<string[]> {
const items = core.getInput(name);
if (items == '') {
return [];
}
return items.split(/\r?\n/).reduce<string[]>(
(acc, line) =>
acc
.concat(line.split(','))
.filter(pat => pat)
.map(pat => pat.trim()),
[]
);
}
15 changes: 4 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import {getInputs, Inputs} from './context';

let inputs: Inputs;
let octokit;
let liveLabels: Array<Label>;
let fileLabels: Array<Label>;
Expand All @@ -31,7 +32,7 @@ enum LabelStatus {

async function run() {
try {
let inputs: Inputs = await getInputs();
inputs = await getInputs();
octokit = github.getOctokit(inputs.githubToken);

if (!fs.existsSync(inputs.yamlFile)) {
Expand Down Expand Up @@ -200,20 +201,12 @@ async function displayLiveLabels() {
}

async function getExclusions(): Promise<string[]> {
const patterns = core.getInput('exclude');
if (patterns == '') {
if (inputs.exclude.length == 0) {
return [];
}
return matcher(
liveLabels.map(label => label.name),
patterns.split(/\r?\n/).reduce<string[]>(
(acc, line) =>
acc
.concat(line.split(','))
.filter(pat => pat)
.map(pat => pat.trim()),
[]
)
inputs.exclude
);
}

Expand Down

0 comments on commit a084826

Please sign in to comment.