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)
| 203 | // newest version's number means the current version, like 0 does. A number |
| 204 | // the API didn't return is an error. |
| 205 | func 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 |