From 567b7a9b1b0a8cbfb0432f979772123c7864af5f Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 15 Sep 2017 11:04:03 -0300 Subject: [PATCH] support github enterprise --- config/config.go | 6 ++++-- internal/client/github.go | 15 +++++++++++++-- pipeline/brew/brew.go | 2 +- pipeline/release/release.go | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 72351c87f..72f52f58b 100644 --- a/config/config.go +++ b/config/config.go @@ -17,6 +17,7 @@ import ( type Repo struct { Owner string `yaml:",omitempty"` Name string `yaml:",omitempty"` + URL string `yaml:",omitempty"` // Capture all undefined fields and should be empty after loading XXX map[string]interface{} `yaml:",inline"` @@ -101,8 +102,9 @@ type Archive struct { // Release config used for the GitHub release type Release struct { - GitHub Repo `yaml:",omitempty"` - Draft bool `yaml:",omitempty"` + GitHub Repo `yaml:",omitempty"` + Draft bool `yaml:",omitempty"` + GitHubURL string `yaml:"github_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 9929a36c4..0098b05ec 100644 --- a/internal/client/github.go +++ b/internal/client/github.go @@ -2,10 +2,12 @@ package client import ( "bytes" + "net/url" "os" "github.com/apex/log" "github.com/google/go-github/github" + "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "golang.org/x/oauth2" ) @@ -15,12 +17,21 @@ type githubClient struct { } // NewGitHub returns a github client implementation -func NewGitHub(ctx *context.Context) Client { +func NewGitHub(ctx *context.Context, repo config.Repo) Client { 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 err != nil { + // TODO: return the err here + log.Fatal("failed to parse url") + } + client.BaseURL = url + } return &githubClient{ - client: github.NewClient(oauth2.NewClient(ctx, ts)), + client: client, } } diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 954b2154a..e72fa2758 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -33,7 +33,7 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - return doRun(ctx, client.NewGitHub(ctx)) + return doRun(ctx, client.NewGitHub(ctx, ctx.Config.Brew.GitHub)) } func doRun(ctx *context.Context, client client.Client) error { diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 1d245e5e7..27500529f 100644 --- a/pipeline/release/release.go +++ b/pipeline/release/release.go @@ -23,7 +23,7 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - return doRun(ctx, client.NewGitHub(ctx)) + return doRun(ctx, client.NewGitHub(ctx, ctx.Config.Release.GitHub)) } func doRun(ctx *context.Context, client client.Client) error {