MCPcopy
hub / github.com/cli/cli / fetchReleases

Function fetchReleases

pkg/cmd/release/list/http.go:41–119  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, limit int, excludeDrafts bool, excludePreReleases bool, order string, releaseFeatures fd.ReleaseFeatures)

Source from the content-addressed store, hash-verified

39}
40
41func fetchReleases(httpClient *http.Client, repo ghrepo.Interface, limit int, excludeDrafts bool, excludePreReleases bool, order string, releaseFeatures fd.ReleaseFeatures) ([]Release, error) {
42 // TODO: immutableReleaseFullSupport
43 // This is a temporary workaround until all supported GHES versions fully
44 // support immutable releases, which would probably be when GHES 3.18 goes
45 // EOL. At that point we can remove this if statement.
46 //
47 // Note 1: This could have been done differently by using two separate query
48 // types or even using plain text/string queries. But, both would require us
49 // to refactor them back in the future, to the single, strongly-typed query
50 // approach as it was before. So, duplicating the entire function for now
51 // seems like the lesser evil, with a quicker and less risky clean up in the
52 // near future.
53 //
54 // Note 2: We couldn't use GraphQL directives like `@include(condition)` or
55 // `@skip(condition)` here because if the field doesn't exist on the schema
56 // then the whole query would still fail regardless of the condition being
57 // met or not.
58 // TODO immutableReleaseFullSupport
59 if !releaseFeatures.ImmutableReleases {
60 return fetchReleasesWithoutImmutableReleases(httpClient, repo, limit, excludeDrafts, excludePreReleases, order)
61 }
62
63 type responseData struct {
64 Repository struct {
65 Releases struct {
66 Nodes []Release
67 PageInfo struct {
68 HasNextPage bool
69 EndCursor string
70 }
71 } `graphql:"releases(first: $perPage, orderBy: {field: CREATED_AT, direction: $direction}, after: $endCursor)"`
72 } `graphql:"repository(owner: $owner, name: $name)"`
73 }
74
75 perPage := limit
76 if limit > 100 {
77 perPage = 100
78 }
79
80 variables := map[string]interface{}{
81 "owner": githubv4.String(repo.RepoOwner()),
82 "name": githubv4.String(repo.RepoName()),
83 "perPage": githubv4.Int(perPage),
84 "endCursor": (*githubv4.String)(nil),
85 "direction": githubv4.OrderDirection(strings.ToUpper(order)),
86 }
87
88 gql := api.NewClientFromHTTP(httpClient)
89
90 var releases []Release
91loop:
92 for {
93 var query responseData
94 err := gql.Query(repo.RepoHost(), "RepositoryReleaseList", &query, variables)
95 if err != nil {
96 return nil, err
97 }
98

Callers 1

listRunFunction · 0.85

Calls 7

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

Tested by

no test coverage detected