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