diff --git a/action.yml b/action.yml index 79e3226..cebe5f6 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ name: 'github-labeler' description: 'Declarative way to configure GitHub labels' inputs: - manifest: + config: description: 'Path to YAML file which defines GitHub labels' required: false default: '.github/labels.yml' diff --git a/cli.go b/cli.go index 073a20c..17551ee 100644 --- a/cli.go +++ b/cli.go @@ -20,18 +20,18 @@ type CLI struct { Stderr io.Writer Option Option - GitHub *app - Config Manifest + GitHub *App + Config Config } type Option struct { DryRun bool `long:"dry-run" description:"Just dry run"` - Config string `short:"c" long:"config" description:"Path to YAML file that labels are defined" default:"labels.yaml"` + Config string `long:"config" description:"Path to YAML file that labels are defined" default:"labels.yaml"` Import bool `long:"import" description:"Import existing labels if enabled"` Version bool `long:"version" description:"Show version"` } -type app struct { +type App struct { Labeler Labeler logger *log.Logger } @@ -48,12 +48,12 @@ func (c *CLI) Run(args []string) error { tc := oauth2.NewClient(oauth2.NoContext, ts) client := github.NewClient(tc) - m, err := loadManifest(c.Option.Config) + cfg, err := loadConfig(c.Option.Config) if err != nil { return err } - gc := &app{ + gc := &App{ Labeler: githubClientImpl{client}, logger: log.New(os.Stdout, "labeler: ", log.Ldate|log.Ltime), } @@ -64,20 +64,20 @@ func (c *CLI) Run(args []string) error { } c.GitHub = gc - c.Config = m + c.Config = cfg if len(c.Config.Repos) == 0 { return fmt.Errorf("no repos found in %s", c.Option.Config) } if c.Option.Import { - m := c.CurrentLabels() + cfg := c.CurrentLabels() f, err := os.Create(c.Option.Config) if err != nil { return err } defer f.Close() - return yaml.NewEncoder(f).Encode(&m) + return yaml.NewEncoder(f).Encode(&cfg) } if cmp.Equal(c.CurrentLabels(), c.Config) { @@ -150,8 +150,8 @@ func (c *CLI) Sync(repo Repo) error { return c.deleteLabels(slugs[0], slugs[1]) } -func (c *CLI) CurrentLabels() Manifest { - var m Manifest +func (c *CLI) CurrentLabels() Config { + var cfg Config for _, repo := range c.Config.Repos { slugs := strings.Split(repo.Name, "/") if len(slugs) != 2 { @@ -168,8 +168,8 @@ func (c *CLI) CurrentLabels() Manifest { ls = append(ls, label.Name) } repo.Labels = ls - m.Repos = append(m.Repos, repo) - m.Labels = append(m.Labels, labels...) + cfg.Repos = append(cfg.Repos, repo) + cfg.Labels = append(cfg.Labels, labels...) } - return m + return cfg } diff --git a/config.go b/config.go index 0d70ab9..9a470de 100644 --- a/config.go +++ b/config.go @@ -7,34 +7,34 @@ import ( yaml "gopkg.in/yaml.v2" ) -// Manifest represents the YAML file described about labels and repos -type Manifest struct { +// Config represents the YAML file described about labels and repos +type Config struct { Labels Labels `yaml:"labels"` Repos Repos `yaml:"repos"` } -func loadManifest(path string) (Manifest, error) { - var m Manifest +func loadConfig(path string) (Config, error) { + var cfg Config buf, err := ioutil.ReadFile(path) if err != nil { - return m, err + return cfg, err } - err = yaml.Unmarshal(buf, &m) - return m, err + err = yaml.Unmarshal(buf, &cfg) + return cfg, err } -func (m Manifest) getDefinedLabel(name string) (Label, error) { - for _, label := range m.Labels { +func (cfg Config) getDefinedLabel(name string) (Label, error) { + for _, label := range cfg.Labels { if label.Name == name { return label, nil } } - return Label{}, fmt.Errorf("%s: no such defined label in manifest YAML", name) + return Label{}, fmt.Errorf("%s: no such defined label in config YAML", name) } -func (m Manifest) checkIfRepoHasLabel(repoName, labelName string) bool { +func (cfg Config) checkIfRepoHasLabel(repoName, labelName string) bool { var labels []string - for _, repo := range m.Repos { + for _, repo := range cfg.Repos { if repo.Name == repoName { labels = repo.Labels break diff --git a/entrypoint.sh b/entrypoint.sh index 4369cb2..a97f810 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,11 @@ #!/bin/bash -manifest=${INPUT_MANIFEST} +config=${INPUT_CONFIG} import=${INPUT_IMPORT:-false} if ${import}; then - github-labeler --import --config=${manifest} + github-labeler --import --config=${config} exit ${?} fi -github-labeler --config=${manifest} +github-labeler --config=${config} diff --git a/label.go b/label.go index d6efcef..1ebec7a 100644 --- a/label.go +++ b/label.go @@ -26,7 +26,7 @@ type Repo struct { // Repos represents a collection of Repo type Repos []Repo -func (a *app) GetLabel(owner, repo string, label Label) (Label, error) { +func (a *App) GetLabel(owner, repo string, label Label) (Label, error) { ctx := context.Background() ghLabel, _, err := a.Labeler.GetLabel(ctx, owner, repo, label.Name) if err != nil { @@ -39,7 +39,7 @@ func (a *app) GetLabel(owner, repo string, label Label) (Label, error) { }, nil } -func (a *app) CreateLabel(owner, repo string, label Label) error { +func (a *App) CreateLabel(owner, repo string, label Label) error { ctx := context.Background() ghLabel := &github.Label{ Name: github.String(label.Name), @@ -56,7 +56,7 @@ func (a *app) CreateLabel(owner, repo string, label Label) error { return err } -func (a *app) EditLabel(owner, repo string, label Label) error { +func (a *App) EditLabel(owner, repo string, label Label) error { ctx := context.Background() ghLabel := &github.Label{ Name: github.String(label.Name), @@ -68,7 +68,7 @@ func (a *app) EditLabel(owner, repo string, label Label) error { return err } -func (a *app) ListLabels(owner, repo string) ([]Label, error) { +func (a *App) ListLabels(owner, repo string) ([]Label, error) { ctx := context.Background() opt := &github.ListOptions{PerPage: 10} var labels []Label @@ -92,7 +92,7 @@ func (a *app) ListLabels(owner, repo string) ([]Label, error) { return labels, nil } -func (a *app) DeleteLabel(owner, repo string, label Label) error { +func (a *App) DeleteLabel(owner, repo string, label Label) error { ctx := context.Background() a.logger.Printf("delete %q in %s/%s", label.Name, owner, repo) _, err := a.Labeler.DeleteLabel(ctx, owner, repo, label.Name)