import * as vscode from "vscode"; import * as path from "path"; import * as fs from "fs"; export class Issue extends vscode.TreeItem { constructor(public readonly label: string, public issueId: number, public body: string, public issueState: string, public assignee: string, public creator: string, public labels: any[], public collapsibleState: vscode.TreeItemCollapsibleState, public readonly command?: vscode.Command) { super(label, collapsibleState); try { for (const issueLabel of labels) { const folderPath = path.join(vscode.workspace.rootPath as string, '.gitea', 'label_pictures'); if (!fs.existsSync(path.join(folderPath, issueLabel.name + ".svg"))) { if (!fs.existsSync(folderPath)) { fs.mkdirSync(folderPath); } fs.writeFileSync(path.join(folderPath, issueLabel.name + ".svg"), createIconWithColor(issueLabel.color)); } } } catch (e) { console.log(e); } } get tooltip() { return this.label + " - " + this.assignee; } labelDependentIcon(dark: boolean = false): string { if (this.labels.length === 0) { return path.join(__filename, '..', '..', 'media', 'issue.svg'); } else { return path.join(vscode.workspace.rootPath as string, '.gitea', 'label_pictures', this.labels[0].name + ".svg"); } } iconPath = { light: this.labelDependentIcon(), dark: this.labelDependentIcon(true) }; contextValue = 'issue'; } export function createIconWithColor(color: string) { return ` `.replace(new RegExp("{{color}}", 'g'), "#" + color); }