1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

support github enterprise

This commit is contained in:
Stephan Klevenz 2017-09-23 19:42:07 +02:00
parent 17e9e6ca0e
commit ca48aa430f
8 changed files with 53 additions and 8 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ dist/
vendor vendor
coverage.txt coverage.txt
goreleaser goreleaser
.idea/

View File

@ -17,6 +17,9 @@ import (
type Repo struct { type Repo struct {
Owner string `yaml:",omitempty"` Owner string `yaml:",omitempty"`
Name 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 // Capture all undefined fields and should be empty after loading
XXX map[string]interface{} `yaml:",inline"` XXX map[string]interface{} `yaml:",inline"`

View File

@ -16,6 +16,11 @@ release:
github: github:
owner: user owner: user
name: repo 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. # If set to true, will not auto-publish the release.
# Default is false # Default is false

View File

@ -19,6 +19,11 @@ brew:
github: github:
owner: user owner: user
name: homebrew-tap 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. # Folder inside the repository to put the formula.
# Default is the root folder. # Default is the root folder.

View File

@ -2,10 +2,12 @@ package client
import ( import (
"bytes" "bytes"
"net/url"
"os" "os"
"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"
) )
@ -15,13 +17,27 @@ type githubClient struct {
} }
// NewGitHub returns a github client implementation // 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( ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ctx.Token}, &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( func (c *githubClient) CreateFile(

View File

@ -33,7 +33,12 @@ 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)) 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 { func doRun(ctx *context.Context, client client.Client) error {

View File

@ -22,7 +22,13 @@ type templateData struct {
const formulaTemplate = `class {{ .Name }} < Formula const formulaTemplate = `class {{ .Name }} < Formula
desc "{{ .Desc }}" desc "{{ .Desc }}"
homepage "{{ .Homepage }}" homepage "{{ .Homepage }}"
{{ 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 }}" url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
{{ end }}
version "{{ .Version }}" version "{{ .Version }}"
sha256 "{{ .SHA256 }}" sha256 "{{ .SHA256 }}"

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)) 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 { func doRun(ctx *context.Context, client client.Client) error {