Skip to content

Commit 9934ff2

Browse files
Copilotalexr00
andauthored
[WIP] Map issue template metadata to NewIssue.md (#8263)
* Initial plan * Initial plan for mapping issue template metadata to NewIssue.md Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add support for labels and assignees in issue templates Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Extract labels and assignees from YAML issue templates Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 4c47a03 commit 9934ff2

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/issues/issueFeatureRegistrar.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ export class IssueFeatureRegistrar extends Disposable {
786786
...options,
787787
title: template.title,
788788
body: template.body,
789+
labels: template.labels,
790+
assignees: template.assignees,
789791
};
790792
}
791793
this.makeNewIssueFile(uri, options);
@@ -1136,7 +1138,7 @@ export class IssueFeatureRegistrar extends Disposable {
11361138
await vscode.workspace.fs.delete(bodyPath);
11371139
const assigneeLine = `${ASSIGNEES} ${options?.assignees && options.assignees.length > 0 ? options.assignees.map(value => '@' + value).join(', ') + ' ' : ''
11381140
}`;
1139-
const labelLine = `${LABELS} `;
1141+
const labelLine = `${LABELS} ${options?.labels && options.labels.length > 0 ? options.labels.join(', ') + ' ' : ''}`;
11401142
const milestoneLine = `${MILESTONE} `;
11411143
const projectsLine = `${PROJECTS} `;
11421144
const cached = this._newIssueCache.get();
@@ -1283,14 +1285,14 @@ ${options?.body ?? ''}\n
12831285
return choice?.repo;
12841286
}
12851287

1286-
private async chooseTemplate(folderManager: FolderRepositoryManager): Promise<{ title: string | undefined, body: string | undefined } | undefined> {
1288+
private async chooseTemplate(folderManager: FolderRepositoryManager): Promise<IssueTemplate | undefined> {
12871289
const templateUris = await folderManager.getIssueTemplates();
12881290
if (templateUris.length === 0) {
1289-
return { title: undefined, body: undefined };
1291+
return { title: undefined, body: undefined, labels: undefined, assignees: undefined, name: undefined, about: undefined };
12901292
}
12911293

12921294
interface IssueChoice extends vscode.QuickPickItem {
1293-
template: { title: string | undefined, body: string | undefined } | undefined;
1295+
template: IssueTemplate | undefined;
12941296
}
12951297
const templates = await Promise.all(
12961298
templateUris
@@ -1316,7 +1318,7 @@ ${options?.body ?? ''}\n
13161318
});
13171319
choices.push({
13181320
label: vscode.l10n.t('Blank issue'),
1319-
template: { title: undefined, body: undefined }
1321+
template: { title: undefined, body: undefined, labels: undefined, assignees: undefined, name: undefined, about: undefined }
13201322
});
13211323

13221324
const selectedTemplate = await vscode.window.showQuickPick(choices, {
@@ -1343,15 +1345,23 @@ ${options?.body ?? ''}\n
13431345
const title = template.match(/title:\s*(.*)/)?.[1]?.replace(/^["']|["']$/g, '');
13441346
const name = template.match(/name:\s*(.*)/)?.[1]?.replace(/^["']|["']$/g, '');
13451347
const about = template.match(/about:\s*(.*)/)?.[1]?.replace(/^["']|["']$/g, '');
1348+
const labelsMatch = template.match(/labels:\s*(.*)/)?.[1];
1349+
const labels = labelsMatch ? labelsMatch.split(',').map(label => label.trim()).filter(label => label) : undefined;
1350+
const assigneesMatch = template.match(/assignees:\s*(.*)/)?.[1];
1351+
const assignees = assigneesMatch ? assigneesMatch.split(',').map(assignee => assignee.trim()).filter(assignee => assignee) : undefined;
13461352
const body = template.match(/---([\s\S]*)---([\s\S]*)/)?.[2];
1347-
return { title, name, about, body };
1353+
return { title, name, about, labels, assignees, body };
13481354
}
13491355

13501356
private parseYamlTemplate(parsed: YamlIssueTemplate): IssueTemplate {
13511357
const name = parsed.name;
13521358
const about = parsed.description || parsed.about;
13531359
const title = parsed.title;
13541360

1361+
// Extract labels and assignees from YAML
1362+
const labels = parsed.labels && Array.isArray(parsed.labels) ? parsed.labels : undefined;
1363+
const assignees = parsed.assignees && Array.isArray(parsed.assignees) ? parsed.assignees : undefined;
1364+
13551365
// Convert YAML body fields to markdown
13561366
let body = '';
13571367
if (parsed.body && Array.isArray(parsed.body)) {
@@ -1396,7 +1406,7 @@ ${options?.body ?? ''}\n
13961406
}
13971407
}
13981408

1399-
return { title, name, about, body: body.trim() || undefined };
1409+
return { title, name, about, labels, assignees, body: body.trim() || undefined };
14001410
}
14011411

14021412
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)