MCPcopy Create free account
hub / github.com/cli/cli / updateLabel

Function updateLabel

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

Source from the content-addressed store, hash-verified

160}
161
162func updateLabel(apiClient *api.Client, repo ghrepo.Interface, opts *editOptions) error {
163 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "labels", opts.Name)
164 if err != nil {
165 return err
166 }
167 properties := map[string]string{}
168 if opts.Description != "" {
169 properties["description"] = opts.Description
170 }
171 if opts.Color != "" {
172 properties["color"] = opts.Color
173 }
174 if opts.NewName != "" {
175 properties["new_name"] = opts.NewName
176 }
177 requestByte, err := json.Marshal(properties)
178 if err != nil {
179 return err
180 }
181 requestBody := bytes.NewReader(requestByte)
182 err = apiClient.REST(repo.RepoHost(), "PATCH", path.String(), requestBody, nil)
183
184 if httpError, ok := err.(api.HTTPError); ok && isLabelAlreadyExistsError(httpError) {
185 err = errLabelAlreadyExists
186 }
187
188 return err
189}
190
191func isLabelAlreadyExistsError(err api.HTTPError) bool {
192 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 7

JoinPathFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected