Skip to content

Commit 7f145ad

Browse files
committed
add skip flag
adds the ability to avoid categorization when needed, also set a base for the inclusion flags
1 parent be18669 commit 7f145ad

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

logcategory.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,35 @@ type logsByCategory struct {
2424
}
2525

2626
// printLog - loops through the collected logs to write them to string builder
27-
func (logs logContainer) printLog(out *strings.Builder, title string) {
27+
func (logs logContainer) printLog(out *strings.Builder, title string, skipped bool) {
2828
if len(logs) > 0 {
29-
out.WriteString(fmt.Sprintf("\n\n## %s \n", title))
29+
if !skipped {
30+
out.WriteString(fmt.Sprintf("\n\n## %s \n", title))
31+
}
3032
for _, item := range logs {
3133
out.WriteString(item + "\n")
3234
}
3335
}
3436
}
3537

3638
// ToMarkdown - Generate markdown output for the collected commits
37-
func (logs *logsByCategory) ToMarkdown() string {
39+
func (logs *logsByCategory) ToMarkdown(skipped bool) string {
3840
var markdownString strings.Builder
3941

4042
markdownString.WriteString("# Changelog \n")
4143

42-
logs.FEATURE.printLog(&markdownString, "Features")
43-
logs.FIX.printLog(&markdownString, "Fixes")
44-
logs.REFACTOR.printLog(&markdownString, "Performance")
45-
logs.CI.printLog(&markdownString, "CI")
46-
logs.DOCS.printLog(&markdownString, "Docs")
47-
logs.CHORE.printLog(&markdownString, "Chores")
48-
logs.TEST.printLog(&markdownString, "Tests")
49-
logs.OTHER.printLog(&markdownString, "Other Changes")
44+
if !skipped {
45+
logs.FEATURE.printLog(&markdownString, "Features", skipped)
46+
logs.FIX.printLog(&markdownString, "Fixes", skipped)
47+
logs.REFACTOR.printLog(&markdownString, "Performance", skipped)
48+
logs.CI.printLog(&markdownString, "CI", skipped)
49+
logs.DOCS.printLog(&markdownString, "Docs", skipped)
50+
logs.CHORE.printLog(&markdownString, "Chores", skipped)
51+
logs.TEST.printLog(&markdownString, "Tests", skipped)
52+
logs.OTHER.printLog(&markdownString, "Other Changes", skipped)
53+
} else {
54+
logs.OTHER.printLog(&markdownString, "Other Changes", skipped)
55+
}
5056

5157
return markdownString.String()
5258
}

main.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ func main() {
2323
var startCommit = flag.String("s", "", "commit hash string start collecting commit messages from")
2424
var endCommit = flag.String("e", "", "commit hash string to stop collecting commit message at")
2525
var inclusionFlags = flag.String("i", "", "commit types to be includes, defaults to CI FIX REFACTOR FEATURE DOCS CHORE TEST OTHER")
26+
var skipClassification = flag.Bool("skip", false, "if true will skip trying to classify and just give a list of changes")
2627

2728
flag.Parse()
2829

2930
path := repoPath
3031

31-
err := CommitLog(*path, *startCommit, *endCommit, *inclusionFlags)
32+
err := CommitLog(*path, *startCommit, *endCommit, *inclusionFlags, *skipClassification)
3233

3334
if err.err != nil {
3435
log.Fatal(err.message, err.err)
3536
}
3637
}
3738

3839
// CommitLog - Generate commit log
39-
func CommitLog(path string, startCommitString string, endCommitString string, inclusionFlags string) ErrMessage {
40+
func CommitLog(path string, startCommitString string, endCommitString string, inclusionFlags string, skipClassification bool) ErrMessage {
4041
currentRepository := openRepository(path)
4142
baseCommitReference, err := currentRepository.Head()
4243
var startHash, endHash *object.Commit
@@ -79,22 +80,26 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
7980

8081
for _, c := range commits {
8182
normalizedHash := c.Hash.String() + " - " + normalizeCommit(c.Message)
82-
switch strings.SplitN(strings.TrimSpace(c.Message), ":", 2)[0] {
83-
case "ci":
84-
logContainer.CI = append(logContainer.CI, normalizedHash)
85-
case "fix":
86-
logContainer.FIX = append(logContainer.FIX, normalizedHash)
87-
case "refactor":
88-
logContainer.REFACTOR = append(logContainer.REFACTOR, normalizedHash)
89-
case "feat", "feature":
90-
logContainer.FEATURE = append(logContainer.FEATURE, normalizedHash)
91-
case "docs":
92-
logContainer.DOCS = append(logContainer.DOCS, normalizedHash)
93-
case "test":
94-
logContainer.TEST = append(logContainer.TEST, normalizedHash)
95-
case "chore":
96-
logContainer.CHORE = append(logContainer.CHORE, normalizedHash)
97-
default:
83+
if !skipClassification {
84+
switch strings.SplitN(strings.TrimSpace(c.Message), ":", 2)[0] {
85+
case "ci":
86+
logContainer.CI = append(logContainer.CI, normalizedHash)
87+
case "fix":
88+
logContainer.FIX = append(logContainer.FIX, normalizedHash)
89+
case "refactor":
90+
logContainer.REFACTOR = append(logContainer.REFACTOR, normalizedHash)
91+
case "feat", "feature":
92+
logContainer.FEATURE = append(logContainer.FEATURE, normalizedHash)
93+
case "docs":
94+
logContainer.DOCS = append(logContainer.DOCS, normalizedHash)
95+
case "test":
96+
logContainer.TEST = append(logContainer.TEST, normalizedHash)
97+
case "chore":
98+
logContainer.CHORE = append(logContainer.CHORE, normalizedHash)
99+
default:
100+
logContainer.OTHER = append(logContainer.OTHER, normalizedHash)
101+
}
102+
} else {
98103
logContainer.OTHER = append(logContainer.OTHER, normalizedHash)
99104
}
100105

@@ -104,7 +109,7 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
104109
break
105110
}
106111
}
107-
fmt.Println(logContainer.ToMarkdown())
112+
fmt.Println(logContainer.ToMarkdown(skipClassification))
108113

109114
return ErrMessage{}
110115
}

0 commit comments

Comments
 (0)