Add ability to start from user specified hash.

This feature can be useful for repositories with already established versioning, but
having hundreds of commits which could potentially produce really weird results due
to lack of previous rules on wording.
This commit is contained in:
2021-05-09 19:04:25 +01:00
parent 3b4c00f0ef
commit 1b2292f6cb
6 changed files with 59 additions and 57 deletions
+12 -4
View File
@@ -25,6 +25,7 @@ import (
"time"
git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/lithammer/fuzzysearch/fuzzy"
"github.com/lukaszraczylo/zero"
@@ -44,9 +45,10 @@ type Wording struct {
}
type Force struct {
Patch int
Minor int
Major int
Patch int
Minor int
Major int
Commit string
}
type SemVer struct {
@@ -107,7 +109,13 @@ func (s *Setup) CalculateSemver() SemVer {
}
func (s *Setup) ListCommits() ([]CommitDetails, error) {
ref, err := s.RepositoryHandler.Head()
var ref *plumbing.Reference
var err error
if zero.IsZero(s.Force.Commit) {
ref, err = s.RepositoryHandler.Head()
} else {
ref = plumbing.NewHashReference("start_commit", plumbing.NewHash(s.Force.Commit))
}
if err != nil {
return []CommitDetails{}, err
}
+28
View File
@@ -285,11 +285,23 @@ func (suite *Tests) TestSetup_ListCommits() {
noCommits: true,
wantErr: true,
},
{
name: "List commits starting with certain hash",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
Force: Force{
Commit: "69fbe2df696f40281b9104ff073d26186cde1024",
},
},
noCommits: false,
wantErr: false,
},
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {
s := &Setup{
RepositoryName: tt.fields.RepositoryName,
Force: tt.fields.Force,
}
s.Prepare()
listOfCommits, err := s.ListCommits()
@@ -306,6 +318,7 @@ func (suite *Tests) TestSetup_ListCommits() {
func (suite *Tests) TestSetup_CalculateSemver() {
type fields struct {
RepositoryName string
Force Force
}
type wantSemver struct {
Major int
@@ -328,6 +341,20 @@ func (suite *Tests) TestSetup_CalculateSemver() {
Patch: 1,
},
},
{
name: "Test on existing repository, starting with certain hash",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
Force: Force{
Commit: "69fbe2df696f40281b9104ff073d26186cde1024",
},
},
wantSemver: wantSemver{
Major: 3,
Minor: 0,
Patch: 5,
},
},
{
name: "Test on non-existing repository",
fields: fields{
@@ -344,6 +371,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
suite.T().Run(tt.name, func(t *testing.T) {
s := &Setup{
RepositoryName: tt.fields.RepositoryName,
Force: tt.fields.Force,
}
s.ReadConfig("../config.yaml")
s.Prepare()