diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1a0684e..2a9b60d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,7 +33,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
## [0.0.5] - 2019-04-12
### Added:
- Child items to root items. Collapsable item now shows assignee, state, id and list all labels from the issue
-- Label dependent icons
+- Label dependent icons (Automatically fetch colors)
### Refactored:
- Created two methods that are used in both classes (the closed and the open issues provider)
diff --git a/README.md b/README.md
index 1c29811..da8955b 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ When you've finished you can press the refresh button in the open issues section
![Issues with multiple colors](./media/gitea-issues.png)
-In order to get nice looking issueicons in multiple colors you need to assigne any issue a label called either "feature" or "bug". A bug is going to be represented as an red issue, while a feature will have a green icon. If the issue does not have got a label it will receive a grey icon. If the label is not know (so neither "feature" nor "bug" not case sensitive) it will also get a grey icon.
+In order to get nice looking issue icons in multiple colors (of your choice) you just need to assign a label to your issue. The color is being fetched automatically. If you change the color of the label however, you need to delete the `.gitea/{issuename}.svg` file in the given folder. If you skip this step, the file is not going to get updated. In most cases you need to restart visual studio code to apply the icons in the issues tab.
## Future
- Implement a `Close Issue` Button
- Create Issues via Webview
diff --git a/resources/dark/bug.svg b/resources/bug.svg
similarity index 100%
rename from resources/dark/bug.svg
rename to resources/bug.svg
diff --git a/resources/dark/feature.svg b/resources/feature.svg
similarity index 100%
rename from resources/dark/feature.svg
rename to resources/feature.svg
diff --git a/resources/light/bug.svg b/resources/light/bug.svg
deleted file mode 100644
index a573efb..0000000
--- a/resources/light/bug.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-
diff --git a/resources/light/feature.svg b/resources/light/feature.svg
deleted file mode 100644
index c60518b..0000000
--- a/resources/light/feature.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-
diff --git a/src/issue.ts b/src/issue.ts
index 884f321..208e893 100644
--- a/src/issue.ts
+++ b/src/issue.ts
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import * as path from "path";
+import * as fs from "fs";
export class Issue extends vscode.TreeItem {
@@ -12,6 +13,19 @@ export class Issue extends vscode.TreeItem {
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() {
@@ -22,10 +36,11 @@ export class Issue extends vscode.TreeItem {
let filename = "";
if (this.labels.length === 0) {
filename = "issue";
+ return path.join(__filename, '..', '..', 'media', 'issue.svg');
} else {
- this.labels[0].name.toLowerCase() === "feature" ? filename = "feature" : filename = this.labels[0].name.toLowerCase() === "bug" ? "bug" : "issue";
+ filename = this.labels[0].name;
+ return path.join(vscode.workspace.rootPath as string, '.gitea', 'label_pictures', this.labels[0].name + ".svg");
}
- return path.join(__filename, '..', '..', 'resources', dark ? 'dark' : 'light', filename + '.svg');
}
iconPath = {
@@ -34,4 +49,13 @@ export class Issue extends vscode.TreeItem {
};
contextValue = 'issue';
+}
+
+export function createIconWithColor(color: string) {
+ return `
+`.replace(new RegExp("{{color}}", 'g'), "#" + color);
}
\ No newline at end of file