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

flag unlabeled PRs with wildcard label #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,54 @@ The supported options are:

- `labels`: GitHub PR labels mapped to changelog section headers

- `wildcardLabel`: A label to identify commits that don't have a GitHub PR label
which matches a value in `labels`. (e.g. `unlabeled`) By default, this has no value. [Read more about this option](#wildcardlabel).

- `ignoreCommitters`: List of committers to ignore (exact or partial match).
Useful for example to ignore commits from bots.

- `cacheDir`: Path to a GitHub API response cache to avoid throttling
(e.g. `.changelog`)

### wildcardLabel

For some projects, it may be beneficial to list PRs in the changelog that don't
have a matching label defined in the configuration `labels`. Listing these PRs also allows you to review the changelog and identify any PRs that should be re-labeled on GitHub. For example, forgetting to label a breaking change.

```json5
{
// ...
"changelog": {
"wildcardLabel": "unlabeled"
}
}
```

A default changlog heading of `:present: Additional updates` is set when a value for `wildcardLabel` is in the configuration.

```md
## Unreleased (2018-05-24)

#### 🎁 Additional updates
* [#514](https://github.com/my-org/my-repo/pull/514) Setting to mute video ([@diligent-developer](https://github.com/diligent-developer))
```

You can overwrite the default heading by including the `wildcardLabel` value in the configuration's `labels` object. For example:

```json5
{
// ...
"changelog": {
"labels": {
"feature": "New Feature",
"bug": "Bug Fix",
"unlabeled": "Unlabeled PRs"
},
"wildcardLabel": "unlabeled"
}
}
```


License
------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ export default class Changelog {

const labels = commit.githubIssue.labels.map(label => label.name.toLowerCase());

if (this.config.wildcardLabel) {
// check whether the commit has any of the labels from the learna.json config.
// If not, label this commit with the provided label

let foundLabel = Object.keys(this.config.labels).some(label => labels.indexOf(label.toLowerCase()) !== -1);

if (!foundLabel) {
labels.push(this.config.wildcardLabel);
}
}

commit.categories = Object.keys(this.config.labels)
.filter(label => labels.indexOf(label.toLowerCase()) !== -1)
.map(label => this.config.labels[label]);
Expand Down
8 changes: 7 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Configuration {
cacheDir?: string;
nextVersion: string | undefined;
nextVersionFromMetadata?: boolean;
wildcardLabel?: string;
}

export interface ConfigLoaderOptions {
Expand All @@ -31,7 +32,7 @@ export function fromPath(rootPath: string, options: ConfigLoaderOptions = {}): C
let config = fromPackageConfig(rootPath) || fromLernaConfig(rootPath) || {};

// Step 2: fill partial config with defaults
let { repo, nextVersion, labels, cacheDir, ignoreCommitters } = config;
let { repo, nextVersion, labels, cacheDir, ignoreCommitters, wildcardLabel } = config;

if (!repo) {
repo = findRepo(rootPath);
Expand All @@ -58,6 +59,10 @@ export function fromPath(rootPath: string, options: ConfigLoaderOptions = {}): C
};
}

if (wildcardLabel && !labels[wildcardLabel]) {
labels[wildcardLabel] = "️:present: Additional updates";
}

if (!ignoreCommitters) {
ignoreCommitters = [
"dependabot-bot",
Expand All @@ -76,6 +81,7 @@ export function fromPath(rootPath: string, options: ConfigLoaderOptions = {}): C
labels,
ignoreCommitters,
cacheDir,
wildcardLabel,
};
}

Expand Down