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