mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
support github enterprise
This commit is contained in:
parent
17e9e6ca0e
commit
ca48aa430f
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ dist/
|
||||
vendor
|
||||
coverage.txt
|
||||
goreleaser
|
||||
.idea/
|
||||
|
@ -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"`
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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(
|
||||
|
@ -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 {
|
||||
|
@ -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 }}"
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user