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

Function FindVersion

pkg/cmd/issue/artifact/shared/shared.go:205–217  ·  view source on GitHub ↗

FindVersion returns the version numbered number from an artifact's edit history, or nil for the current version. Versions come newest first, so the newest version's number means the current version, like 0 does. A number the API didn't return is an error.

(a *client.ArtifactWithVersions, number int)

Source from the content-addressed store, hash-verified

203// newest version's number means the current version, like 0 does. A number
204// the API didn't return is an error.
205func FindVersion(a *client.ArtifactWithVersions, number int) (*client.Version, error) {
206 if number == 0 {
207 return nil, nil
208 }
209 i := slices.IndexFunc(a.Versions, func(v client.Version) bool { return v.Version == number })
210 switch {
211 case i < 0:
212 return nil, fmt.Errorf("version %d not found for artifact %d", number, a.Number)
213 case i == 0:
214 return nil, nil
215 }
216 return &a.Versions[i], nil
217}
218
219// CheckHost refuses GitHub Enterprise Server, which doesn't support issue
220// artifacts. Callers run it before any request, so the user gets this reason

Callers 4

viewRunFunction · 0.92
selectVersionFunction · 0.92
restoreVersionFunction · 0.92
TestFindVersionFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by 1

TestFindVersionFunction · 0.68