label.go 989 字节
Newer Older
P
Pepper Lebeck-Jobe 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
package commands

import (
	"github.com/github/hub/github"
	"github.com/github/hub/ui"
	"github.com/github/hub/utils"
)


var (
	cmdLabel = &Command{
		Run: listLabels,
		Usage: `
label
`,
		Long: `Manage GitHub labels for the current repository.

## Commands:

With no arguments, show a list of open issues.
`,
	}
)

func init() {
	CmdRunner.Use(cmdLabel)
}

func listLabels(cmd *Command, args *Args) {
	localRepo, err := github.LocalRepo()
	utils.Check(err)

	project, err := localRepo.MainProject()
	utils.Check(err)

	gh := github.NewClient(project.Host)

    if args.Noop {
		ui.Printf("Would request list of labels for %s\n", project)
	} else {
		labels, err := gh.FetchLabels(project)
		utils.Check(err)

		for _, label := range labels {
			ui.Printf(formatLabel(label))
		}
	}

	args.NoForward()
}

func formatLabel(label github.IssueLabel) string {
    format := "%l%n"

	placeholders := map[string]string{
		"l":  label.Name,
	}

	return ui.Expand(format, placeholders, false)
}