MCPcopy Create free account
hub / github.com/cli/cli / createRun

Function createRun

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

Source from the content-addressed store, hash-verified

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