MCPcopy Create free account
hub / github.com/cli/cli / ProjectItemIDByURL

Method ProjectItemIDByURL

pkg/cmd/project/shared/queries/resolve.go:153–191  ·  view source on GitHub ↗

ProjectItemIDByURL returns the project item ID for the issue or pull request at rawURL on the project identified by projectID. projectNumber is used only to build a helpful error message. It returns a *ItemNotInProjectError when the resource exists but is not an item on the project. The projectItem

(rawURL, projectID string, projectNumber int32)

Source from the content-addressed store, hash-verified

151// The projectItems connection is read with a bounded page size; very large
152// boards may exceed it.
153func (c *Client) ProjectItemIDByURL(rawURL, projectID string, projectNumber int32) (string, error) {
154 uri, err := url.Parse(rawURL)
155 if err != nil {
156 return "", err
157 }
158
159 variables := map[string]interface{}{
160 "url": githubv4.URI{URL: uri},
161 "firstItems": githubv4.Int(LimitMax),
162 }
163
164 var query projectItemByURL
165 if err := c.doQueryWithProgressIndicator("GetProjectItemByURL", &query, variables); err != nil {
166 return "", err
167 }
168
169 var nodes []struct {
170 ID string
171 Project struct {
172 ID string
173 }
174 }
175 switch query.Resource.Typename {
176 case "Issue":
177 nodes = query.Resource.Issue.ProjectItems.Nodes
178 case "PullRequest":
179 nodes = query.Resource.PullRequest.ProjectItems.Nodes
180 default:
181 return "", fmt.Errorf("resource not found, please check the URL: %s", rawURL)
182 }
183
184 for _, n := range nodes {
185 if n.Project.ID == projectID {
186 return n.ID, nil
187 }
188 }
189
190 return "", &ItemNotInProjectError{URL: rawURL, ProjectNumber: projectNumber}
191}

Callers 2

resolveItemEditNamesFunction · 0.80
TestProjectItemIDByURLFunction · 0.80

Calls 2

ErrorfMethod · 0.65

Tested by 1

TestProjectItemIDByURLFunction · 0.64