| 92 | var errLabelAlreadyExists = errors.New("label already exists") |
| 93 | |
| 94 | func 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 | |
| 129 | func createLabel(client *http.Client, repo ghrepo.Interface, opts *createOptions) error { |
| 130 | apiClient := api.NewClientFromHTTP(client) |