Skip to content

Commit bda39b6

Browse files
committed
Allow hash symbol in color codes
1 parent 3abd5ab commit bda39b6

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ The default file path is `.github/labels.yml`, but you can specify any file path
3333

3434
To create manifest of the current labels easily, using [label-exporter](https://github.com/micnncim/label-exporter) is recommended.
3535

36+
Color code can be defined in either format `d73a4a` or `'#d73a4a'` (note the quotes).
37+
3638
### Create Workflow
3739

3840
An example workflow is here.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.13
55
require (
66
github.com/google/go-github v17.0.0+incompatible
77
github.com/google/go-querystring v1.0.0 // indirect
8+
github.com/stretchr/testify v1.7.0
89
go.uber.org/multierr v1.7.0
910
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
1011
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e

pkg/github/github.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"io/ioutil"
21+
"strings"
2122

2223
"github.com/google/go-github/github"
2324
"golang.org/x/oauth2"
@@ -41,9 +42,19 @@ func FromManifestToLabels(path string) ([]Label, error) {
4142
if err != nil {
4243
return nil, err
4344
}
45+
4446
var labels []Label
45-
err = yaml.Unmarshal(buf, &labels)
46-
return labels, err
47+
48+
if err := yaml.Unmarshal(buf, &labels); err != nil {
49+
return labels, err
50+
}
51+
52+
for i, label := range labels {
53+
label.Color = strings.TrimPrefix(label.Color, "#")
54+
labels[i] = label
55+
}
56+
57+
return labels, nil
4758
}
4859

4960
func NewClient(token string) *Client {

pkg/github/github_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package github_test
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
7+
"github.com/micnncim/action-label-syncer/pkg/github"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestFromManifestToLabels(t *testing.T) {
13+
labels, err := github.FromManifestToLabels(filepath.Join("testdata", "labels.yml"))
14+
require.NoError(t, err)
15+
assert.ElementsMatch(t, labels, []github.Label{
16+
{
17+
Name: "bug",
18+
Description: "Something isn't working",
19+
Color: "d73a4a",
20+
},
21+
{
22+
Name: "documentation",
23+
Description: "Improvements or additions to documentation",
24+
Color: "0075ca",
25+
},
26+
{
27+
Name: "duplicate",
28+
Description: "This issue or pull request already exists",
29+
Color: "cfd3d7",
30+
},
31+
})
32+
}

pkg/github/testdata/labels.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: bug
2+
description: Something isn't working
3+
color: d73a4a
4+
- name: documentation
5+
description: Improvements or additions to documentation
6+
color: '#0075ca'
7+
- name: duplicate
8+
description: This issue or pull request already exists
9+
color: cfd3d7

0 commit comments

Comments
 (0)