1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/client/client.go
Carlos Alexandro Becker 61bead8989
feat: improve output and pipe skipping (#2480)
* refactor: improve middleware

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: upload tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: twitter tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: source tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: snapshot tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: improved some tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: snapcraft skip

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip slack

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip sign

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip scoop

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip reddit

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip discord

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip publish

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip nfpm

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip milestone

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip custompublishers

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip checksums

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip changelog

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip brew

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip blob

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip before

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip artifactory

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip announce

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip defaults

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: cmds

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip docker

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* chore: todo

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: go.mod

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip release

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: remove old skip pipe errors

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip teams

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip brew

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix/test: skip smtp

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: lint issues

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip docker

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip brew and scoop

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip docker

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: skip http/artifactory

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: increase coverage

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-18 10:21:29 -03:00

116 lines
2.9 KiB
Go

// Package client contains the client implementations for several providers.
package client
import (
"errors"
"fmt"
"os"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Info of the repository.
type Info struct {
Description string
Homepage string
URL string
}
type Repo struct {
Owner string
Name string
}
func (r Repo) String() string {
if r.Owner == "" && r.Name == "" {
return ""
}
return r.Owner + "/" + r.Name
}
// Client interface.
type Client interface {
CloseMilestone(ctx *context.Context, repo Repo, title string) (err error)
CreateRelease(ctx *context.Context, body string) (releaseID string, err error)
ReleaseURLTemplate(ctx *context.Context) (string, error)
CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo Repo, content []byte, path, message string) (err error)
Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error)
}
// New creates a new client depending on the token type.
func New(ctx *context.Context) (Client, error) {
log.WithField("type", ctx.TokenType).Debug("token type")
if ctx.TokenType == context.TokenTypeGitHub {
return NewGitHub(ctx, ctx.Token)
}
if ctx.TokenType == context.TokenTypeGitLab {
return NewGitLab(ctx, ctx.Token)
}
if ctx.TokenType == context.TokenTypeGitea {
return NewGitea(ctx, ctx.Token)
}
return nil, nil
}
func newWithToken(ctx *context.Context, token string) (Client, error) {
if ctx.TokenType == context.TokenTypeGitHub {
return NewGitHub(ctx, token)
}
if ctx.TokenType == context.TokenTypeGitLab {
return NewGitLab(ctx, token)
}
if ctx.TokenType == context.TokenTypeGitea {
return NewGitea(ctx, token)
}
return nil, nil
}
func NewIfToken(ctx *context.Context, cli Client, token string) (Client, error) {
if token == "" {
return cli, nil
}
token, err := tmpl.New(ctx).ApplySingleEnvOnly(token)
if err != nil {
return nil, err
}
log.Debug("using custom token")
return newWithToken(ctx, token)
}
// ErrNoMilestoneFound is an error when no milestone is found.
type ErrNoMilestoneFound struct {
Title string
}
func (e ErrNoMilestoneFound) Error() string {
return fmt.Sprintf("no milestone found: %s", e.Title)
}
// RetriableError is an error that will cause the action to be retried.
type RetriableError struct {
Err error
}
func (e RetriableError) Error() string {
return e.Err.Error()
}
// NotImplementedError happens when trying to use something a client does not
// implement.
type NotImplementedError struct {
TokenType context.TokenType
}
func (e NotImplementedError) Error() string {
return fmt.Sprintf("not implemented for %s", e.TokenType)
}
// IsNotImplementedErr returns true if given error is a NotImplementedError.
func IsNotImplementedErr(err error) bool {
return errors.As(err, &NotImplementedError{})
}