resolveProjectNodeID resolves (owner, ownerType, projectNumber) to a project node ID via GraphQL.
(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, projectNumber int)
| 1144 | |
| 1145 | // resolveProjectNodeID resolves (owner, ownerType, projectNumber) to a project node ID via GraphQL. |
| 1146 | func resolveProjectNodeID(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, projectNumber int) (githubv4.ID, error) { |
| 1147 | var projectIDQueryUser struct { |
| 1148 | User struct { |
| 1149 | ProjectV2 struct { |
| 1150 | ID githubv4.ID |
| 1151 | } `graphql:"projectV2(number: $projectNumber)"` |
| 1152 | } `graphql:"user(login: $owner)"` |
| 1153 | } |
| 1154 | var projectIDQueryOrg struct { |
| 1155 | Organization struct { |
| 1156 | ProjectV2 struct { |
| 1157 | ID githubv4.ID |
| 1158 | } `graphql:"projectV2(number: $projectNumber)"` |
| 1159 | } `graphql:"organization(login: $owner)"` |
| 1160 | } |
| 1161 | |
| 1162 | queryVars := map[string]any{ |
| 1163 | "owner": githubv4.String(owner), |
| 1164 | "projectNumber": githubv4.Int(int32(projectNumber)), //nolint:gosec // Project numbers are small integers |
| 1165 | } |
| 1166 | |
| 1167 | if ownerType == "org" { |
| 1168 | err := gqlClient.Query(ctx, &projectIDQueryOrg, queryVars) |
| 1169 | if err != nil { |
| 1170 | return "", fmt.Errorf("%s: %w", ProjectResolveIDFailedError, err) |
| 1171 | } |
| 1172 | return projectIDQueryOrg.Organization.ProjectV2.ID, nil |
| 1173 | } |
| 1174 | |
| 1175 | err := gqlClient.Query(ctx, &projectIDQueryUser, queryVars) |
| 1176 | if err != nil { |
| 1177 | return "", fmt.Errorf("%s: %w", ProjectResolveIDFailedError, err) |
| 1178 | } |
| 1179 | return projectIDQueryUser.User.ProjectV2.ID, nil |
| 1180 | } |
| 1181 | |
| 1182 | // addProjectItem adds an item to a project by resolving the issue/PR number to a node ID |
| 1183 | func addProjectItem(ctx context.Context, gqlClient *githubv4.Client, owner, ownerType string, projectNumber int, itemOwner, itemRepo string, itemNumber int, itemType string) (*mcp.CallToolResult, any, error) { |
no test coverage detected