Skip to content

Commit

Permalink
Allow hash symbol in color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
armsnyder committed Feb 1, 2022
1 parent 3abd5ab commit bda39b6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The default file path is `.github/labels.yml`, but you can specify any file path

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

Color code can be defined in either format `d73a4a` or `'#d73a4a'` (note the quotes).

### Create Workflow

An example workflow is here.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/stretchr/testify v1.7.0
go.uber.org/multierr v1.7.0
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
Expand Down
15 changes: 13 additions & 2 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"io/ioutil"
"strings"

"github.com/google/go-github/github"
"golang.org/x/oauth2"
Expand All @@ -41,9 +42,19 @@ func FromManifestToLabels(path string) ([]Label, error) {
if err != nil {
return nil, err
}

var labels []Label
err = yaml.Unmarshal(buf, &labels)
return labels, err

if err := yaml.Unmarshal(buf, &labels); err != nil {
return labels, err
}

for i, label := range labels {
label.Color = strings.TrimPrefix(label.Color, "#")
labels[i] = label
}

return labels, nil
}

func NewClient(token string) *Client {
Expand Down
32 changes: 32 additions & 0 deletions pkg/github/github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package github_test

import (
"path/filepath"
"testing"

"github.com/micnncim/action-label-syncer/pkg/github"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestFromManifestToLabels(t *testing.T) {
labels, err := github.FromManifestToLabels(filepath.Join("testdata", "labels.yml"))
require.NoError(t, err)
assert.ElementsMatch(t, labels, []github.Label{
{
Name: "bug",
Description: "Something isn't working",
Color: "d73a4a",
},
{
Name: "documentation",
Description: "Improvements or additions to documentation",
Color: "0075ca",
},
{
Name: "duplicate",
Description: "This issue or pull request already exists",
Color: "cfd3d7",
},
})
}
9 changes: 9 additions & 0 deletions pkg/github/testdata/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: bug
description: Something isn't working
color: d73a4a
- name: documentation
description: Improvements or additions to documentation
color: '#0075ca'
- name: duplicate
description: This issue or pull request already exists
color: cfd3d7

0 comments on commit bda39b6

Please sign in to comment.