(client *http.Client, repo ghrepo.Interface, opts *createOptions)
| 127 | } |
| 128 | |
| 129 | func createLabel(client *http.Client, repo ghrepo.Interface, opts *createOptions) error { |
| 130 | apiClient := api.NewClientFromHTTP(client) |
| 131 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "labels") |
| 132 | if err != nil { |
| 133 | return err |
| 134 | } |
| 135 | requestByte, err := json.Marshal(map[string]string{ |
| 136 | "name": opts.Name, |
| 137 | "description": opts.Description, |
| 138 | "color": opts.Color, |
| 139 | }) |
| 140 | if err != nil { |
| 141 | return err |
| 142 | } |
| 143 | requestBody := bytes.NewReader(requestByte) |
| 144 | err = apiClient.REST(repo.RepoHost(), "POST", path.String(), requestBody, nil) |
| 145 | |
| 146 | if httpError, ok := err.(api.HTTPError); ok && isLabelAlreadyExistsError(httpError) { |
| 147 | err = errLabelAlreadyExists |
| 148 | } |
| 149 | |
| 150 | if opts.Force && errors.Is(err, errLabelAlreadyExists) { |
| 151 | editOpts := editOptions{ |
| 152 | Description: opts.Description, |
| 153 | Color: opts.Color, |
| 154 | Name: opts.Name, |
| 155 | } |
| 156 | return updateLabel(apiClient, repo, &editOpts) |
| 157 | } |
| 158 | |
| 159 | return err |
| 160 | } |
| 161 | |
| 162 | func updateLabel(apiClient *api.Client, repo ghrepo.Interface, opts *editOptions) error { |
| 163 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "labels", opts.Name) |
no test coverage detected