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

Function getLatestReleaseInfo

internal/update/update.go:116–147  ·  view source on GitHub ↗
(ctx context.Context, client *http.Client, repo string)

Source from the content-addressed store, hash-verified

114}
115
116func getLatestReleaseInfo(ctx context.Context, client *http.Client, repo string) (*ReleaseInfo, error) {
117 owner, name, err := safeurl.RepoPartsFromNWO(repo)
118 if err != nil {
119 return nil, err
120 }
121 u, err := safeurl.JoinPathWithHostPrefix("https://api.github.com", "repos", owner, name, "releases", "latest")
122 if err != nil {
123 return nil, err
124 }
125 // The URL stays absolute on purpose: CLI releases live on github.com regardless of the
126 // host the user has configured, so this must not be rewritten to their API host.
127 // TODO(api-client-rollout)
128 // This line of code is part of a mechanical roll out of the api client.
129 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
130 res, err := api.NewClientFromHTTP(client).RequestWithContext(ctx, "github.com", http.MethodGet, u.String(), nil)
131 if err != nil {
132 return nil, err
133 }
134 defer func() {
135 _, _ = io.Copy(io.Discard, res.Body)
136 res.Body.Close()
137 }()
138 if res.StatusCode != 200 {
139 return nil, api.UnexpectedStatusError(res)
140 }
141 dec := json.NewDecoder(res.Body)
142 var latestRelease ReleaseInfo
143 if err := dec.Decode(&latestRelease); err != nil {
144 return nil, err
145 }
146 return &latestRelease, nil
147}
148
149func getStateEntry(stateFilePath string) (*StateEntry, error) {
150 content, err := os.ReadFile(stateFilePath)

Callers 1

CheckForUpdateFunction · 0.85

Calls 8

RepoPartsFromNWOFunction · 0.92
JoinPathWithHostPrefixFunction · 0.92
NewClientFromHTTPFunction · 0.92
UnexpectedStatusErrorFunction · 0.92
RequestWithContextMethod · 0.80
StringMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected