diff --git a/CHANGELOG.md b/CHANGELOG.md index e2057b7d..d3cb8cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ - ⚠️ Fixed a pre-hijacking OAuth2 linking vulnerability ([#7662](https://github.com/pocketbase/pocketbase/discussions/7662); thanks @Alardiians for reporting it privately). +- Added `ghupdate.BaseURL` config option ([#7665](https://github.com/pocketbase/pocketbase/issues/7665)). + - Bumped Go and npm dependencies. diff --git a/plugins/ghupdate/ghupdate.go b/plugins/ghupdate/ghupdate.go index 0ffabe69..0a4c9618 100644 --- a/plugins/ghupdate/ghupdate.go +++ b/plugins/ghupdate/ghupdate.go @@ -46,6 +46,12 @@ type Config struct { // (default to "pocketbase"; an additional ".exe" check is also performed as a fallback). ArchiveExecutable string + // BaseURL is the base URL of the GitHub API (or similar compatible) + // used to fetch the latest releases information. + // + // Defaults to "https://api.github.com". + BaseURL string + // Optional context to use when fetching and downloading the latest release. Context context.Context @@ -82,6 +88,12 @@ func Register(app core.App, rootCmd *cobra.Command, config Config) error { p.config.ArchiveExecutable = "pocketbase" } + if p.config.BaseURL == "" { + p.config.BaseURL = "https://api.github.com" + } else { + p.config.BaseURL = strings.TrimRight(p.config.BaseURL, "/") + } + if p.config.HttpClient == nil { p.config.HttpClient = http.DefaultClient } @@ -145,12 +157,9 @@ func (p *plugin) updateCmd() *cobra.Command { func (p *plugin) update(withBackup bool) error { color.Yellow("Fetching release information...") - latest, err := fetchLatestRelease( - p.config.Context, - p.config.HttpClient, - p.config.Owner, - p.config.Repo, - ) + url := fmt.Sprintf("%s/repos/%s/%s/releases/latest", p.config.BaseURL, p.config.Owner, p.config.Repo) + + latest, err := fetchLatestRelease(p.config.Context, p.config.HttpClient, url) if err != nil { return err } @@ -260,11 +269,8 @@ func (p *plugin) update(withBackup bool) error { func fetchLatestRelease( ctx context.Context, client HttpClient, - owner string, - repo string, + url string, ) (*release, error) { - url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", owner, repo) - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, err