in src/issues/issueFeatureRegistrar.ts [512:585]
async createIssueFromFile() {
let text: string;
if (
!vscode.window.activeTextEditor ||
vscode.window.activeTextEditor.document.uri.scheme !== NEW_ISSUE_SCHEME
) {
return;
}
text = vscode.window.activeTextEditor.document.getText();
const indexOfEmptyLineWindows = text.indexOf('\r\n\r\n');
const indexOfEmptyLineOther = text.indexOf('\n\n');
let indexOfEmptyLine: number;
if (indexOfEmptyLineWindows < 0 && indexOfEmptyLineOther < 0) {
return;
} else {
if (indexOfEmptyLineWindows < 0) {
indexOfEmptyLine = indexOfEmptyLineOther;
} else if (indexOfEmptyLineOther < 0) {
indexOfEmptyLine = indexOfEmptyLineWindows;
} else {
indexOfEmptyLine = Math.min(indexOfEmptyLineWindows, indexOfEmptyLineOther);
}
}
const title = text.substring(0, indexOfEmptyLine);
let assignees: string[] | undefined;
text = text.substring(indexOfEmptyLine + 2).trim();
if (text.startsWith(ASSIGNEES)) {
const lines = text.split(/\r\n|\n/, 1);
if (lines.length === 1) {
assignees = lines[0]
.substring(ASSIGNEES.length)
.split(',')
.map(value => {
value = value.trim();
if (value.startsWith('@')) {
value = value.substring(1);
}
return value;
});
text = text.substring(lines[0].length).trim();
}
}
let labels: string[] | undefined;
if (text.startsWith(LABELS)) {
const lines = text.split(/\r\n|\n/, 1);
if (lines.length === 1) {
labels = lines[0]
.substring(LABELS.length)
.split(',')
.map(value => value.trim())
.filter(label => label);
text = text.substring(lines[0].length).trim();
}
}
const body = text;
if (!title || !body) {
return;
}
const createSucceeded = await this.doCreateIssue(
this.createIssueInfo?.document,
this.createIssueInfo?.newIssue,
title,
body,
assignees,
labels,
this.createIssueInfo?.lineNumber,
this.createIssueInfo?.insertIndex,
extractIssueOriginFromQuery(vscode.window.activeTextEditor.document.uri),
);
this.createIssueInfo = undefined;
if (createSucceeded) {
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
}
}