diff --git a/config/config.go b/config/config.go index 8b29a4d41..e293781c7 100644 --- a/config/config.go +++ b/config/config.go @@ -15,9 +15,10 @@ import ( // Repo represents any kind of repo (github, gitlab, etc) type Repo struct { - Owner string `yaml:",omitempty"` - Name string `yaml:",omitempty"` - URL string `yaml:",omitempty"` + Owner string `yaml:",omitempty"` + Name string `yaml:",omitempty"` + APIURL string `yaml:api_url",omitempty"` + UploadsURL string `yaml:uploads_url",omitempty"` // Capture all undefined fields and should be empty after loading XXX map[string]interface{} `yaml:",inline"` diff --git a/internal/client/github.go b/internal/client/github.go index 49cadd0c5..8daf09c06 100644 --- a/internal/client/github.go +++ b/internal/client/github.go @@ -7,7 +7,6 @@ import ( "github.com/apex/log" "github.com/google/go-github/github" - "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "golang.org/x/oauth2" ) @@ -17,23 +16,26 @@ type githubClient struct { } // NewGitHub returns a github client implementation -func NewGitHub(ctx *context.Context, repo config.Repo) Client { +func NewGitHub(ctx *context.Context, api, upload string) (Client, error) { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: ctx.Token}, ) client := github.NewClient(oauth2.NewClient(ctx, ts)) - if repo.URL != "" { - url, err := url.Parse(repo.URL) + if api != "" { + apiURL, err := url.Parse(api) if err != nil { - // TODO: return the err here - log.Fatal("failed to parse url") + return &githubClient{}, err } - // TODO: check if we need to change upload url as well - client.BaseURL = url + client.BaseURL = apiURL } - return &githubClient{ - client: client, + if upload != "" { + uploadURL, err := url.Parse(upload) + if err != nil { + return &githubClient{}, err + } + client.UploadURL = uploadURL } + return &githubClient{client}, nil } func (c *githubClient) CreateFile( diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index e72fa2758..f8ca7e65a 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -33,7 +33,11 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - return doRun(ctx, client.NewGitHub(ctx, ctx.Config.Brew.GitHub)) + client, err := client.NewGitHub(ctx, ctx.Config.Brew.GitHub.APIURL, ctx.Config.Brew.GitHub.UploadsURL) + if err != nil { + return err + } + return doRun(ctx, client) } func doRun(ctx *context.Context, client client.Client) error { diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 27500529f..0740a09d4 100644 --- a/pipeline/release/release.go +++ b/pipeline/release/release.go @@ -23,7 +23,11 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - return doRun(ctx, client.NewGitHub(ctx, ctx.Config.Release.GitHub)) + client, err := client.NewGitHub(ctx, ctx.Config.Release.GitHub.APIURL, ctx.Config.Release.GitHub.UploadsURL) + if err != nil { + return err + } + return doRun(ctx, client) } func doRun(ctx *context.Context, client client.Client) error {