createProject handles the create_project method for ProjectsWrite.
(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, args map[string]any)
| 1559 | |
| 1560 | // createProject handles the create_project method for ProjectsWrite. |
| 1561 | func createProject(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 1562 | if ownerType == "" { |
| 1563 | return utils.NewToolResultError("owner_type is required for create_project"), nil, nil |
| 1564 | } |
| 1565 | if ownerType != "user" && ownerType != "org" { |
| 1566 | return utils.NewToolResultError(fmt.Sprintf("invalid owner_type %q: must be \"user\" or \"org\"", ownerType)), nil, nil |
| 1567 | } |
| 1568 | |
| 1569 | title, err := RequiredParam[string](args, "title") |
| 1570 | if err != nil { |
| 1571 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1572 | } |
| 1573 | |
| 1574 | ownerID, err := getOwnerNodeID(ctx, gqlClient, owner, ownerType) |
| 1575 | if err != nil { |
| 1576 | return utils.NewToolResultError(fmt.Sprintf("failed to get owner ID: %v", err)), nil, nil |
| 1577 | } |
| 1578 | |
| 1579 | var mutation struct { |
| 1580 | CreateProjectV2 struct { |
| 1581 | ProjectV2 struct { |
| 1582 | ID string |
| 1583 | Number int |
| 1584 | Title string |
| 1585 | URL string |
| 1586 | } |
| 1587 | } `graphql:"createProjectV2(input: $input)"` |
| 1588 | } |
| 1589 | |
| 1590 | input := githubv4.CreateProjectV2Input{ |
| 1591 | OwnerID: githubv4.ID(ownerID), |
| 1592 | Title: githubv4.String(title), |
| 1593 | } |
| 1594 | |
| 1595 | err = gqlClient.Mutate(ctx, &mutation, input, nil) |
| 1596 | if err != nil { |
| 1597 | return utils.NewToolResultError(fmt.Sprintf("failed to create project: %v", err)), nil, nil |
| 1598 | } |
| 1599 | |
| 1600 | result := struct { |
| 1601 | ID string `json:"id"` |
| 1602 | Number int `json:"number"` |
| 1603 | Title string `json:"title"` |
| 1604 | URL string `json:"url"` |
| 1605 | }{ |
| 1606 | ID: mutation.CreateProjectV2.ProjectV2.ID, |
| 1607 | Number: mutation.CreateProjectV2.ProjectV2.Number, |
| 1608 | Title: mutation.CreateProjectV2.ProjectV2.Title, |
| 1609 | URL: mutation.CreateProjectV2.ProjectV2.URL, |
| 1610 | } |
| 1611 | |
| 1612 | return MarshalledTextResult(result), nil, nil |
| 1613 | } |
| 1614 | |
| 1615 | // createIterationField handles the create_iteration_field method for ProjectsWrite. |
| 1616 | // |
no test coverage detected