Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude option with wildcard matching on label names #1

Merged
merged 1 commit into from Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -29,3 +29,37 @@ jobs:
dry_run: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Labeler (exclude part 1)
uses: ./
with:
yaml_file: .res/labels.exclude1.yml
exclude: "['d*', 'enhancement', '*fix']"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Labeler (restore)
uses: ./
with:
yaml_file: .res/labels.restore.yml
skip_delete: false
dry_run: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Labeler (exclude part 2)
uses: ./
with:
yaml_file: .res/labels.exclude2.yml
exclude: '*fix'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Labeler (restore)
uses: ./
with:
yaml_file: .res/labels.restore.yml
skip_delete: false
dry_run: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40 changes: 40 additions & 0 deletions .res/labels.exclude1.yml
@@ -0,0 +1,40 @@
---
- name: bug
color: d73a4a
description: "Something isn't working"

# would be deleted if not excluded by action configuration
# - name: documentation
# color: 0075ca
# description: "Improvements or additions to documentation"

# - name: duplicate
# color: cfd3d7
# description: "This issue or pull request already exists"

# would be updated if not excluded by action configuration
- name: enhancement
color: a2eeef
description: "New features or requests"

- name: good first issue
color: 7057ff
description: "Good for newcomers"

- name: help wanted
color: "008672"
description: "Extra attention is needed"

- name: invalid
color: e4e669
description: "This doesn't seem right"

- name: question
color: d876e3
description: "Further information is requested"

# would be renamed if not excluded by action configuration
- name: wontfix_it
color: "000000"
description: "This will not be worked on"
from_name: wontfix
38 changes: 38 additions & 0 deletions .res/labels.exclude2.yml
@@ -0,0 +1,38 @@
---
- name: bug
color: d73a4a
description: "Something isn't working"

- name: documentation
color: 0075ca
description: "Improvements or additions to documentation"

- name: duplicate
color: cfd3d7
description: "This issue or pull request already exists"

- name: enhancement
color: a2eeef
description: "New features or requests"

- name: good first issue
color: 7057ff
description: "Good for newcomers"

- name: help wanted
color: "008672"
description: "Extra attention is needed"

- name: invalid
color: e4e669
description: "This doesn't seem right"

- name: question
color: d876e3
description: "Further information is requested"

