mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
github client factory
This commit is contained in:
parent
ef1bd21c8b
commit
764f23869e
16
clients/github.go
Normal file
16
clients/github.go
Normal file
@ -0,0 +1,16 @@
|
||||
package clients
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func Github(token string) *github.Client {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: token},
|
||||
)
|
||||
tc := oauth2.NewClient(context.Background(), ts)
|
||||
return github.NewClient(tc)
|
||||
}
|
@ -2,16 +2,15 @@ package brew
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
goctx "context"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/goreleaser/releaser/clients"
|
||||
"github.com/goreleaser/releaser/context"
|
||||
"github.com/goreleaser/releaser/sha256sum"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const formulae = `class {{ .Name }} < Formula
|
||||
@ -51,18 +50,9 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
if ctx.Config.Brew.Repo == "" {
|
||||
return nil
|
||||
}
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: *ctx.Token},
|
||||
)
|
||||
tc := oauth2.NewClient(goctx.Background(), ts)
|
||||
client := github.NewClient(tc)
|
||||
client := clients.Github(*ctx.Token)
|
||||
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.BinaryName+".rb")
|
||||
|
||||
owner := ctx.BrewRepo.Owner
|
||||
repo := ctx.BrewRepo.Name
|
||||
path := filepath.Join(
|
||||
ctx.Config.Brew.Folder,
|
||||
ctx.Config.BinaryName+".rb",
|
||||
)
|
||||
log.Println("Updating", path, "on", ctx.Config.Brew.Repo, "...")
|
||||
out, err := buildFormulae(ctx, client)
|
||||
if err != nil {
|
||||
@ -80,6 +70,8 @@ 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{},
|
||||
)
|
||||
|
@ -1,14 +1,13 @@
|
||||
package release
|
||||
|
||||
import (
|
||||
goctx "context"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/goreleaser/releaser/clients"
|
||||
"github.com/goreleaser/releaser/context"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@ -22,11 +21,7 @@ func (Pipe) Name() string {
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: *ctx.Token},
|
||||
)
|
||||
tc := oauth2.NewClient(goctx.Background(), ts)
|
||||
client := github.NewClient(tc)
|
||||
client := clients.Github(*ctx.Token)
|
||||
|
||||
r, err := getOrCreateRelease(client, ctx)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user