mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
e0315ff4c4
* feat: allow default branch to be used in gitlab * feat: add func to get default branch * fix: matching branch args * feat: branch customization * fix: fixing dummyclient naming * refactor: remove createbranch * feat: Adding gitlab branch customization * feat: testing for github and gitea defaultbranch * fix: remove dummy debug message * fix: removing note about gitea not being supported * feat: allow default branch to be used in gitlab * docs: links updat Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * chore: delete kodiak.yml Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: add func to get default branch * fix: matching branch args * feat: branch customization * fix: docs: Missing mattermost docs on website (#2543) * docs: update CircleCI example (#2545) * fix: fixing dummyclient naming * docs: some little fixes on the webpage (#2547) * feat: some little fixes on the webpage Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com> * Update www/docs/overrides/home.html Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * refactor: remove unused not impl error (#2540) Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * feat: add template support for homebrew tap owner (#2544) * feat: add template support for homebrew tap name refs #2544 Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * refactor: remove createbranch * feat: Adding gitlab branch customization * feat: testing for github and gitea defaultbranch * fix: remove dummy debug message * fix: removing note about gitea not being supported Co-authored-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: Engin Diri <engin.diri@mail.schwarz> Co-authored-by: Ricardo N Feliciano <FelicianoTech@gmail.com> Co-authored-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com> Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> Co-authored-by: Erik Weber <terbolous@gmail.com>
245 lines
6.0 KiB
Go
245 lines
6.0 KiB
Go
package milestone
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDefaultWithRepoConfig(t *testing.T) {
|
|
testlib.Mktmp(t)
|
|
testlib.GitInit(t)
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
|
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Milestones: []config.Milestone{
|
|
{
|
|
Repo: config.Repo{
|
|
Name: "configrepo",
|
|
Owner: "configowner",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "configrepo", ctx.Config.Milestones[0].Repo.Name)
|
|
require.Equal(t, "configowner", ctx.Config.Milestones[0].Repo.Owner)
|
|
}
|
|
|
|
func TestDefaultWithRepoRemote(t *testing.T) {
|
|
testlib.Mktmp(t)
|
|
testlib.GitInit(t)
|
|
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
|
|
|
ctx := context.New(config.Project{
|
|
Milestones: []config.Milestone{{}},
|
|
})
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "githubrepo", ctx.Config.Milestones[0].Repo.Name)
|
|
require.Equal(t, "githubowner", ctx.Config.Milestones[0].Repo.Owner)
|
|
}
|
|
|
|
func TestDefaultWithNameTemplate(t *testing.T) {
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Milestones: []config.Milestone{
|
|
{
|
|
NameTemplate: "confignametemplate",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
|
|
}
|
|
|
|
func TestDefaultWithoutGitRepo(t *testing.T) {
|
|
testlib.Mktmp(t)
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Milestones: []config.Milestone{{}},
|
|
},
|
|
}
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
|
}
|
|
|
|
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
|
testlib.Mktmp(t)
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Milestones: []config.Milestone{{}},
|
|
},
|
|
}
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
testlib.GitInit(t)
|
|
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
|
}
|
|
|
|
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
|
testlib.Mktmp(t)
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Milestones: []config.Milestone{{}},
|
|
},
|
|
}
|
|
ctx.TokenType = context.TokenTypeGitHub
|
|
ctx.Snapshot = true
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
|
}
|
|
|
|
func TestDefaultWithoutNameTemplate(t *testing.T) {
|
|
ctx := &context.Context{
|
|
Config: config.Project{
|
|
Milestones: []config.Milestone{{}},
|
|
},
|
|
}
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
require.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
|
|
}
|
|
|
|
func TestString(t *testing.T) {
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
}
|
|
|
|
func TestPublishCloseDisabled(t *testing.T) {
|
|
ctx := context.New(config.Project{
|
|
Milestones: []config.Milestone{
|
|
{
|
|
Close: false,
|
|
},
|
|
},
|
|
})
|
|
client := &DummyClient{}
|
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
|
require.Equal(t, "", client.ClosedMilestone)
|
|
}
|
|
|
|
func TestPublishCloseEnabled(t *testing.T) {
|
|
ctx := context.New(config.Project{
|
|
Milestones: []config.Milestone{
|
|
{
|
|
Close: true,
|
|
NameTemplate: defaultNameTemplate,
|
|
Repo: config.Repo{
|
|
Name: "configrepo",
|
|
Owner: "configowner",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
|
client := &DummyClient{}
|
|
require.NoError(t, doPublish(ctx, client))
|
|
require.Equal(t, "v1.0.0", client.ClosedMilestone)
|
|
}
|
|
|
|
func TestPublishCloseError(t *testing.T) {
|
|
config := config.Project{
|
|
Milestones: []config.Milestone{
|
|
{
|
|
Close: true,
|
|
NameTemplate: defaultNameTemplate,
|
|
Repo: config.Repo{
|
|
Name: "configrepo",
|
|
Owner: "configowner",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
ctx := context.New(config)
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
|
client := &DummyClient{
|
|
FailToCloseMilestone: true,
|
|
}
|
|
require.NoError(t, doPublish(ctx, client))
|
|
require.Equal(t, "", client.ClosedMilestone)
|
|
}
|
|
|
|
func TestPublishCloseFailOnError(t *testing.T) {
|
|
config := config.Project{
|
|
Milestones: []config.Milestone{
|
|
{
|
|
Close: true,
|
|
FailOnError: true,
|
|
NameTemplate: defaultNameTemplate,
|
|
Repo: config.Repo{
|
|
Name: "configrepo",
|
|
Owner: "configowner",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
ctx := context.New(config)
|
|
ctx.Git.CurrentTag = "v1.0.0"
|
|
client := &DummyClient{
|
|
FailToCloseMilestone: true,
|
|
}
|
|
require.Error(t, doPublish(ctx, client))
|
|
require.Equal(t, "", client.ClosedMilestone)
|
|
}
|
|
|
|
func TestSkip(t *testing.T) {
|
|
t.Run("skip", func(t *testing.T) {
|
|
require.True(t, Pipe{}.Skip(context.New(config.Project{})))
|
|
})
|
|
|
|
t.Run("dont skip", func(t *testing.T) {
|
|
ctx := context.New(config.Project{
|
|
Milestones: []config.Milestone{
|
|
{},
|
|
},
|
|
})
|
|
require.False(t, Pipe{}.Skip(ctx))
|
|
})
|
|
}
|
|
|
|
type DummyClient struct {
|
|
ClosedMilestone string
|
|
FailToCloseMilestone bool
|
|
}
|
|
|
|
func (c *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
|
|
if c.FailToCloseMilestone {
|
|
return errors.New("milestone failed")
|
|
}
|
|
|
|
c.ClosedMilestone = title
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *DummyClient) CreateRelease(ctx *context.Context, body string) (string, error) {
|
|
return "", nil
|
|
}
|
|
|
|
func (c *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
|
|
return "", nil
|
|
}
|
|
|
|
func (c *DummyClient) GetDefaultBranch(ctx *context.Context, repo client.Repo) (string, error) {
|
|
return "", errors.New("DummyClient does not yet implement GetDefaultBranch")
|
|
}
|
|
|
|
func (c *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) error {
|
|
return nil
|
|
}
|
|
|
|
func (c *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) error {
|
|
return nil
|
|
}
|