# would be renamed if not excluded by action configuration
- name: wontfix_it
color: "000000"
description: "This will not be worked on"
from_name: wontfix
29 changes: 20 additions & 9 deletions README.md
@@ -1,7 +1,7 @@
[![GitHub release](https://img.shields.io/github/release/crazy-max/ghaction-github-labeler.svg?style=flat-square)](https://github.com/crazy-max/ghaction-github-labeler/releases/latest)
[![GitHub marketplace](https://img.shields.io/badge/marketplace-github--labeler-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/github-labeler)
[![Test workflow](https://github.com/crazy-max/ghaction-github-labeler/workflows/test/badge.svg)](https://github.com/crazy-max/ghaction-github-labeler/actions/?workflow=test)
[![Support me on Patreon](https://img.shields.io/badge/donate-patreon-f96854.svg?logo=patreon&style=flat-square)](https://www.patreon.com/crazymax)
[![Support me on Patreon](https://img.shields.io/badge/donate-patreon-f96854.svg?logo=patreon&style=flat-square)](https://www.patreon.com/crazymax)
[![Paypal Donate](https://img.shields.io/badge/donate-paypal-00457c.svg?logo=paypal&style=flat-square)](https://www.paypal.me/crazyws)

## ✨ About
Expand Down Expand Up @@ -60,6 +60,7 @@ jobs:
uses: crazy-max/ghaction-github-labeler@v1
with:
yaml_file: .github/labels.yml
exclude: "['help*', '*issue']"
skip_delete: false
dry_run: false
env:
Expand All @@ -72,8 +73,8 @@ With this workflow, the YAML configuration above on a [fresh repository](.res/sa
* Skip `documentation` (because same `color` and `description`)
* Update `duplicate` (`color` is different)
* Update `enhancement` (`color` is different, keep current `description`)
* Delete `good first issue`
* Delete `help wanted`
* Leave `good first issue` alone (because it matches an `exclude` pattern)
* Leave `help wanted` alone (because it matches an `exclude` pattern)
* Delete `invalid`
* Delete `question`
* Rename `wontfix` to `wontfix_it` and set `color` and `description`
Expand All @@ -84,11 +85,19 @@ 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 |
|-----------------|---------|------------------------------------------------------------------------------------|
| `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`) |
| Name | Type | Description |
|-----------------|----------|------------------------------------------------------------------------------------|
| `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¹ | If present, prevents changes to labels that match the given [pattern(s)][matcher]. |

¹ The `exclude` option accepts only a single string, but that string can contain a YAML array of strings:

```yaml
exclude: 'help*'
exclude: "['help*', '*bug*', '*issue']"
```

### environment variables

Expand All @@ -104,9 +113,11 @@ All kinds of contributions are welcome :raised_hands:!<br />
The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon:<br />
But we're not gonna lie to each other, I'd rather you buy me a beer or two :beers:!

[![Support me on Patreon](.res/patreon.png)](https://www.patreon.com/crazymax)
[![Support me on Patreon](.res/patreon.png)](https://www.patreon.com/crazymax)
[![Paypal Donate](.res/paypal.png)](https://www.paypal.me/crazyws)

## 📝 License

MIT. See `LICENSE` for more details.

[matcher]: https://github.com/sindresorhus/matcher
41 changes: 40 additions & 1 deletion lib/main.js
Expand Up @@ -15,23 +15,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const yaml = __importStar(require("js-yaml"));
const matcher_1 = __importDefault(require("matcher"));
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
const octokit = new github.GitHub(process.env['GITHUB_TOKEN'] || '');
let liveLabels;
let fileLabels;
let exclusions;
var LabelStatus;
(function (LabelStatus) {
LabelStatus[LabelStatus["Create"] = 0] = "Create";
LabelStatus[LabelStatus["Update"] = 1] = "Update";
LabelStatus[LabelStatus["Rename"] = 2] = "Rename";
LabelStatus[LabelStatus["Delete"] = 3] = "Delete";
LabelStatus[LabelStatus["Skip"] = 4] = "Skip";
LabelStatus[LabelStatus["Error"] = 5] = "Error";
LabelStatus[LabelStatus["Exclude"] = 5] = "Exclude";
LabelStatus[LabelStatus["Error"] = 6] = "Error";
})(LabelStatus || (LabelStatus = {}));
function run() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -50,6 +56,10 @@ function run() {
let actionLabels = yield getActionLabels();
for (const actionLabel of actionLabels) {
switch (actionLabel.ghaction_status) {
case LabelStatus.Exclude: {
core.info(`${dry_run ? '[dryrun] ' : ''}${actionLabel.ghaction_log}`);
break;
}
case LabelStatus.Create: {
if (dry_run) {
core.info(`[dryrun] ${actionLabel.ghaction_log}`);
Expand Down Expand Up @@ -165,9 +175,26 @@ function displayLiveLabels() {
core.info(`👉 Current labels\n${yaml.safeDump(labels).toString()}`);
});
}
function getExclusions() {
return __awaiter(this, void 0, void 0, function* () {
const raw = core.getInput('exclude') || '[]';
let patterns;
if (raw.trimLeft().startsWith('[')) {
patterns = yield yaml.load(raw);
}
else {
patterns = [raw];
}
if (patterns === undefined || patterns.length === 0) {
return new Set();
}
return new Set(matcher_1.default(liveLabels.map(label => label.name), patterns));
});
}
function getActionLabels() {
return __awaiter(this, void 0, void 0, function* () {
let labels = Array();
exclusions = yield getExclusions();
for (const fileLabel of fileLabels) {
const liveLabel = yield getLiveLabel(fileLabel.name);
// Rename
Expand All @@ -178,6 +205,10 @@ function getActionLabels() {
}
const liveFromLabel = yield getLiveLabel(fileLabel.from_name);
if (liveFromLabel !== undefined) {
if (exclusions.has(liveFromLabel.name)) {
labels.push(Object.assign(Object.assign({}, liveFromLabel), { ghaction_status: LabelStatus.Exclude, ghaction_log: `🚫️ Excluding '${liveFromLabel.name}' from rename.` }));
continue;
}
labels.push(Object.assign(Object.assign({}, fileLabel), { ghaction_status: LabelStatus.Rename, ghaction_log: `✨ Renaming '${liveFromLabel.name}' label to '${fileLabel.name}' and set color '${fileLabel.color}'${fileLabel.description !== undefined ? ` and desc '${fileLabel.description}'` : ''}` }));
continue;
}
Expand All @@ -186,6 +217,10 @@ function getActionLabels() {
}
// Update
if (liveLabel !== undefined) {
if (exclusions.has(liveLabel.name)) {
labels.push(Object.assign(Object.assign({}, fileLabel), { ghaction_status: LabelStatus.Exclude, ghaction_log: `🚫️ Excluding '${fileLabel.name}' from update.` }));
continue;
}
if (fileLabel.color == liveLabel.color && fileLabel.description == liveLabel.description) {
labels.push(Object.assign(Object.assign({}, fileLabel), { ghaction_status: LabelStatus.Skip, ghaction_log: `⚠️ Skipping update for '${fileLabel.name}' label. Same color and description` }));
continue;
Expand All @@ -201,6 +236,10 @@ function getActionLabels() {
if ((yield getFileLabel(liveLabel.name)) !== undefined) {
continue;
}
if (exclusions.has(liveLabel.name)) {
labels.push(Object.assign(Object.assign({}, liveLabel), { ghaction_status: LabelStatus.Exclude, ghaction_log: `🚫️ Excluding '${liveLabel.name}' from deletion.` }));
continue;
}
labels.push(Object.assign(Object.assign({}, liveLabel), { ghaction_status: LabelStatus.Delete, ghaction_log: `🔫 Deleting '${liveLabel.name}'` }));
}
return labels;
Expand Down
15 changes: 15 additions & 0 deletions node_modules/.bin/editorconfig

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

7 changes: 7 additions & 0 deletions node_modules/.bin/editorconfig.cmd

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

15 changes: 15 additions & 0 deletions node_modules/.bin/prettier

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

7 changes: 7 additions & 0 deletions node_modules/.bin/prettier.cmd

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

15 changes: 15 additions & 0 deletions node_modules/.bin/tsc

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

7 changes: 7 additions & 0 deletions node_modules/.bin/tsc.cmd

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

15 changes: 15 additions & 0 deletions node_modules/.bin/tsfmt

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

7 changes: 7 additions & 0 deletions node_modules/.bin/tsfmt.cmd

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