Automatically add new labels to newly created issues (#292)

* Automatically add new labels to newly created issues

* changelog
This commit is contained in:
Will Hunt 2022-04-11 17:25:26 +01:00 committed by GitHub
parent e8d2003868
commit 1ab442107c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

1
changelog.d/292.feature Normal file
View File

@ -0,0 +1 @@
Add new GitHubRepo config option `newIssue.labels` which allows admins to automatically set labels on new issues.

View File

@ -34,6 +34,8 @@ This connection supports a few options which can be defined in the room state:
|includingLabels|Only notify on issues matching these label names|Array of: String matching a label name|*empty*|
|excludingLabels|Never notify on issues matching these label names|Array of: String matching a label name|*empty*|
|hotlinkIssues|Send a link to an issue/PR in the room when a user mentions a prefix followed by a number|` { prefix: string }`|`{prefix: "#"}`|
|newIssue|Configuration options for new issues|`{ labels: string[] }`|*empty*|
|newIssue.labels|Automatically set these labels on issues created via commands|Array of: String matching a label name|*empty*|
### Supported event types

View File

@ -44,7 +44,10 @@ export interface GitHubRepoConnectionOptions {
excludingLabels?: string[];
hotlinkIssues?: boolean|{
prefix: string;
}
};
newIssue?: {
labels: string[];
};
}
export interface GitHubRepoConnectionState extends GitHubRepoConnectionOptions{
org: string;
@ -438,13 +441,16 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
if (!octokit) {
throw new NotLoggedInError();
}
const labelsNames = labels?.split(",");
const labelsNames = new Set(labels?.split(","));
if (this.state.newIssue?.labels) {
this.state.newIssue?.labels.forEach(l => labelsNames.add(l));
}
const res = await octokit.issues.create({
repo: this.state.repo,
owner: this.state.org,
title: title,
body: description,
labels: labelsNames,
labels: [...labelsNames],
});
return {