MCPcopy
hub / github.com/cli/cli / ProjectsV2ItemsForIssue

Function ProjectsV2ItemsForIssue

api/queries_projects_v2.go:65–133  ·  view source on GitHub ↗

ProjectsV2ItemsForIssue fetches all ProjectItems for an issue.

(client *Client, repo ghrepo.Interface, issue *Issue)

Source from the content-addressed store, hash-verified

63
64// ProjectsV2ItemsForIssue fetches all ProjectItems for an issue.
65func ProjectsV2ItemsForIssue(client *Client, repo ghrepo.Interface, issue *Issue) error {
66 type projectV2ItemStatus struct {
67 StatusFragment struct {
68 OptionID string `json:"optionId"`
69 Name string `json:"name"`
70 } `graphql:"... on ProjectV2ItemFieldSingleSelectValue"`
71 }
72
73 type projectV2Item struct {
74 ID string `json:"id"`
75 Project struct {
76 ID string `json:"id"`
77 Title string `json:"title"`
78 }
79 Status projectV2ItemStatus `graphql:"status:fieldValueByName(name: \"Status\")"`
80 }
81
82 type response struct {
83 Repository struct {
84 Issue struct {
85 ProjectItems struct {
86 TotalCount int
87 Nodes []*projectV2Item
88 PageInfo struct {
89 HasNextPage bool
90 EndCursor string
91 }
92 } `graphql:"projectItems(first: 100, after: $endCursor)"`
93 } `graphql:"issue(number: $number)"`
94 } `graphql:"repository(owner: $owner, name: $name)"`
95 }
96 variables := map[string]interface{}{
97 "owner": githubv4.String(repo.RepoOwner()),
98 "name": githubv4.String(repo.RepoName()),
99 "number": githubv4.Int(issue.Number),
100 "endCursor": (*githubv4.String)(nil),
101 }
102 var items ProjectItems
103 for {
104 var query response
105 err := client.Query(repo.RepoHost(), "IssueProjectItems", &query, variables)
106 if err != nil {
107 return err
108 }
109 for _, projectItemNode := range query.Repository.Issue.ProjectItems.Nodes {
110 if projectItemNode == nil {
111 continue
112 }
113 items.Nodes = append(items.Nodes, &ProjectV2Item{
114 ID: projectItemNode.ID,
115 Project: ProjectV2ItemProject{
116 ID: projectItemNode.Project.ID,
117 Title: projectItemNode.Project.Title,
118 },
119 Status: ProjectV2ItemStatus{
120 OptionID: projectItemNode.Status.StatusFragment.OptionID,
121 Name: projectItemNode.Status.StatusFragment.Name,
122 },

Callers 2

FindIssueOrPRFunction · 0.92

Calls 5

RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.45

Tested by 1