Skip to content

Commit 1ff1894

Browse files
committed
Move GITHUB_TOKEN env var to github-token input
1 parent cf49640 commit 1ff1894

File tree

5 files changed

+113
-53
lines changed

5 files changed

+113
-53
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,27 @@ jobs:
2323
name: Labeler (test)
2424
uses: ./
2525
with:
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
2627
yaml_file: .res/labels.update.yml
2728
skip_delete: true
2829
dry_run: true
29-
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3130
-
3231
name: Labeler (exclude part 1)
3332
uses: ./
3433
with:
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
3535
yaml_file: .res/labels.exclude1.yml
3636
dry_run: true
3737
exclude: |
3838
* d*
3939
*enhancement
4040
*fix
41-
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4341
-
4442
name: Labeler (exclude part 2)
4543
uses: ./
4644
with:
45+
github-token: ${{ secrets.GITHUB_TOKEN }}
4746
yaml_file: .res/labels.exclude2.yml
4847
dry_run: true
4948
exclude: |
5049
*fix
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ___
1919
* [Workflow](#workflow)
2020
* [Customizing](#customizing)
2121
* [inputs](#inputs)
22-
* [environment variables](#environment-variables)
2322
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
2423
* [How can I help?](#how-can-i-help)
2524
* [License](#license)
@@ -71,14 +70,13 @@ jobs:
7170
if: success()
7271
uses: crazy-max/ghaction-github-labeler@v2
7372
with:
73+
github-token: ${{ secrets.GITHUB_TOKEN }}
7474
yaml_file: .github/labels.yml
7575
skip_delete: false
7676
dry_run: false
7777
exclude: |
7878
help*
7979
*issue
80-
env:
81-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8280
```
8381

8482
With this workflow, the YAML configuration above on a [fresh repository](.res/samples/original.yml), this will:
@@ -101,19 +99,12 @@ Following inputs can be used as `step.with` keys
10199

102100
| Name | Type | Description |
103101
|-----------------|----------|------------------------------------------------------------------------------------|
102+
| `github-token` | String | [GitHub Token](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
104103
| `yaml_file` | String | Path to YAML file containing labels definitions (default `.github/labels.yml`) |
105104
| `skip_delete` | Bool | If enabled, labels will not be deleted if not found in YAML file (default `false`) |
106105
| `dry_run` | Bool | If enabled, changes will not be applied (default `false`) |
107106
| `exclude` | String | Newline-delimited list of labels pattern(s)/matcher to exclude. |
108107

109-
### environment variables
110-
111-
Following environment variables can be used as `step.env` keys
112-
113-
| Name | Description |
114-
|----------------|--------------------------------------|
115-
| `GITHUB_TOKEN` | [GITHUB_TOKEN](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
116-
117108
## Keep up-to-date with GitHub Dependabot
118109

119110
Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)

dist/index.js

Lines changed: 72 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import * as core from '@actions/core';
4+
5+
export interface Inputs {
6+
githubToken: string;
7+
yamlFile: fs.PathLike;
8+
skipDelete: boolean;
9+
dryRun: boolean;
10+
}
11+
12+
export async function getInputs(): Promise<Inputs> {
13+
return {
14+
githubToken: core.getInput('github-token'),
15+
yamlFile: path.join(core.getInput('yaml_file') || '.github/labels.yml'),
16+
skipDelete: /true/i.test(core.getInput('skip_delete')),
17+
dryRun: /true/i.test(core.getInput('dry_run'))
18+
};
19+
}

src/main.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as fs from 'fs';
2-
import * as path from 'path';
32
import * as yaml from 'js-yaml';
43
import matcher from 'matcher';
54
import * as core from '@actions/core';
65
import * as github from '@actions/github';
6+
import {getInputs, Inputs} from './context';
77

8-
const octokit = github.getOctokit(process.env['GITHUB_TOKEN'] || '');
8+
let octokit;
99
let liveLabels: Array<Label>;
1010
let fileLabels: Array<Label>;
1111
let exclusions: Array<string>;
@@ -31,17 +31,16 @@ enum LabelStatus {
3131

3232
async function run() {
3333
try {
34-
const yaml_file: fs.PathLike = path.join(core.getInput('yaml_file') || '.github/labels.yml');
35-
const skip_delete: boolean = /true/i.test(core.getInput('skip_delete'));
36-
const dry_run: boolean = /true/i.test(core.getInput('dry_run'));
34+
let inputs: Inputs = await getInputs();
35+
octokit = github.getOctokit(inputs.githubToken);
3736

38-
if (!fs.existsSync(yaml_file)) {
39-
core.setFailed(`Cannot find YAML file ${yaml_file}`);
37+
if (!fs.existsSync(inputs.yamlFile)) {
38+
core.setFailed(`Cannot find YAML file ${inputs.yamlFile}`);
4039
return;
4140
}
4241

4342
liveLabels = await getLiveLabels();
44-
fileLabels = await getFileLabels(yaml_file);
43+
fileLabels = await getFileLabels(inputs.yamlFile);
4544
await displayLiveLabels();
4645

4746
core.info(`🏃 Running GitHub Labeler`);
@@ -50,11 +49,11 @@ async function run() {
5049
for (const actionLabel of actionLabels) {
5150
switch (actionLabel.ghaction_status) {
5251
case LabelStatus.Exclude: {
53-
core.info(`${dry_run ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
52+
core.info(`${inputs.dryRun ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
5453
break;
5554
}
5655
case LabelStatus.Create: {
57-
if (dry_run) {
56+
if (inputs.dryRun) {
5857
core.info(`[dryrun] ${actionLabel.ghaction_log}`);
5958
break;
6059
}
@@ -77,7 +76,7 @@ async function run() {
7776
break;
7877
}
7978
case LabelStatus.Update: {
80-
if (dry_run) {
79+
if (inputs.dryRun) {
8180
core.info(`[dryrun] ${actionLabel.ghaction_log}`);
8281
break;
8382
}
@@ -101,7 +100,7 @@ async function run() {
101100
break;
102101
}
103102
case LabelStatus.Rename: {
104-
if (dry_run) {
103+
if (inputs.dryRun) {
105104
core.info(`[dryrun] ${actionLabel.ghaction_log}`);
106105
break;
107106
}
@@ -125,11 +124,11 @@ async function run() {
125124
break;
126125
}
127126
case LabelStatus.Delete: {
128-
if (skip_delete) {
129-
core.info(`${dry_run ? '[dryrun] ' : ''}⛔️ Skipping delete for '${actionLabel.name}' (skip_delete on)`);
127+
if (inputs.skipDelete) {
128+
core.info(`${inputs.dryRun ? '[dryrun] ' : ''}⛔️ Skipping delete for '${actionLabel.name}' (inputs.skipDelete on)`);
130129
break;
131130
}
132-
if (dry_run) {
131+
if (inputs.dryRun) {
133132
core.info(`[dryrun] ${actionLabel.ghaction_log}`);
134133
break;
135134
}
@@ -147,16 +146,16 @@ async function run() {
147146
break;
148147
}
149148
case LabelStatus.Skip: {
150-
core.info(`${dry_run ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
149+
core.info(`${inputs.dryRun ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
151150
break;
152151
}
153152
case LabelStatus.Error: {
154-
core.error(`${dry_run ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
153+
core.error(`${inputs.dryRun ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
155154
hasError = true;
156155
break;
157156
}
158157
default: {
159-
core.error(`${dry_run ? '[dryrun] ' : ''}🚫 '${actionLabel.name}' not processed`);
158+
core.error(`${inputs.dryRun ? '[dryrun] ' : ''}🚫 '${actionLabel.name}' not processed`);
160159
hasError = true;
161160
break;
162161
}

0 commit comments

Comments
 (0)