Skip to content

Commit eb988e2

Browse files
Copilotalexr00
andcommitted
Add support for labels and assignees in issue templates
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 97b4ff7 commit eb988e2

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/issues/issueFeatureRegistrar.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ export class IssueFeatureRegistrar extends Disposable {
739739
...options,
740740
title: template.title,
741741
body: template.body,
742+
labels: template.labels,
743+
assignees: template.assignees,
742744
};
743745
}
744746
this.makeNewIssueFile(uri, options);
@@ -1059,7 +1061,7 @@ export class IssueFeatureRegistrar extends Disposable {
10591061
await vscode.workspace.fs.delete(bodyPath);
10601062
const assigneeLine = `${ASSIGNEES} ${options?.assignees && options.assignees.length > 0 ? options.assignees.map(value => '@' + value).join(', ') + ' ' : ''
10611063
}`;
1062-
const labelLine = `${LABELS} `;
1064+
const labelLine = `${LABELS} ${options?.labels && options.labels.length > 0 ? options.labels.join(', ') + ' ' : ''}`;
10631065
const milestoneLine = `${MILESTONE} `;
10641066
const projectsLine = `${PROJECTS} `;
10651067
const cached = this._newIssueCache.get();
@@ -1206,14 +1208,14 @@ ${options?.body ?? ''}\n
12061208
return choice?.repo;
12071209
}
12081210

1209-
private async chooseTemplate(folderManager: FolderRepositoryManager): Promise<{ title: string | undefined, body: string | undefined } | undefined> {
1211+
private async chooseTemplate(folderManager: FolderRepositoryManager): Promise<IssueTemplate | undefined> {
12101212
const templateUris = await folderManager.getIssueTemplates();
12111213
if (templateUris.length === 0) {
1212-
return { title: undefined, body: undefined };
1214+
return { title: undefined, body: undefined, labels: undefined, assignees: undefined, name: undefined, about: undefined };
12131215
}
12141216

12151217
interface IssueChoice extends vscode.QuickPickItem {
1216-
template: { title: string | undefined, body: string | undefined } | undefined;
1218+
template: IssueTemplate | undefined;
12171219
}
12181220
const templates = await Promise.all(
12191221
templateUris
@@ -1239,7 +1241,7 @@ ${options?.body ?? ''}\n
12391241
});
12401242
choices.push({
12411243
label: vscode.l10n.t('Blank issue'),
1242-
template: { title: undefined, body: undefined }
1244+
template: { title: undefined, body: undefined, labels: undefined, assignees: undefined, name: undefined, about: undefined }
12431245
});
12441246

12451247
const selectedTemplate = await vscode.window.showQuickPick(choices, {
@@ -1253,8 +1255,12 @@ ${options?.body ?? ''}\n
12531255
const title = template.match(/title:\s*(.*)/)?.[1]?.replace(/^["']|["']$/g, '');
12541256
const name = template.match(/name:\s*(.*)/)?.[1]?.replace(/^["']|["']$/g, '');
12551257
const about = template.match(/about:\s*(.*)/)?.[1]?.replace(/^["']|["']$/g, '');
1258+
const labelsMatch = template.match(/labels:\s*(.*)/)?.[1];
1259+
const labels = labelsMatch ? labelsMatch.split(',').map(label => label.trim()).filter(label => label) : undefined;
1260+
const assigneesMatch = template.match(/assignees:\s*(.*)/)?.[1];
1261+
const assignees = assigneesMatch ? assigneesMatch.split(',').map(assignee => assignee.trim()).filter(assignee => assignee) : undefined;
12561262
const body = template.match(/---([\s\S]*)---([\s\S]*)/)?.[2];
1257-
return { title, name, about, body };
1263+
return { title, name, about, labels, assignees, body };
12581264
}
12591265

12601266
private async doCreateIssue(

src/issues/issueFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface NewIssueFileOptions {
1414
title?: string;
1515
body?: string;
1616
assignees?: string[] | undefined,
17+
labels?: string[] | undefined,
1718
remote?: Remote,
1819
}
1920

src/issues/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export interface IssueTemplate {
9191
name: string | undefined,
9292
about: string | undefined,
9393
title: string | undefined,
94+
labels: string[] | undefined,
95+
assignees: string[] | undefined,
9496
body: string | undefined
9597
}
9698

0 commit comments

Comments
 (0)