MCPcopy Index your code
hub / github.com/cli/cli / createRun

Function createRun

pkg/cmd/label/create.go:93–126  ·  view source on GitHub ↗
(opts *createOptions)

Source from the content-addressed store, hash-verified

91var errLabelAlreadyExists = errors.New("label already exists")
92
93func createRun(opts *createOptions) error {
94 httpClient, err := opts.HttpClient()
95 if err != nil {
96 return err
97 }
98
99 baseRepo, err := opts.BaseRepo()
100 if err != nil {
101 return err
102 }
103
104 if opts.Color == "" {
105 r := rand.New(rand.NewSource(time.Now().UnixNano()))
106 opts.Color = randomColors[r.Intn(len(randomColors)-1)]
107 }
108
109 opts.IO.StartProgressIndicator()
110 err = createLabel(httpClient, baseRepo, opts)
111 opts.IO.StopProgressIndicator()
112 if err != nil {
113 if errors.Is(err, errLabelAlreadyExists) {
114 return fmt.Errorf("label with name %q already exists; use `--force` to update its color and description", opts.Name)
115 }
116 return err
117 }
118
119 if opts.IO.IsStdoutTTY() {
120 cs := opts.IO.ColorScheme()
121 successMsg := fmt.Sprintf("%s Label %q created in %s\n", cs.SuccessIcon(), opts.Name, ghrepo.FullName(baseRepo))
122 fmt.Fprint(opts.IO.Out, successMsg)
123 }
124
125 return nil
126}
127
128func createLabel(client *http.Client, repo ghrepo.Interface, opts *createOptions) error {
129 apiClient := api.NewClientFromHTTP(client)

Callers 2

TestCreateRunFunction · 0.70
newCmdCreateFunction · 0.70

Calls 9

FullNameFunction · 0.92
createLabelFunction · 0.85
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
BaseRepoMethod · 0.65
StopProgressIndicatorMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestCreateRunFunction · 0.56