MCPcopy
hub / github.com/cli/cli / UpdateProjectV2Items

Function UpdateProjectV2Items

api/queries_projects_v2.go:35–62  ·  view source on GitHub ↗

UpdateProjectV2Items uses the addProjectV2ItemById and the deleteProjectV2Item mutations to add and delete items from projects. The addProjectItems and deleteProjectItems arguments are mappings between a project and an item. This function can be used across multiple projects and items. Note that the

(client *Client, repo ghrepo.Interface, addProjectItems, deleteProjectItems map[string]string)

Source from the content-addressed store, hash-verified

33// and items. Note that the deleteProjectV2Item mutation requires the item id from the project not
34// the global id.
35func UpdateProjectV2Items(client *Client, repo ghrepo.Interface, addProjectItems, deleteProjectItems map[string]string) error {
36 l := len(addProjectItems) + len(deleteProjectItems)
37 if l == 0 {
38 return nil
39 }
40 inputs := make([]string, 0, l)
41 mutations := make([]string, 0, l)
42 variables := make(map[string]interface{}, l)
43 var i int
44
45 for project, item := range addProjectItems {
46 inputs = append(inputs, fmt.Sprintf("$input_%03d: AddProjectV2ItemByIdInput!", i))
47 mutations = append(mutations, fmt.Sprintf("add_%03d: addProjectV2ItemById(input: $input_%03d) { item { id } }", i, i))
48 variables[fmt.Sprintf("input_%03d", i)] = map[string]interface{}{"contentId": item, "projectId": project}
49 i++
50 }
51
52 for project, item := range deleteProjectItems {
53 inputs = append(inputs, fmt.Sprintf("$input_%03d: DeleteProjectV2ItemInput!", i))
54 mutations = append(mutations, fmt.Sprintf("delete_%03d: deleteProjectV2Item(input: $input_%03d) { deletedItemId }", i, i))
55 variables[fmt.Sprintf("input_%03d", i)] = map[string]interface{}{"itemId": item, "projectId": project}
56 i++
57 }
58
59 query := fmt.Sprintf(`mutation UpdateProjectV2Items(%s) {%s}`, strings.Join(inputs, " "), strings.Join(mutations, " "))
60
61 return client.GraphQL(repo.RepoHost(), query, variables, nil)
62}
63
64// ProjectsV2ItemsForIssue fetches all ProjectItems for an issue.
65func ProjectsV2ItemsForIssue(client *Client, repo ghrepo.Interface, issue *Issue) error {

Callers 4

UpdateIssueFunction · 0.92
IssueCreateFunction · 0.85
CreatePullRequestFunction · 0.85
TestUpdateProjectV2ItemsFunction · 0.85

Calls 3

JoinMethod · 0.80
GraphQLMethod · 0.80
RepoHostMethod · 0.65

Tested by 1

TestUpdateProjectV2ItemsFunction · 0.68