diff --git a/.gitignore b/.gitignore index 0cc6ddfa7..5985e6dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dist/ vendor coverage.txt goreleaser +.idea/ diff --git a/config/config.go b/config/config.go index 995657c37..18f1cae64 100644 --- a/config/config.go +++ b/config/config.go @@ -15,8 +15,11 @@ import ( // Repo represents any kind of repo (github, gitlab, etc) type Repo struct { - Owner string `yaml:",omitempty"` - Name string `yaml:",omitempty"` + Owner string `yaml:",omitempty"` + Name string `yaml:",omitempty"` + ApiURL string `yaml:"api_url,omitempty"` + UploadsURL string `yaml:"uploads_url,omitempty"` + DownloadURL string `yaml:"download_url,omitempty"` // Capture all undefined fields and should be empty after loading XXX map[string]interface{} `yaml:",inline"` diff --git a/docs/115-release.md b/docs/115-release.md index 10ae7e288..09896b6a9 100644 --- a/docs/115-release.md +++ b/docs/115-release.md @@ -16,6 +16,11 @@ release: github: owner: user name: repo + # endpoint urls for enterprise github. + # Default is github.com. + api_url: github api endpoint + uploads_url: github file uploads url + download_url github download url # If set to true, will not auto-publish the release. # Default is false diff --git a/docs/120-homebrew.md b/docs/120-homebrew.md index 183cd3dca..d7f8770eb 100644 --- a/docs/120-homebrew.md +++ b/docs/120-homebrew.md @@ -19,6 +19,11 @@ brew: github: owner: user name: homebrew-tap + # endpoint urls for enterprise github. + # Default is github.com. + api_url: github api endpoint + uploads_url: github file uploads url + download_url github download url # Folder inside the repository to put the formula. # Default is the root folder. diff --git a/internal/client/github.go b/internal/client/github.go index 9929a36c4..c1bff213c 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,13 +17,27 @@ type githubClient struct { } // NewGitHub returns a github client implementation -func NewGitHub(ctx *context.Context) Client { +func NewGitHub(ctx *context.Context, repo config.Repo) (Client, error) { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: ctx.Token}, ) - return &githubClient{ - client: github.NewClient(oauth2.NewClient(ctx, ts)), + client := github.NewClient(oauth2.NewClient(ctx, ts)) + if repo.ApiURL != "" { + url, err := url.Parse(repo.ApiURL) + if err != nil { + return &githubClient{}, err + } + client.BaseURL = url } + if repo.UploadsURL != "" { + url, err := url.Parse(repo.UploadsURL) + if err != nil { + return &githubClient{}, err + } + client.UploadURL = url + } + + return &githubClient{client}, nil } func (c *githubClient) CreateFile( diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 954b2154a..91d26885d 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -33,7 +33,12 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - return doRun(ctx, client.NewGitHub(ctx)) + client, err := client.NewGitHub(ctx, ctx.Config.Brew.GitHub) + if err != nil { + return err + } + return doRun(ctx, client) + } func doRun(ctx *context.Context, client client.Client) error { diff --git a/pipeline/brew/template.go b/pipeline/brew/template.go index 87e5b74de..9c50b5a74 100644 --- a/pipeline/brew/template.go +++ b/pipeline/brew/template.go @@ -22,7 +22,13 @@ type templateData struct { const formulaTemplate = `class {{ .Name }} < Formula desc "{{ .Desc }}" homepage "{{ .Homepage }}" - url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + + {{ if .Repo.DownloadURL }} + url "{{ .Repo.DownloadURL }}{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + {{ else }} + url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + {{ end }} + version "{{ .Version }}" sha256 "{{ .SHA256 }}" diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 1d245e5e7..542c348c0 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)) + client, err := client.NewGitHub(ctx, ctx.Config.Release.GitHub) + if err != nil { + return err + } + return doRun(ctx, client) } func doRun(ctx *context.Context, client client.Client) error {