createIterationField handles the create_iteration_field method for ProjectsWrite. GitHub's GraphQL API requires two mutations to fully configure an iteration field: 1. createProjectV2Field creates the field with DataType=ITERATION (no schedule yet). 2. updateProjectV2Field sets the start date, dura
(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, projectNumber int, args map[string]any)
| 1622 | // by calling this method again (the create will fail with a duplicate-name error, which |
| 1623 | // surfaces clearly) or by deleting the field via the GitHub UI. |
| 1624 | func createIterationField(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, projectNumber int, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 1625 | fieldName, err := RequiredParam[string](args, "field_name") |
| 1626 | if err != nil { |
| 1627 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1628 | } |
| 1629 | duration, err := RequiredInt(args, "iteration_duration") |
| 1630 | if err != nil { |
| 1631 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1632 | } |
| 1633 | startDateStr, err := RequiredParam[string](args, "start_date") |
| 1634 | if err != nil { |
| 1635 | return utils.NewToolResultError(err.Error()), nil, nil |
| 1636 | } |
| 1637 | |
| 1638 | projectID, err := resolveProjectNodeID(ctx, gqlClient, owner, ownerType, projectNumber) |
| 1639 | if err != nil { |
| 1640 | return utils.NewToolResultError(fmt.Sprintf("failed to get project ID: %v", err)), nil, nil |
| 1641 | } |
| 1642 | |
| 1643 | // Step 1: Create the iteration field. |
| 1644 | var createMutation struct { |
| 1645 | CreateProjectV2Field struct { |
| 1646 | ProjectV2Field struct { |
| 1647 | ProjectV2IterationField struct { |
| 1648 | ID string |
| 1649 | Name string |
| 1650 | } `graphql:"... on ProjectV2IterationField"` |
| 1651 | } `graphql:"projectV2Field"` |
| 1652 | } `graphql:"createProjectV2Field(input: $input)"` |
| 1653 | } |
| 1654 | |
| 1655 | createInput := githubv4.CreateProjectV2FieldInput{ |
| 1656 | ProjectID: githubv4.ID(projectID), |
| 1657 | DataType: githubv4.ProjectV2CustomFieldType("ITERATION"), |
| 1658 | Name: githubv4.String(fieldName), |
| 1659 | } |
| 1660 | |
| 1661 | err = gqlClient.Mutate(ctx, &createMutation, createInput, nil) |
| 1662 | if err != nil { |
| 1663 | return utils.NewToolResultError(fmt.Sprintf("failed to create iteration field: %v", err)), nil, nil |
| 1664 | } |
| 1665 | |
| 1666 | fieldID := createMutation.CreateProjectV2Field.ProjectV2Field.ProjectV2IterationField.ID |
| 1667 | |
| 1668 | // Step 2: Configure the iteration field with start date and duration. |
| 1669 | var updateMutation struct { |
| 1670 | UpdateProjectV2Field struct { |
| 1671 | ProjectV2Field struct { |
| 1672 | ProjectV2IterationField struct { |
| 1673 | ID string |
| 1674 | Name string |
| 1675 | Configuration struct { |
| 1676 | Iterations []struct { |
| 1677 | ID string |
| 1678 | Title string |
| 1679 | StartDate string |
| 1680 | Duration int |
| 1681 | } |
no test coverage detected