mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
github enterprise config update
This commit is contained in:
parent
9ddf723c4e
commit
fd0e57ee4e
@ -13,13 +13,17 @@ import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// GitHubURLs holds the URLs to be used when using github enterprise
|
||||
type GitHubURLs struct {
|
||||
API string `yaml:"api,omitempty"`
|
||||
Upload string `yaml:"upload,omitempty"`
|
||||
Download string `yaml:"download,omitempty"`
|
||||
}
|
||||
|
||||
// Repo represents any kind of repo (github, gitlab, etc)
|
||||
type Repo struct {
|
||||
Owner string `yaml:",omitempty"`
|
||||
Name string `yaml:",omitempty"`
|
||||
APIURL string `yaml:"api_url,omitempty"`
|
||||
UploadsURL string `yaml:"uploads_url,omitempty"`
|
||||
DownloadsURL string `yaml:"downloads_url,omitempty"`
|
||||
Owner string `yaml:",omitempty"`
|
||||
Name string `yaml:",omitempty"`
|
||||
|
||||
// Capture all undefined fields and should be empty after loading
|
||||
XXX map[string]interface{} `yaml:",inline"`
|
||||
@ -193,6 +197,9 @@ type Project struct {
|
||||
// this is a hack ¯\_(ツ)_/¯
|
||||
SingleBuild Build `yaml:"build,omitempty"`
|
||||
|
||||
// should be set if using github enterprise
|
||||
GitHubURLs GitHubURLs `yaml:"github_urls,omitempty"`
|
||||
|
||||
// test only property indicating the path to the dist folder
|
||||
Dist string `yaml:"-"`
|
||||
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
@ -17,24 +16,22 @@ type githubClient struct {
|
||||
}
|
||||
|
||||
// NewGitHub returns a github client implementation
|
||||
func NewGitHub(ctx *context.Context, repo config.Repo) (Client, error) {
|
||||
func NewGitHub(ctx *context.Context) (Client, error) {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: ctx.Token},
|
||||
)
|
||||
client := github.NewClient(oauth2.NewClient(ctx, ts))
|
||||
if repo.APIURL != "" {
|
||||
url, err := url.Parse(repo.APIURL)
|
||||
if ctx.Config.GitHubURLs.API != "" {
|
||||
api, err := url.Parse(ctx.Config.GitHubURLs.API)
|
||||
if err != nil {
|
||||
return &githubClient{}, err
|
||||
}
|
||||
client.BaseURL = url
|
||||
}
|
||||
if repo.UploadsURL != "" {
|
||||
url, err := url.Parse(repo.UploadsURL)
|
||||
upload, err := url.Parse(ctx.Config.GitHubURLs.Upload)
|
||||
if err != nil {
|
||||
return &githubClient{}, err
|
||||
}
|
||||
client.UploadURL = url
|
||||
client.BaseURL = api
|
||||
client.UploadURL = upload
|
||||
}
|
||||
|
||||
return &githubClient{client}, nil
|
||||
|
@ -97,8 +97,13 @@ func dataFor(ctx *context.Context, client client.Client, folder string) (result
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var url = "https://github.com"
|
||||
if ctx.Config.GitHubURLs.Download != "" {
|
||||
url = ctx.Config.GitHubURLs.Download
|
||||
}
|
||||
return templateData{
|
||||
Name: formulaNameFor(ctx.Config.ProjectName),
|
||||
DownloadURL: url,
|
||||
Desc: ctx.Config.Brew.Description,
|
||||
Homepage: ctx.Config.Brew.Homepage,
|
||||
Repo: ctx.Config.Release.GitHub,
|
||||
|
@ -6,6 +6,7 @@ type templateData struct {
|
||||
Name string
|
||||
Desc string
|
||||
Homepage string
|
||||
DownloadURL string
|
||||
Repo config.Repo // FIXME: will not work for anything but github right now.
|
||||
Tag string
|
||||
Version string
|
||||
@ -22,11 +23,7 @@ type templateData struct {
|
||||
const formulaTemplate = `class {{ .Name }} < Formula
|
||||
desc "{{ .Desc }}"
|
||||
homepage "{{ .Homepage }}"
|
||||
{{ if .Repo.DownloadsURL }}
|
||||
url "{{ .Repo.DownloadsURL }}{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
|
||||
{{- else -}}
|
||||
url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
|
||||
{{ end -}}
|
||||
url "{{ .DownloadsURL }}/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
|
||||
|
||||
version "{{ .Version }}"
|
||||
sha256 "{{ .SHA256 }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user