Skip to content

Commit 2249122

Browse files
committed
refactor: use revision, add refactor
changes the GetCommitFromString function to use revision resolving to support `git rev-parse` syntax, also changes the inclusionFlags default values to have refactor as a default
1 parent ffab287 commit 2249122

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

gitutils.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,14 @@ func openRepository(path string) *git.Repository {
120120

121121
// GetCommitFromString - get commit from hash string
122122
func GetCommitFromString(commitString string, repo *git.Repository) *object.Commit {
123-
baseCommitReference, err := repo.Head()
123+
hash, err := repo.ResolveRevision(plumbing.Revision(commitString))
124124
if err != nil {
125125
log.Fatal("Unable to get Repo head:", err)
126126
}
127-
cIter, err := repo.Log(&git.LogOptions{From: baseCommitReference.Hash()})
128-
if err != nil {
129-
log.Fatal("Unable to get commits:", err)
130-
}
131-
foundMatch := false
132-
var commitRef *object.Commit
133-
134-
for {
135-
if foundMatch {
136-
break
137-
}
138-
139-
commit, _ := cIter.Next()
140-
141-
if commit.Hash.String() == commitString {
142-
foundMatch = true
143-
commitRef = commit
144-
}
145127

128+
commitRef, err := repo.CommitObject(*hash)
129+
if err != nil {
130+
log.Fatal("Unable to get resolve commit:", err)
146131
}
147-
148132
return commitRef
149133
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func main() {
2525
var repoPath = flag.String("p", ".", "path to the repository, points to the current working directory by default")
2626
var startCommit = flag.String("s", "", "commit hash string start collecting commit messages from")
2727
var endCommit = flag.String("e", "", "commit hash string to stop collecting commit message at")
28-
var inclusionFlags = flag.String("i", "ci,docs,fix,feat,test,chore,other", "commit types to be includes, defaults to CI FIX REFACTOR FEATURE DOCS CHORE TEST OTHER")
28+
var inclusionFlags = flag.String("i", "ci,refactor,docs,fix,feat,test,chore,other", "commit types to be includes, defaults to CI FIX REFACTOR FEATURE DOCS CHORE TEST OTHER")
2929
var skipClassification = flag.Bool("skip", false, "if true will skip trying to classify and just give a list of changes")
3030

3131
flag.Parse()

0 commit comments

Comments
 (0)