Skip to content

Commit 6d1e91b

Browse files
authored
Merge pull request #207 from pjpires/feature/allow-hex-color-codes
Sanitize the color field to allow using hex codes
2 parents 91cccb3 + 16902c7 commit 6d1e91b

6 files changed

Lines changed: 70 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ looks like:
5151
* `description` can be omit if your want to keep the current one
5252
* `from_name` allow to rename a label from one currently available on your repository
5353

54+
**Note:** You can use hex codes for the `color` field, as that helps previewing the colors in some code editors. The leading "#" will be automatically removed.
55+
5456
### Workflow
5557

5658
```yaml
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- # bot
2+
name: ":robot: bot"
3+
color: "#69cde9"
4+
description: ""
5+
- # bug
6+
name: ":bug: bug"
7+
color: "#b60205"
8+
description: ""
9+
- # dependencies
10+
name: ":game_die: dependencies"
11+
color: "#0366d6"
12+
description: ""
13+
- # documentation
14+
name: ":memo: documentation"
15+
color: "#c5def5"
16+
description: ""
17+
- # duplicate
18+
name: ":busts_in_silhouette: duplicate"
19+
color: "#cccccc"
20+
description: ""
21+
- # enhancement
22+
name: ":sparkles: enhancement"
23+
color: "#0054ca"
24+
description: ""
25+
- # feature request
26+
name: ":bulb: feature request"
27+
color: "#0e8a16"
28+
description: ""
29+
- # feedback
30+
name: ":mega: feedback"
31+
color: "#03a9f4"
32+
description: ""
33+
- # future maybe
34+
name: ":rocket: future maybe"
35+
color: "#fef2c0"
36+
description: ""
37+
- # good first issue
38+
name: ":hatching_chick: good first issue"
39+
color: "#7057ff"
40+
description: ""

__tests__/labeler.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ const cases = [
6565
delete: 4,
6666
error: 0
6767
}
68+
],
69+
[
70+
'labels.hexcodes.yml',
71+
{
72+
githubToken: 'n/a',
73+
yamlFile: './__tests__/fixtures/labels.hexcodes.yml',
74+
skipDelete: true,
75+
dryRun: true,
76+
exclude: []
77+
},
78+
{
79+
skip: 10,
80+
exclude: 0,
81+
create: 0,
82+
update: 0,
83+
rename: 0,
84+
delete: 11,
85+
error: 0
86+
}
6887
]
6988
];
7089

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/labeler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ export class Labeler {
213213
}
214214

215215
for (const fileLabel of await this.fileLabels) {
216+
// Allow color hex codes (e.g., '#cccccc') to be set even though GitHub's API requires the # sign not to be present.
217+
fileLabel.color = this.sanitizeColorString(fileLabel.color);
218+
216219
const repoLabel = await this.getRepoLabel(fileLabel.name);
217220

218221
// Rename
@@ -334,6 +337,10 @@ export class Labeler {
334337
core.info(`👉 Current labels\n${yaml.dump(labels).toString()}`);
335338
}
336339

340+
private sanitizeColorString(color: string) {
341+
return color.replace(/^#/, '');
342+
}
343+
337344
private logInfo(message: string) {
338345
core.info(`${this.dryRun ? '[dryrun] ' : ''}${message}`);
339346
}

0 commit comments

Comments
 (0)