(apiClient *api.Client, repo ghrepo.Interface, opts *editOptions)
| 156 | } |
| 157 | |
| 158 | func updateLabel(apiClient *api.Client, repo ghrepo.Interface, opts *editOptions) error { |
| 159 | path := fmt.Sprintf("repos/%s/%s/labels/%s", repo.RepoOwner(), repo.RepoName(), opts.Name) |
| 160 | properties := map[string]string{} |
| 161 | if opts.Description != "" { |
| 162 | properties["description"] = opts.Description |
| 163 | } |
| 164 | if opts.Color != "" { |
| 165 | properties["color"] = opts.Color |
| 166 | } |
| 167 | if opts.NewName != "" { |
| 168 | properties["new_name"] = opts.NewName |
| 169 | } |
| 170 | requestByte, err := json.Marshal(properties) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | requestBody := bytes.NewReader(requestByte) |
| 175 | err = apiClient.REST(repo.RepoHost(), "PATCH", path, requestBody, nil) |
| 176 | |
| 177 | if httpError, ok := err.(api.HTTPError); ok && isLabelAlreadyExistsError(httpError) { |
| 178 | err = errLabelAlreadyExists |
| 179 | } |
| 180 | |
| 181 | return err |
| 182 | } |
| 183 | |
| 184 | func isLabelAlreadyExistsError(err api.HTTPError) bool { |
| 185 | return err.StatusCode == 422 && len(err.Errors) == 1 && err.Errors[0].Field == "name" && err.Errors[0].Code == "already_exists" |
no test coverage detected