IssueCreate creates an issue in a GitHub repository
(client *Client, repo *Repository, params map[string]interface{})
| 321 | |
| 322 | // IssueCreate creates an issue in a GitHub repository |
| 323 | func IssueCreate(client *Client, repo *Repository, params map[string]interface{}) (*Issue, error) { |
| 324 | query := ` |
| 325 | mutation IssueCreate($input: CreateIssueInput!) { |
| 326 | createIssue(input: $input) { |
| 327 | issue { |
| 328 | id |
| 329 | url |
| 330 | } |
| 331 | } |
| 332 | }` |
| 333 | |
| 334 | inputParams := map[string]interface{}{ |
| 335 | "repositoryId": repo.ID, |
| 336 | } |
| 337 | for key, val := range params { |
| 338 | switch key { |
| 339 | case "assigneeIds", "body", "issueTemplate", "labelIds", "milestoneId", "projectIds", "repositoryId", "title": |
| 340 | inputParams[key] = val |
| 341 | case "projectV2Ids", "assigneeLogins": |
| 342 | // handled after issue creation |
| 343 | default: |
| 344 | return nil, fmt.Errorf("invalid IssueCreate mutation parameter %s", key) |
| 345 | } |
| 346 | } |
| 347 | variables := map[string]interface{}{ |
| 348 | "input": inputParams, |
| 349 | } |
| 350 | |
| 351 | result := struct { |
| 352 | CreateIssue struct { |
| 353 | Issue Issue |
| 354 | } |
| 355 | }{} |
| 356 | |
| 357 | err := client.GraphQL(repo.RepoHost(), query, variables, &result) |
| 358 | if err != nil { |
| 359 | return nil, err |
| 360 | } |
| 361 | issue := &result.CreateIssue.Issue |
| 362 | |
| 363 | // Assign users using login-based mutation when ApiActorsSupported is true (github.com). |
| 364 | if assigneeLogins, ok := params["assigneeLogins"].([]string); ok && len(assigneeLogins) > 0 { |
| 365 | err := ReplaceActorsForAssignableByLogin(client, repo, issue.ID, assigneeLogins) |
| 366 | if err != nil { |
| 367 | return issue, err |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // projectV2 parameters aren't supported in the `createIssue` mutation, |
| 372 | // so add them after the issue has been created. |
| 373 | projectV2Ids, ok := params["projectV2Ids"].([]string) |
| 374 | if ok { |
| 375 | projectItems := make(map[string]string, len(projectV2Ids)) |
| 376 | for _, p := range projectV2Ids { |
| 377 | projectItems[p] = issue.ID |
| 378 | } |
| 379 | err = UpdateProjectV2Items(client, repo, projectItems, nil) |
| 380 | if err != nil { |
no test coverage detected