FetchLatestRelease returns the latest published release of the plugin's GitHub repository, mirroring the WebUI panel update check.
(ctx context.Context, plugin Plugin)
| 56 | // FetchLatestRelease returns the latest published release of the plugin's |
| 57 | // GitHub repository, mirroring the WebUI panel update check. |
| 58 | func (c Client) FetchLatestRelease(ctx context.Context, plugin Plugin) (Release, error) { |
| 59 | owner, repo, errRepository := GitHubRepositoryParts(plugin.Repository) |
| 60 | if errRepository != nil { |
| 61 | return Release{}, errRepository |
| 62 | } |
| 63 | releaseURL := fmt.Sprintf( |
| 64 | "https://api.github.com/repos/%s/%s/releases/latest", |
| 65 | url.PathEscape(owner), |
| 66 | url.PathEscape(repo), |
| 67 | ) |
| 68 | data, errDownload := c.get(ctx, releaseURL, "application/vnd.github+json", RequestKindMetadata, 0) |
| 69 | if errDownload != nil { |
| 70 | return Release{}, errDownload |
| 71 | } |
| 72 | var release Release |
| 73 | if errDecode := json.Unmarshal(data, &release); errDecode != nil { |
| 74 | return Release{}, fmt.Errorf("decode release: %w", errDecode) |
| 75 | } |
| 76 | return release, nil |
| 77 | } |
| 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) { |
no test coverage detected