MCPcopy
hub / github.com/cli/cli / updateLabel

Function updateLabel

pkg/cmd/label/create.go:158–182  ·  view source on GitHub ↗
(apiClient *api.Client, repo ghrepo.Interface, opts *editOptions)

Source from the content-addressed store, hash-verified

156}
157
158func 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
184func 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"

Callers 2

editRunFunction · 0.85
createLabelFunction · 0.85

Calls 5

RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected