createOrgIssue creates a GitHub issue with the given title, body, and label. If creating with the label fails (e.g. label does not exist), it retries once without the label so the issue is always created.
(ctx context.Context, repo, title, body, label string)
| 212 | // creating with the label fails (e.g. label does not exist), it retries once without |
| 213 | // the label so the issue is always created. |
| 214 | func createOrgIssue(ctx context.Context, repo, title, body, label string) error { |
| 215 | endpoint := fmt.Sprintf("/repos/%s/issues", repo) |
| 216 | remoteHost := getHostFromOriginRemote() |
| 217 | output, err := runOrgAPICombined(ctx, remoteHost, "Creating issue...", |
| 218 | "--method", "POST", |
| 219 | endpoint, |
| 220 | "-f", "title="+title, |
| 221 | "-f", "body="+body, |
| 222 | "-f", "labels[]="+label, |
| 223 | ) |
| 224 | if err == nil { |
| 225 | return nil |
| 226 | } |
| 227 | if !isLabelValidationError(output, err) { |
| 228 | return err |
| 229 | } |
| 230 | // Label may not exist; retry without it so the issue is always created. |
| 231 | orgIPLog.Printf("Failed to create issue with label %q, retrying without: %v", label, err) |
| 232 | _, err = runOrgAPI(ctx, remoteHost, "Creating issue...", |
| 233 | "--method", "POST", |
| 234 | endpoint, |
| 235 | "-f", "title="+title, |
| 236 | "-f", "body="+body, |
| 237 | ) |
| 238 | return err |
| 239 | } |