1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00

Merge pull request #127 from goreleaser/bump-github

Bump GitHub
This commit is contained in:
Carlos Alexandro Becker 2017-02-26 12:55:14 -03:00 committed by GitHub
commit b0319c5604
6 changed files with 40 additions and 29 deletions

View File

@ -1,17 +1,15 @@
package clients
import (
"context"
"github.com/google/go-github/github"
"github.com/goreleaser/goreleaser/context"
"golang.org/x/oauth2"
)
// GitHub client for the given token
func GitHub(token string) *github.Client {
func GitHub(ctx *context.Context) *github.Client {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
&oauth2.Token{AccessToken: ctx.Token},
)
tc := oauth2.NewClient(context.Background(), ts)
return github.NewClient(tc)
return github.NewClient(oauth2.NewClient(ctx, ts))
}

View File

@ -1,6 +1,10 @@
package context
import "github.com/goreleaser/goreleaser/config"
import (
ctx "context"
"github.com/goreleaser/goreleaser/config"
)
// GitInfo includes tags and diffs used in some point
type GitInfo struct {
@ -16,6 +20,7 @@ type Repo struct {
// Context carries along some data through the pipes
type Context struct {
ctx.Context
Config config.Project
Token string
Git GitInfo
@ -28,6 +33,7 @@ type Context struct {
// New context
func New(config config.Project) *Context {
return &Context{
Context: ctx.Background(),
Config: config,
Archives: map[string]string{},
}

18
glide.lock generated
View File

@ -1,34 +1,34 @@
hash: 4ae97a8ee2374ccb3e4730069be4fe7cd9f222861add5633ebf82cbbee99025e
updated: 2017-01-14T20:01:15.582114617-02:00
hash: 2c942a7561b41834e42ce185a40875d4982f81650fb15ae9c5388ee125b14f2d
updated: 2017-02-23T16:01:12.607119087-03:00
imports:
- name: github.com/golang/protobuf
version: 8ee79997227bf9b34611aee7946ae64735e6fd93
version: 69b215d01a5606c843240eab4937eab3acee6530
subpackages:
- proto
- name: github.com/google/go-github
version: 90861904aa86352a956f91ba0664df93a3547584
version: b59d3a6479bd00374a1523ad032da4621d9dd84a
subpackages:
- github
- name: github.com/google/go-querystring
version: 9235644dd9e52eeae6fa48efd539fdc351a0af53
version: 53e6ce116135b80d037921a7fdd5138cf32d7a8a
subpackages:
- query
- name: github.com/urfave/cli
version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6
- name: golang.org/x/net
version: 6d3beaea10370160dea67f5c9327ed791afd5389
version: 6b27048ae5e6ad1ef927e72e437531493de612fe
subpackages:
- context
- name: golang.org/x/oauth2
version: 314dd2c0bf3ebd592ec0d20847d27e79d0dbe8dd
version: b9780ec78894ab900c062d58ee3076cd9b2a4501
subpackages:
- internal
- name: golang.org/x/sync
version: 316e794f7b5e3df4e95175a45a5fb8b12f85cb4f
version: 86ddc858aa39d0f6cccccd733e482ddc52b852e9
subpackages:
- errgroup
- name: google.golang.org/appengine
version: 08a149cfaee099e6ce4be01c0113a78c85ee1dee
version: 3a452f9e00122ead39586d68ffdb9c6e1326af3c
subpackages:
- internal
- internal/base

View File

@ -3,13 +3,13 @@ import:
- package: github.com/google/go-github
subpackages:
- github
- package: github.com/urfave/cli
version: ~1.19.1
- package: golang.org/x/oauth2
- package: gopkg.in/yaml.v1
- package: golang.org/x/sync
subpackages:
- errgroup
- package: github.com/urfave/cli
version: ~1.19.1
- package: gopkg.in/yaml.v1
testImport:
- package: github.com/stretchr/testify
version: ~1.1.4

View File

@ -88,7 +88,7 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Brew.Repo == "" {
return nil
}
client := clients.GitHub(ctx.Token)
client := clients.GitHub(ctx)
path := filepath.Join(
ctx.Config.Brew.Folder, ctx.Config.Build.BinaryName+".rb",
)
@ -113,14 +113,16 @@ func (Pipe) Run(ctx *context.Context) error {
owner := ctx.BrewRepo.Owner
repo := ctx.BrewRepo.Name
file, _, res, err := client.Repositories.GetContents(
owner, repo, path, &github.RepositoryContentGetOptions{},
ctx, owner, repo, path, &github.RepositoryContentGetOptions{},
)
if err != nil && res.StatusCode == 404 {
_, _, err = client.Repositories.CreateFile(owner, repo, path, options)
_, _, err = client.Repositories.CreateFile(
ctx, owner, repo, path, options,
)
return err
}
options.SHA = file.SHA
_, _, err = client.Repositories.UpdateFile(owner, repo, path, options)
_, _, err = client.Repositories.UpdateFile(ctx, owner, repo, path, options)
return err
}
@ -142,10 +144,14 @@ func doBuildFormula(data templateData) (bytes.Buffer, error) {
return out, err
}
func dataFor(ctx *context.Context, client *github.Client) (result templateData, err error) {
func dataFor(
ctx *context.Context, client *github.Client,
) (result templateData, err error) {
var homepage string
var description string
rep, _, err := client.Repositories.Get(ctx.ReleaseRepo.Owner, ctx.ReleaseRepo.Name)
rep, _, err := client.Repositories.Get(
ctx, ctx.ReleaseRepo.Owner, ctx.ReleaseRepo.Name,
)
if err != nil {
return
}

View File

@ -22,7 +22,7 @@ func (Pipe) Description() string {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
client := clients.GitHub(ctx.Token)
client := clients.GitHub(ctx)
r, err := getOrCreateRelease(client, ctx)
if err != nil {
@ -52,14 +52,14 @@ func getOrCreateRelease(client *github.Client, ctx *context.Context) (*github.Re
TagName: github.String(ctx.Git.CurrentTag),
Body: github.String(description(ctx.Git.Diff)),
}
r, _, err := client.Repositories.GetReleaseByTag(owner, repo, ctx.Git.CurrentTag)
r, _, err := client.Repositories.GetReleaseByTag(ctx, owner, repo, ctx.Git.CurrentTag)
if err != nil {
log.Println("Creating release", ctx.Git.CurrentTag, "on", ctx.Config.Release.Repo)
r, _, err = client.Repositories.CreateRelease(owner, repo, data)
r, _, err = client.Repositories.CreateRelease(ctx, owner, repo, data)
return r, err
}
log.Println("Updating existing release", ctx.Git.CurrentTag, "on", ctx.Config.Release.Repo)
r, _, err = client.Repositories.EditRelease(owner, repo, *r.ID, data)
r, _, err = client.Repositories.EditRelease(ctx, owner, repo, *r.ID, data)
return r, err
}
@ -93,6 +93,7 @@ func upload(ctx *context.Context, client *github.Client, releaseID int, archive,
defer func() { _ = file.Close() }()
log.Println("Uploading", file.Name())
_, _, err = client.Repositories.UploadReleaseAsset(
ctx,
ctx.ReleaseRepo.Owner,
ctx.ReleaseRepo.Name,
releaseID,