[#7665] added BaseURL to the ghupdate plugin configuration
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user