FetchReleaseByTag returns a published release by its exact GitHub tag.
(ctx context.Context, plugin Plugin, tag string)
| 78 | |
| 79 | // FetchReleaseByTag returns a published release by its exact GitHub tag. |
| 80 | func (c Client) FetchReleaseByTag(ctx context.Context, plugin Plugin, tag string) (Release, error) { |
| 81 | owner, repo, errRepository := GitHubRepositoryParts(plugin.Repository) |
| 82 | if errRepository != nil { |
| 83 | return Release{}, errRepository |
| 84 | } |
| 85 | tag = strings.TrimSpace(tag) |
| 86 | if tag == "" { |
| 87 | return Release{}, fmt.Errorf("release tag is required") |
| 88 | } |
| 89 | releaseURL := fmt.Sprintf( |
| 90 | "https://api.github.com/repos/%s/%s/releases/tags/%s", |
| 91 | url.PathEscape(owner), |
| 92 | url.PathEscape(repo), |
| 93 | url.PathEscape(tag), |
| 94 | ) |
| 95 | data, errDownload := c.get(ctx, releaseURL, "application/vnd.github+json", RequestKindMetadata, 0) |
| 96 | if errDownload != nil { |
| 97 | return Release{}, errDownload |
| 98 | } |
| 99 | var release Release |
| 100 | if errDecode := json.Unmarshal(data, &release); errDecode != nil { |
| 101 | return Release{}, fmt.Errorf("decode release: %w", errDecode) |
| 102 | } |
| 103 | return release, nil |
| 104 | } |
| 105 | |
| 106 | // ReleaseVersion derives the plugin version from the release tag, stripping a |
| 107 | // leading "v"/"V" and validating the result. |
no test coverage detected