1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

fixed uploads url

This commit is contained in:
Carlos Alexandro Becker 2017-09-22 09:42:36 -03:00
parent cff77260cc
commit 618711cd43
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
4 changed files with 26 additions and 15 deletions

View File

@ -15,9 +15,10 @@ import (
// Repo represents any kind of repo (github, gitlab, etc) // Repo represents any kind of repo (github, gitlab, etc)
type Repo struct { type Repo struct {
Owner string `yaml:",omitempty"` Owner string `yaml:",omitempty"`
Name string `yaml:",omitempty"` Name string `yaml:",omitempty"`
URL 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 // Capture all undefined fields and should be empty after loading
XXX map[string]interface{} `yaml:",inline"` XXX map[string]interface{} `yaml:",inline"`

View File

@ -7,7 +7,6 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/google/go-github/github" "github.com/google/go-github/github"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -17,23 +16,26 @@ type githubClient struct {
} }
// NewGitHub returns a github client implementation // 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( ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ctx.Token}, &oauth2.Token{AccessToken: ctx.Token},
) )
client := github.NewClient(oauth2.NewClient(ctx, ts)) client := github.NewClient(oauth2.NewClient(ctx, ts))
if repo.URL != "" { if api != "" {
url, err := url.Parse(repo.URL) apiURL, err := url.Parse(api)
if err != nil { if err != nil {
// TODO: return the err here return &githubClient{}, err
log.Fatal("failed to parse url")
} }
// TODO: check if we need to change upload url as well client.BaseURL = apiURL
client.BaseURL = url
} }
return &githubClient{ if upload != "" {
client: client, uploadURL, err := url.Parse(upload)
if err != nil {
return &githubClient{}, err
}
client.UploadURL = uploadURL
} }
return &githubClient{client}, nil
} }
func (c *githubClient) CreateFile( func (c *githubClient) CreateFile(

View File

@ -33,7 +33,11 @@ func (Pipe) Description() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { 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 { func doRun(ctx *context.Context, client client.Client) error {

View File

@ -23,7 +23,11 @@ func (Pipe) Description() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { 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 { func doRun(ctx *context.Context, client client.Client) error {