refactor: move git to package

This commit is contained in:
Julian Tölle 2024-08-30 22:47:50 +02:00
parent 44184a77f9
commit 5765b48703
10 changed files with 114 additions and 102 deletions

View file

@ -4,6 +4,8 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/apricote/releaser-pleaser/internal/git"
) )
func ptr[T any](input T) *T { func ptr[T any](input T) *T {
@ -39,7 +41,7 @@ func Test_NewChangelogEntry(t *testing.T) {
args: args{ args: args{
analyzedCommits: []AnalyzedCommit{ analyzedCommits: []AnalyzedCommit{
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "feat", Type: "feat",
Description: "Foobar!", Description: "Foobar!",
}, },
@ -55,7 +57,7 @@ func Test_NewChangelogEntry(t *testing.T) {
args: args{ args: args{
analyzedCommits: []AnalyzedCommit{ analyzedCommits: []AnalyzedCommit{
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "fix", Type: "fix",
Description: "Foobar!", Description: "Foobar!",
}, },
@ -71,23 +73,23 @@ func Test_NewChangelogEntry(t *testing.T) {
args: args{ args: args{
analyzedCommits: []AnalyzedCommit{ analyzedCommits: []AnalyzedCommit{
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "feat", Type: "feat",
Description: "Blabla!", Description: "Blabla!",
}, },
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "feat", Type: "feat",
Description: "So awesome!", Description: "So awesome!",
Scope: ptr("awesome"), Scope: ptr("awesome"),
}, },
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "fix", Type: "fix",
Description: "Foobar!", Description: "Foobar!",
}, },
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "fix", Type: "fix",
Description: "So sad!", Description: "So sad!",
Scope: ptr("sad"), Scope: ptr("sad"),
@ -114,7 +116,7 @@ func Test_NewChangelogEntry(t *testing.T) {
args: args{ args: args{
analyzedCommits: []AnalyzedCommit{ analyzedCommits: []AnalyzedCommit{
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "fix", Type: "fix",
Description: "Foobar!", Description: "Foobar!",
}, },
@ -137,7 +139,7 @@ func Test_NewChangelogEntry(t *testing.T) {
args: args{ args: args{
analyzedCommits: []AnalyzedCommit{ analyzedCommits: []AnalyzedCommit{
{ {
Commit: Commit{}, Commit: git.Commit{},
Type: "fix", Type: "fix",
Description: "Foobar!", Description: "Foobar!",
}, },

View file

@ -5,23 +5,12 @@ import (
"github.com/leodido/go-conventionalcommits" "github.com/leodido/go-conventionalcommits"
"github.com/leodido/go-conventionalcommits/parser" "github.com/leodido/go-conventionalcommits/parser"
"github.com/apricote/releaser-pleaser/internal/git"
) )
type Commit struct {
Hash string
Message string
PullRequest *PullRequest
}
type PullRequest struct {
ID int
Title string
Description string
}
type AnalyzedCommit struct { type AnalyzedCommit struct {
Commit git.Commit
Type string Type string
Description string Description string
Scope *string Scope *string
@ -29,7 +18,7 @@ type AnalyzedCommit struct {
} }
type CommitParser interface { type CommitParser interface {
Analyze(commits []Commit) ([]AnalyzedCommit, error) Analyze(commits []git.Commit) ([]AnalyzedCommit, error)
} }
type ConventionalCommitsParser struct { type ConventionalCommitsParser struct {
@ -47,7 +36,7 @@ func NewConventionalCommitsParser() *ConventionalCommitsParser {
} }
} }
func (c *ConventionalCommitsParser) Analyze(commits []Commit) ([]AnalyzedCommit, error) { func (c *ConventionalCommitsParser) Analyze(commits []git.Commit) ([]AnalyzedCommit, error) {
analyzedCommits := make([]AnalyzedCommit, 0, len(commits)) analyzedCommits := make([]AnalyzedCommit, 0, len(commits))
for _, commit := range commits { for _, commit := range commits {

View file

@ -4,24 +4,26 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/apricote/releaser-pleaser/internal/git"
) )
func TestAnalyzeCommits(t *testing.T) { func TestAnalyzeCommits(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
commits []Commit commits []git.Commit
expectedCommits []AnalyzedCommit expectedCommits []AnalyzedCommit
wantErr assert.ErrorAssertionFunc wantErr assert.ErrorAssertionFunc
}{ }{
{ {
name: "empty commits", name: "empty commits",
commits: []Commit{}, commits: []git.Commit{},
expectedCommits: []AnalyzedCommit{}, expectedCommits: []AnalyzedCommit{},
wantErr: assert.NoError, wantErr: assert.NoError,
}, },
{ {
name: "malformed commit message", name: "malformed commit message",
commits: []Commit{ commits: []git.Commit{
{ {
Message: "aksdjaklsdjka", Message: "aksdjaklsdjka",
}, },
@ -31,7 +33,7 @@ func TestAnalyzeCommits(t *testing.T) {
}, },
{ {
name: "drops unreleasable", name: "drops unreleasable",
commits: []Commit{ commits: []git.Commit{
{ {
Message: "chore: foobar", Message: "chore: foobar",
}, },
@ -41,7 +43,7 @@ func TestAnalyzeCommits(t *testing.T) {
}, },
{ {
name: "highest bump (patch)", name: "highest bump (patch)",
commits: []Commit{ commits: []git.Commit{
{ {
Message: "chore: foobar", Message: "chore: foobar",
}, },
@ -51,7 +53,7 @@ func TestAnalyzeCommits(t *testing.T) {
}, },
expectedCommits: []AnalyzedCommit{ expectedCommits: []AnalyzedCommit{
{ {
Commit: Commit{Message: "fix: blabla"}, Commit: git.Commit{Message: "fix: blabla"},
Type: "fix", Type: "fix",
Description: "blabla", Description: "blabla",
}, },
@ -60,7 +62,7 @@ func TestAnalyzeCommits(t *testing.T) {
}, },
{ {
name: "highest bump (minor)", name: "highest bump (minor)",
commits: []Commit{ commits: []git.Commit{
{ {
Message: "fix: blabla", Message: "fix: blabla",
}, },
@ -70,12 +72,12 @@ func TestAnalyzeCommits(t *testing.T) {
}, },
expectedCommits: []AnalyzedCommit{ expectedCommits: []AnalyzedCommit{
{ {
Commit: Commit{Message: "fix: blabla"}, Commit: git.Commit{Message: "fix: blabla"},
Type: "fix", Type: "fix",
Description: "blabla", Description: "blabla",
}, },
{ {
Commit: Commit{Message: "feat: foobar"}, Commit: git.Commit{Message: "feat: foobar"},
Type: "feat", Type: "feat",
Description: "foobar", Description: "foobar",
}, },
@ -85,7 +87,7 @@ func TestAnalyzeCommits(t *testing.T) {
{ {
name: "highest bump (major)", name: "highest bump (major)",
commits: []Commit{ commits: []git.Commit{
{ {
Message: "fix: blabla", Message: "fix: blabla",
}, },
@ -95,12 +97,12 @@ func TestAnalyzeCommits(t *testing.T) {
}, },
expectedCommits: []AnalyzedCommit{ expectedCommits: []AnalyzedCommit{
{ {
Commit: Commit{Message: "fix: blabla"}, Commit: git.Commit{Message: "fix: blabla"},
Type: "fix", Type: "fix",
Description: "blabla", Description: "blabla",
}, },
{ {
Commit: Commit{Message: "feat!: foobar"}, Commit: git.Commit{Message: "feat!: foobar"},
Type: "feat", Type: "feat",
Description: "foobar", Description: "foobar",
BreakingChange: true, BreakingChange: true,

View file

@ -13,6 +13,8 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport" "github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/google/go-github/v63/github" "github.com/google/go-github/v63/github"
"github.com/apricote/releaser-pleaser/internal/git"
) )
const ( const (
@ -38,7 +40,7 @@ type Forge interface {
// CommitsSince returns all commits to main branch after the Tag. The tag can be `nil`, in which case this // CommitsSince returns all commits to main branch after the Tag. The tag can be `nil`, in which case this
// function should return all commits. // function should return all commits.
CommitsSince(context.Context, *Tag) ([]Commit, error) CommitsSince(context.Context, *git.Tag) ([]git.Commit, error)
// EnsureLabelsExist verifies that all desired labels are available on the repository. If labels are missing, they // EnsureLabelsExist verifies that all desired labels are available on the repository. If labels are missing, they
// are created them. // are created them.
@ -68,7 +70,7 @@ type Forge interface {
PendingReleases(context.Context, Label) ([]*ReleasePullRequest, error) PendingReleases(context.Context, Label) ([]*ReleasePullRequest, error)
// CreateRelease creates a release on the Forge, pointing at the commit with the passed in details. // CreateRelease creates a release on the Forge, pointing at the commit with the passed in details.
CreateRelease(ctx context.Context, commit Commit, title, changelog string, prerelease, latest bool) error CreateRelease(ctx context.Context, commit git.Commit, title, changelog string, prerelease, latest bool) error
} }
type ForgeOptions struct { type ForgeOptions struct {
@ -123,7 +125,7 @@ func (g *GitHub) LatestTags(ctx context.Context) (Releases, error) {
} }
for _, ghTag := range tags { for _, ghTag := range tags {
tag := &Tag{ tag := &git.Tag{
Hash: ghTag.GetCommit().GetSHA(), Hash: ghTag.GetCommit().GetSHA(),
Name: ghTag.GetName(), Name: ghTag.GetName(),
} }
@ -160,7 +162,7 @@ func (g *GitHub) LatestTags(ctx context.Context) (Releases, error) {
return releases, nil return releases, nil
} }
func (g *GitHub) CommitsSince(ctx context.Context, tag *Tag) ([]Commit, error) { func (g *GitHub) CommitsSince(ctx context.Context, tag *git.Tag) ([]git.Commit, error) {
var repositoryCommits []*github.RepositoryCommit var repositoryCommits []*github.RepositoryCommit
var err error var err error
if tag != nil { if tag != nil {
@ -173,9 +175,9 @@ func (g *GitHub) CommitsSince(ctx context.Context, tag *Tag) ([]Commit, error) {
return nil, err return nil, err
} }
var commits = make([]Commit, 0, len(repositoryCommits)) var commits = make([]git.Commit, 0, len(repositoryCommits))
for _, ghCommit := range repositoryCommits { for _, ghCommit := range repositoryCommits {
commit := Commit{ commit := git.Commit{
Hash: ghCommit.GetSHA(), Hash: ghCommit.GetSHA(),
Message: ghCommit.GetCommit().GetMessage(), Message: ghCommit.GetCommit().GetMessage(),
} }
@ -190,7 +192,7 @@ func (g *GitHub) CommitsSince(ctx context.Context, tag *Tag) ([]Commit, error) {
return commits, nil return commits, nil
} }
func (g *GitHub) commitsSinceTag(ctx context.Context, tag *Tag) ([]*github.RepositoryCommit, error) { func (g *GitHub) commitsSinceTag(ctx context.Context, tag *git.Tag) ([]*github.RepositoryCommit, error) {
head := g.options.BaseBranch head := g.options.BaseBranch
log := g.log.With("base", tag.Hash, "head", head) log := g.log.With("base", tag.Hash, "head", head)
log.Debug("comparing commits", "base", tag.Hash, "head", head) log.Debug("comparing commits", "base", tag.Hash, "head", head)
@ -269,7 +271,7 @@ func (g *GitHub) commitsSinceInit(ctx context.Context) ([]*github.RepositoryComm
return repositoryCommits, nil return repositoryCommits, nil
} }
func (g *GitHub) prForCommit(ctx context.Context, commit Commit) (*PullRequest, error) { func (g *GitHub) prForCommit(ctx context.Context, commit git.Commit) (*git.PullRequest, error) {
// We naively look up the associated PR for each commit through the "List pull requests associated with a commit" // We naively look up the associated PR for each commit through the "List pull requests associated with a commit"
// endpoint. This requires len(commits) requests. // endpoint. This requires len(commits) requests.
// Using the "List pull requests" endpoint might be faster, as it allows us to fetch 100 arbitrary PRs per request, // Using the "List pull requests" endpoint might be faster, as it allows us to fetch 100 arbitrary PRs per request,
@ -526,7 +528,7 @@ func (g *GitHub) PendingReleases(ctx context.Context, pendingLabel Label) ([]*Re
return prs, nil return prs, nil
} }
func (g *GitHub) CreateRelease(ctx context.Context, commit Commit, title, changelog string, preRelease, latest bool) error { func (g *GitHub) CreateRelease(ctx context.Context, commit git.Commit, title, changelog string, preRelease, latest bool) error {
makeLatest := "" makeLatest := ""
if latest { if latest {
makeLatest = "true" makeLatest = "true"
@ -551,8 +553,8 @@ func (g *GitHub) CreateRelease(ctx context.Context, commit Commit, title, change
return nil return nil
} }
func gitHubPRToPullRequest(pr *github.PullRequest) *PullRequest { func gitHubPRToPullRequest(pr *github.PullRequest) *git.PullRequest {
return &PullRequest{ return &git.PullRequest{
ID: pr.GetNumber(), ID: pr.GetNumber(),
Title: pr.GetTitle(), Title: pr.GetTitle(),
Description: pr.GetBody(), Description: pr.GetBody(),
@ -568,9 +570,9 @@ func gitHubPRToReleasePullRequest(pr *github.PullRequest) *ReleasePullRequest {
} }
} }
var releaseCommit *Commit var releaseCommit *git.Commit
if pr.MergeCommitSHA != nil { if pr.MergeCommitSHA != nil {
releaseCommit = &Commit{Hash: pr.GetMergeCommitSHA()} releaseCommit = &git.Commit{Hash: pr.GetMergeCommitSHA()}
} }
return &ReleasePullRequest{ return &ReleasePullRequest{

View file

@ -1 +0,0 @@
package rp

View file

@ -1,4 +1,4 @@
package rp package git
import ( import (
"context" "context"
@ -13,9 +13,22 @@ import (
) )
const ( const (
GitRemoteName = "origin" RemoteName = "origin"
) )
type Commit struct {
Hash string
Message string
PullRequest *PullRequest
}
type PullRequest struct {
ID int
Title string
Description string
}
type Tag struct { type Tag struct {
Hash string Hash string
Name string Name string
@ -27,11 +40,9 @@ func CloneRepo(ctx context.Context, cloneURL, branch string, auth transport.Auth
return nil, fmt.Errorf("failed to create temporary directory for repo clone: %w", err) return nil, fmt.Errorf("failed to create temporary directory for repo clone: %w", err)
} }
// TODO: Log tmpdir
fmt.Printf("Clone tmpdir: %s\n", dir)
repo, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{ repo, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
URL: cloneURL, URL: cloneURL,
RemoteName: GitRemoteName, RemoteName: RemoteName,
ReferenceName: plumbing.NewBranchReferenceName(branch), ReferenceName: plumbing.NewBranchReferenceName(branch),
SingleBranch: false, SingleBranch: false,
Auth: auth, Auth: auth,
@ -43,7 +54,7 @@ func CloneRepo(ctx context.Context, cloneURL, branch string, auth transport.Auth
return repo, nil return repo, nil
} }
func GitSignature() *object.Signature { func Signature() *object.Signature {
return &object.Signature{ return &object.Signature{
Name: "releaser-pleaser", Name: "releaser-pleaser",
Email: "", Email: "",

View file

@ -12,6 +12,7 @@ import (
"github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text" "github.com/yuin/goldmark/text"
"github.com/apricote/releaser-pleaser/internal/git"
"github.com/apricote/releaser-pleaser/internal/markdown" "github.com/apricote/releaser-pleaser/internal/markdown"
east "github.com/apricote/releaser-pleaser/internal/markdown/extensions/ast" east "github.com/apricote/releaser-pleaser/internal/markdown/extensions/ast"
) )
@ -41,7 +42,7 @@ type ReleasePullRequest struct {
Labels []Label Labels []Label
Head string Head string
ReleaseCommit *Commit ReleaseCommit *git.Commit
} }
func NewReleasePullRequest(head, branch, version, changelogEntry string) (*ReleasePullRequest, error) { func NewReleasePullRequest(head, branch, version, changelogEntry string) (*ReleasePullRequest, error) {

View file

@ -10,6 +10,8 @@ import (
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
git2 "github.com/apricote/releaser-pleaser/internal/git"
) )
const ( const (
@ -224,7 +226,7 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
logger.InfoContext(ctx, "next version", "version", nextVersion) logger.InfoContext(ctx, "next version", "version", nextVersion)
logger.DebugContext(ctx, "cloning repository", "clone.url", rp.forge.CloneURL()) logger.DebugContext(ctx, "cloning repository", "clone.url", rp.forge.CloneURL())
repo, err := CloneRepo(ctx, rp.forge.CloneURL(), rp.targetBranch, rp.forge.GitAuth()) repo, err := git2.CloneRepo(ctx, rp.forge.CloneURL(), rp.targetBranch, rp.forge.GitAuth())
if err != nil { if err != nil {
return fmt.Errorf("failed to clone repository: %w", err) return fmt.Errorf("failed to clone repository: %w", err)
} }
@ -317,8 +319,8 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
releaseCommitMessage := fmt.Sprintf("chore(%s): release %s", rp.targetBranch, nextVersion) releaseCommitMessage := fmt.Sprintf("chore(%s): release %s", rp.targetBranch, nextVersion)
releaseCommitHash, err := worktree.Commit(releaseCommitMessage, &git.CommitOptions{ releaseCommitHash, err := worktree.Commit(releaseCommitMessage, &git.CommitOptions{
Author: GitSignature(), Author: git2.Signature(),
Committer: GitSignature(), Committer: git2.Signature(),
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to commit changes: %w", err) return fmt.Errorf("failed to commit changes: %w", err)
@ -329,7 +331,7 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
newReleasePRChanges := true newReleasePRChanges := true
// Check if anything changed in comparison to the remote branch (if exists) // Check if anything changed in comparison to the remote branch (if exists)
if remoteRef, err := repo.Reference(plumbing.NewRemoteReferenceName(GitRemoteName, rpBranch), false); err != nil { if remoteRef, err := repo.Reference(plumbing.NewRemoteReferenceName(git2.RemoteName, rpBranch), false); err != nil {
if err.Error() != "reference not found" { if err.Error() != "reference not found" {
// "reference not found" is expected and we should always push // "reference not found" is expected and we should always push
return err return err
@ -363,7 +365,7 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
)) ))
logger.DebugContext(ctx, "pushing branch", "commit.hash", releaseCommitHash.String(), "branch.name", rpBranch, "refspec", pushRefSpec.String()) logger.DebugContext(ctx, "pushing branch", "commit.hash", releaseCommitHash.String(), "branch.name", rpBranch, "refspec", pushRefSpec.String())
if err = repo.PushContext(ctx, &git.PushOptions{ if err = repo.PushContext(ctx, &git.PushOptions{
RemoteName: GitRemoteName, RemoteName: git2.RemoteName,
RefSpecs: []config.RefSpec{pushRefSpec}, RefSpecs: []config.RefSpec{pushRefSpec},
Force: true, Force: true,
Auth: rp.forge.GitAuth(), Auth: rp.forge.GitAuth(),

View file

@ -6,11 +6,13 @@ import (
"github.com/blang/semver/v4" "github.com/blang/semver/v4"
"github.com/leodido/go-conventionalcommits" "github.com/leodido/go-conventionalcommits"
"github.com/apricote/releaser-pleaser/internal/git"
) )
type Releases struct { type Releases struct {
Latest *Tag Latest *git.Tag
Stable *Tag Stable *git.Tag
} }
type VersioningStrategy = func(Releases, conventionalcommits.VersionBump, NextVersionType) (string, error) type VersioningStrategy = func(Releases, conventionalcommits.VersionBump, NextVersionType) (string, error)
@ -97,7 +99,7 @@ func setPRVersion(version *semver.Version, prType string, count uint64) {
} }
} }
func parseSemverWithDefault(tag *Tag) (semver.Version, error) { func parseSemverWithDefault(tag *git.Tag) (semver.Version, error) {
version := "v0.0.0" version := "v0.0.0"
if tag != nil { if tag != nil {
version = tag.Name version = tag.Name

View file

@ -6,6 +6,8 @@ import (
"github.com/leodido/go-conventionalcommits" "github.com/leodido/go-conventionalcommits"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/apricote/releaser-pleaser/internal/git"
) )
func TestReleases_NextVersion(t *testing.T) { func TestReleases_NextVersion(t *testing.T) {
@ -24,8 +26,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "simple bump (major)", name: "simple bump (major)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MajorVersion, versionBump: conventionalcommits.MajorVersion,
nextVersionType: NextVersionTypeUndefined, nextVersionType: NextVersionTypeUndefined,
@ -37,8 +39,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "simple bump (minor)", name: "simple bump (minor)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MinorVersion, versionBump: conventionalcommits.MinorVersion,
nextVersionType: NextVersionTypeUndefined, nextVersionType: NextVersionTypeUndefined,
@ -50,8 +52,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "simple bump (patch)", name: "simple bump (patch)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeUndefined, nextVersionType: NextVersionTypeUndefined,
@ -63,8 +65,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "normal to prerelease (major)", name: "normal to prerelease (major)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MajorVersion, versionBump: conventionalcommits.MajorVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -76,8 +78,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "normal to prerelease (minor)", name: "normal to prerelease (minor)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MinorVersion, versionBump: conventionalcommits.MinorVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -89,8 +91,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "normal to prerelease (patch)", name: "normal to prerelease (patch)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -102,8 +104,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease bump (major)", name: "prerelease bump (major)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v2.0.0-rc.0"}, Latest: &git.Tag{Name: "v2.0.0-rc.0"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MajorVersion, versionBump: conventionalcommits.MajorVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -115,8 +117,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease bump (minor)", name: "prerelease bump (minor)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.2.0-rc.0"}, Latest: &git.Tag{Name: "v1.2.0-rc.0"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MinorVersion, versionBump: conventionalcommits.MinorVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -128,8 +130,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease bump (patch)", name: "prerelease bump (patch)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.2-rc.0"}, Latest: &git.Tag{Name: "v1.1.2-rc.0"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -141,8 +143,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease different bump (major)", name: "prerelease different bump (major)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.2.0-rc.0"}, Latest: &git.Tag{Name: "v1.2.0-rc.0"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MajorVersion, versionBump: conventionalcommits.MajorVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -154,8 +156,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease different bump (minor)", name: "prerelease different bump (minor)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.2-rc.0"}, Latest: &git.Tag{Name: "v1.1.2-rc.0"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.MinorVersion, versionBump: conventionalcommits.MinorVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -167,8 +169,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease to prerelease", name: "prerelease to prerelease",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-alpha.2"}, Latest: &git.Tag{Name: "v1.1.1-alpha.2"},
Stable: &Tag{Name: "v1.1.0"}, Stable: &git.Tag{Name: "v1.1.0"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -180,8 +182,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease to normal (explicit)", name: "prerelease to normal (explicit)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-alpha.2"}, Latest: &git.Tag{Name: "v1.1.1-alpha.2"},
Stable: &Tag{Name: "v1.1.0"}, Stable: &git.Tag{Name: "v1.1.0"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeNormal, nextVersionType: NextVersionTypeNormal,
@ -193,8 +195,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "prerelease to normal (implicit)", name: "prerelease to normal (implicit)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-alpha.2"}, Latest: &git.Tag{Name: "v1.1.1-alpha.2"},
Stable: &Tag{Name: "v1.1.0"}, Stable: &git.Tag{Name: "v1.1.0"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeUndefined, nextVersionType: NextVersionTypeUndefined,
@ -245,7 +247,7 @@ func TestReleases_NextVersion(t *testing.T) {
name: "nil stable release (major)", name: "nil stable release (major)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-rc.0"}, Latest: &git.Tag{Name: "v1.1.1-rc.0"},
Stable: nil, Stable: nil,
}, },
versionBump: conventionalcommits.MajorVersion, versionBump: conventionalcommits.MajorVersion,
@ -258,7 +260,7 @@ func TestReleases_NextVersion(t *testing.T) {
name: "nil stable release (minor)", name: "nil stable release (minor)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-rc.0"}, Latest: &git.Tag{Name: "v1.1.1-rc.0"},
Stable: nil, Stable: nil,
}, },
versionBump: conventionalcommits.MinorVersion, versionBump: conventionalcommits.MinorVersion,
@ -271,7 +273,7 @@ func TestReleases_NextVersion(t *testing.T) {
name: "nil stable release (patch)", name: "nil stable release (patch)",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-rc.0"}, Latest: &git.Tag{Name: "v1.1.1-rc.0"},
Stable: nil, Stable: nil,
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
@ -285,8 +287,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "error on invalid tag semver", name: "error on invalid tag semver",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "foodazzle"}, Latest: &git.Tag{Name: "foodazzle"},
Stable: &Tag{Name: "foodazzle"}, Stable: &git.Tag{Name: "foodazzle"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -298,8 +300,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "error on invalid tag prerelease", name: "error on invalid tag prerelease",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1-rc.foo"}, Latest: &git.Tag{Name: "v1.1.1-rc.foo"},
Stable: &Tag{Name: "v1.1.1-rc.foo"}, Stable: &git.Tag{Name: "v1.1.1-rc.foo"},
}, },
versionBump: conventionalcommits.PatchVersion, versionBump: conventionalcommits.PatchVersion,
nextVersionType: NextVersionTypeRC, nextVersionType: NextVersionTypeRC,
@ -311,8 +313,8 @@ func TestReleases_NextVersion(t *testing.T) {
name: "error on invalid bump", name: "error on invalid bump",
args: args{ args: args{
releases: Releases{ releases: Releases{
Latest: &Tag{Name: "v1.1.1"}, Latest: &git.Tag{Name: "v1.1.1"},
Stable: &Tag{Name: "v1.1.1"}, Stable: &git.Tag{Name: "v1.1.1"},
}, },
versionBump: conventionalcommits.UnknownVersion, versionBump: conventionalcommits.UnknownVersion,