From cf4e2d05db76ec65432b6cfa28075a237e28e73b Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sat, 13 May 2017 18:06:15 -0300 Subject: [PATCH] moving client to internal folder --- client/client.go | 23 ------- client/github.go | 122 ------------------------------------ pipeline/brew/brew.go | 2 +- pipeline/release/release.go | 2 +- 4 files changed, 2 insertions(+), 147 deletions(-) delete mode 100644 client/client.go delete mode 100644 client/github.go diff --git a/client/client.go b/client/client.go deleted file mode 100644 index 421d37546..000000000 --- a/client/client.go +++ /dev/null @@ -1,23 +0,0 @@ -// Package client contains the client implementations for several providers. -package client - -import ( - "bytes" - "os" - - "github.com/goreleaser/goreleaser/context" -) - -// Info of the repository -type Info struct { - Description string - Homepage string - URL string -} - -// Client interface -type Client interface { - CreateRelease(ctx *context.Context, body string) (releaseID int, err error) - CreateFile(ctx *context.Context, content bytes.Buffer, path string) (err error) - Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error) -} diff --git a/client/github.go b/client/github.go deleted file mode 100644 index ce370cc3e..000000000 --- a/client/github.go +++ /dev/null @@ -1,122 +0,0 @@ -package client - -import ( - "bytes" - "log" - "os" - - "github.com/google/go-github/github" - "github.com/goreleaser/goreleaser/context" - "golang.org/x/oauth2" -) - -type githubClient struct { - client *github.Client -} - -// NewGitHub returns a github client implementation -func NewGitHub(ctx *context.Context) Client { - ts := oauth2.StaticTokenSource( - &oauth2.Token{AccessToken: ctx.Token}, - ) - return &githubClient{ - client: github.NewClient(oauth2.NewClient(ctx, ts)), - } -} - -func (c *githubClient) CreateFile( - ctx *context.Context, - content bytes.Buffer, - path string, -) (err error) { - options := &github.RepositoryContentFileOptions{ - Committer: &github.CommitAuthor{ - Name: github.String("goreleaserbot"), - Email: github.String("bot@goreleaser"), - }, - Content: content.Bytes(), - Message: github.String( - ctx.Config.Build.Binary + " version " + ctx.Git.CurrentTag, - ), - } - - file, _, res, err := c.client.Repositories.GetContents( - ctx, - ctx.Config.Brew.GitHub.Owner, - ctx.Config.Brew.GitHub.Name, - path, - &github.RepositoryContentGetOptions{}, - ) - if err != nil && res.StatusCode == 404 { - _, _, err = c.client.Repositories.CreateFile( - ctx, - ctx.Config.Brew.GitHub.Owner, - ctx.Config.Brew.GitHub.Name, - path, - options, - ) - return - } - options.SHA = file.SHA - _, _, err = c.client.Repositories.UpdateFile( - ctx, - ctx.Config.Brew.GitHub.Owner, - ctx.Config.Brew.GitHub.Name, - path, - options, - ) - return -} - -func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) { - var release *github.RepositoryRelease - var data = &github.RepositoryRelease{ - Name: github.String(ctx.Git.CurrentTag), - TagName: github.String(ctx.Git.CurrentTag), - Body: github.String(body), - Draft: github.Bool(ctx.Config.Release.Draft), - } - release, _, err = c.client.Repositories.GetReleaseByTag( - ctx, - ctx.Config.Release.GitHub.Owner, - ctx.Config.Release.GitHub.Name, - ctx.Git.CurrentTag, - ) - if err != nil { - release, _, err = c.client.Repositories.CreateRelease( - ctx, - ctx.Config.Release.GitHub.Owner, - ctx.Config.Release.GitHub.Name, - data, - ) - } else { - release, _, err = c.client.Repositories.EditRelease( - ctx, - ctx.Config.Release.GitHub.Owner, - ctx.Config.Release.GitHub.Name, - release.GetID(), - data, - ) - } - log.Printf("Release updated: %v\n", release.GetHTMLURL()) - return release.GetID(), err -} - -func (c *githubClient) Upload( - ctx *context.Context, - releaseID int, - name string, - file *os.File, -) (err error) { - _, _, err = c.client.Repositories.UploadReleaseAsset( - ctx, - ctx.Config.Release.GitHub.Owner, - ctx.Config.Release.GitHub.Name, - releaseID, - &github.UploadOptions{ - Name: name, - }, - file, - ) - return -} diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 86863d7e9..e6947cdd4 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -11,9 +11,9 @@ import ( "text/template" "github.com/goreleaser/goreleaser/checksum" - "github.com/goreleaser/goreleaser/client" "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" + "github.com/goreleaser/goreleaser/internal/client" ) // ErrNoDarwin64Build when there is no build for darwin_amd64 (goos doesn't diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 0799c3186..06f011749 100644 --- a/pipeline/release/release.go +++ b/pipeline/release/release.go @@ -7,8 +7,8 @@ import ( "os" "path/filepath" - "github.com/goreleaser/goreleaser/client" "github.com/goreleaser/goreleaser/context" + "github.com/goreleaser/goreleaser/internal/client" "golang.org/x/sync/errgroup" )