2019-04-10 13:45:47 +02:00
|
|
|
import * as vscode from "vscode";
|
2019-04-12 08:35:29 +02:00
|
|
|
import * as path from "path";
|
2019-04-12 10:20:23 +02:00
|
|
|
import * as fs from "fs";
|
2019-04-10 13:45:47 +02:00
|
|
|
|
|
|
|
export class Issue extends vscode.TreeItem {
|
|
|
|
|
|
|
|
constructor(public readonly label: string,
|
|
|
|
public issueId: number,
|
|
|
|
public body: string,
|
|
|
|
public issueState: string,
|
|
|
|
public assignee: string,
|
2019-04-12 14:22:59 +02:00
|
|
|
public creator: string,
|
2019-04-12 08:09:19 +02:00
|
|
|
public labels: any[],
|
|
|
|
public collapsibleState: vscode.TreeItemCollapsibleState,
|
2019-04-10 13:45:47 +02:00
|
|
|
public readonly command?: vscode.Command) {
|
|
|
|
super(label, collapsibleState);
|
2019-04-12 10:20:23 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-04-10 13:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get tooltip() {
|
|
|
|
return this.label + " - " + this.assignee;
|
|
|
|
}
|
2019-04-12 08:35:29 +02:00
|
|
|
|
|
|
|
labelDependentIcon(dark: boolean = false): string {
|
|
|
|
if (this.labels.length === 0) {
|
2019-04-12 10:20:23 +02:00
|
|
|
return path.join(__filename, '..', '..', 'media', 'issue.svg');
|
2019-04-12 08:35:29 +02:00
|
|
|
} else {
|
2019-04-12 10:20:23 +02:00
|
|
|
return path.join(vscode.workspace.rootPath as string, '.gitea', 'label_pictures', this.labels[0].name + ".svg");
|
2019-04-12 08:35:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iconPath = {
|
|
|
|
light: this.labelDependentIcon(),
|
|
|
|
dark: this.labelDependentIcon(true)
|
|
|
|
};
|
|
|
|
|
2019-04-10 13:45:47 +02:00
|
|
|
contextValue = 'issue';
|
2019-04-12 10:20:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createIconWithColor(color: string) {
|
|
|
|
return `<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
<path d="M16 31.5C24.5604 31.5 31.5 24.5604 31.5 16C31.5 7.43959 24.5604 0.5 16 0.5C7.43959 0.5 0.5 7.43959 0.5 16C0.5 24.5604 7.43959 31.5 16 31.5Z" stroke="{{color}}"/>
|
|
|
|
<path d="M19 6C19 4.34315 17.6569 3 16 3C14.3431 3 13 4.34315 13 6V20C13 21.6569 14.3431 23 16 23C17.6569 23 19 21.6569 19 20V6Z" fill="{{color}}"/>
|
|
|
|
<path d="M16.5 24H15.5C14.1193 24 13 25.1193 13 26.5C13 27.8807 14.1193 29 15.5 29H16.5C17.8807 29 19 27.8807 19 26.5C19 25.1193 17.8807 24 16.5 24Z" fill="{{color}}"/>
|
|
|
|
</svg>
|
|
|
|
`.replace(new RegExp("{{color}}", 'g'), "#" + color);
|
2019-04-10 13:45:47 +02:00
|
|
|
}
|