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

Function IssueCreate

api/queries_issue.go:326–389  ·  view source on GitHub ↗

IssueCreate creates an issue in a GitHub repository

(client *Client, repo *Repository, params map[string]any)

Source from the content-addressed store, hash-verified

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

Callers 1

createRunFunction · 0.92

Calls 5

UpdateProjectV2ItemsFunction · 0.85
GraphQLMethod · 0.80
ErrorfMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected