MCPcopy
hub / github.com/cli/cli / RepoProjectsV2

Function RepoProjectsV2

api/queries_projects_v2.go:247–284  ·  view source on GitHub ↗

RepoProjectsV2 fetches all open projectsV2 for a repository.

(client *Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

245
246// RepoProjectsV2 fetches all open projectsV2 for a repository.
247func RepoProjectsV2(client *Client, repo ghrepo.Interface) ([]ProjectV2, error) {
248 type responseData struct {
249 Repository struct {
250 ProjectsV2 struct {
251 Nodes []ProjectV2
252 PageInfo struct {
253 HasNextPage bool
254 EndCursor string
255 }
256 } `graphql:"projectsV2(first: 100, orderBy: {field: TITLE, direction: ASC}, after: $endCursor, query: $query)"`
257 } `graphql:"repository(owner: $owner, name: $name)"`
258 }
259
260 variables := map[string]interface{}{
261 "owner": githubv4.String(repo.RepoOwner()),
262 "name": githubv4.String(repo.RepoName()),
263 "endCursor": (*githubv4.String)(nil),
264 "query": githubv4.String("is:open"),
265 }
266
267 var projectsV2 []ProjectV2
268 for {
269 var query responseData
270 err := client.Query(repo.RepoHost(), "RepositoryProjectV2List", &query, variables)
271 if err != nil {
272 return nil, err
273 }
274
275 projectsV2 = append(projectsV2, query.Repository.ProjectsV2.Nodes...)
276
277 if !query.Repository.ProjectsV2.PageInfo.HasNextPage {
278 break
279 }
280 variables["endCursor"] = githubv4.String(query.Repository.ProjectsV2.PageInfo.EndCursor)
281 }
282
283 return projectsV2, nil
284}
285
286// CurrentUserProjectsV2 fetches all open projectsV2 for current user.
287func CurrentUserProjectsV2(client *Client, hostname string) ([]ProjectV2, error) {

Callers 1

v2ProjectsFunction · 0.85

Calls 5

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

Tested by

no test coverage detected