Skip to content

Commit c58ac36

Browse files
committed
fix: stability, command separation, cleaner commit message
removed the Changelog header as I think it's unnecessary and cleaned up the remaining commit messages to remove the key being used for classification also updated readme with the needed changes
1 parent 7f1ae6e commit c58ac36

File tree

8 files changed

+49
-26
lines changed

8 files changed

+49
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CHANGELOG.md
22
./commitlog
3+
.DS_Store

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,18 @@ Usage of commitlog:
9898
9999
```sh
100100
> commitlog
101+
# which is the shorthand of
102+
> commitlog log -p .
101103
```
102104
103-
```markdown
104-
# Changelog
105+
**As of 0.0.6 there's an experimental release subcommand that can be used for version tagging**
105106
107+
```markdown
106108
## Fixes
109+
97c582b3eb5a6796ef9c250d9653ad90dce63cbe - example fix
107110
108-
97c582b3eb5a6796ef9c250d9653ad90dce63cbe - fix: example fix
109111
110112
## Other Changes
111-
112113
da6d837eb3134f836bfbe401de7882f2e0818ba8 - Create LICENSE
113114
b0f1b1d2bc4265cb72b70b3ae5b60f8e65f47b12 - initial commit
114115
```

assets/header.png

12.3 KB
Loading

cmd/cmd.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
// Init - initializes the commands and also handles the classification
1111
func Init() {
12+
1213
// Install the needed commands from the cmd package
1314
releaseCmd.Install()
1415
commitlogCmd.Install()
@@ -21,9 +22,14 @@ func Init() {
2122
releaseCmd.Run(os.Args[2:])
2223
return
2324
}
25+
case "log":
26+
{
27+
commitlogCmd.Run(os.Args[2:])
28+
return
29+
}
2430
}
2531
}
2632

2733
// Default Command, parse all flags
28-
commitlogCmd.Run(os.Args)
34+
commitlogCmd.Run(os.Args[1:])
2935
}

cmd/commitlog/commitlog.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var skipClassification *bool
1717

1818
// Install - add flags and other options
1919
func Install() {
20-
clogCmd = flag.NewFlagSet("release", flag.ExitOnError)
20+
clogCmd = flag.NewFlagSet("commitlog", flag.ExitOnError)
2121
repoPath = clogCmd.String("p", ".", "path to the repository, points to the current working directory by default")
2222
startCommit = clogCmd.String("s", "", "commit hash string / revision (ex. HEAD, HEAD^, HEAD~2) \n to start collecting commit messages from")
2323
endCommit = clogCmd.String("e", "", "commit hash string / revision (ex. HEAD, HEAD^, HEAD~2) \n to stop collecting commit message at")
@@ -27,11 +27,17 @@ func Install() {
2727

2828
// Run - execute the command
2929
func Run(args []string) {
30-
clogCmd.Parse(args)
31-
changelog, err := clog.CommitLog(*repoPath, *startCommit, *endCommit, *inclusionFlags, *skipClassification)
3230

33-
if err.Err != nil {
34-
log.Fatal(err.Message, err.Err)
31+
err := clogCmd.Parse(args)
32+
33+
if err != nil {
34+
log.Fatalln(err)
35+
}
36+
37+
changelog, clogErr := clog.CommitLog(*repoPath, *startCommit, *endCommit, *inclusionFlags, *skipClassification)
38+
39+
if clogErr.Err != nil {
40+
log.Fatal(clogErr.Message, clogErr.Err)
3541
}
3642

3743
fmt.Println(changelog)

cmd/release/release.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ func Run(args []string) {
6161
var tagToUse = *tag
6262

6363
isBeta := needsQuestionnaire(args)
64-
releaseCmd.Parse(args)
64+
err := releaseCmd.Parse(args)
65+
if err != nil {
66+
log.Fatal(err)
67+
}
6568

6669
if tagToUse == "" {
6770
tagToUse = getTagString()

log/gitutils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ func isCommitToNearestTag(repo *git.Repository, commit *object.Commit) bool {
9797
}
9898

9999
// normalizeCommit - reduces the commit message to the first line and ignore the description text of the commit
100-
func normalizeCommit(commitMessage string) string {
100+
func normalizeCommit(commitMessage string, key string) string {
101101
var message string
102102
for i, msg := range strings.Split(commitMessage, "\n") {
103103
if i == 0 {
104104
message = msg
105105
break
106106
}
107107
}
108-
return strings.TrimSuffix(message, "\n")
108+
109+
removedPrefix := strings.TrimPrefix(strings.TrimSuffix(message, "\n"), key)
110+
return strings.TrimSpace(strings.TrimSuffix(removedPrefix, "\n"))
109111
}
110112

111113
// OpenRepository - open the git repository and return repository reference

log/log.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ func (container logContainer) printLog(out *strings.Builder, title string, skipp
7575
func (logs *logsByCategory) ToMarkdown(skipped bool) string {
7676
var markdownString strings.Builder
7777

78-
markdownString.WriteString("# Changelog \n")
79-
8078
if !skipped {
8179
logs.FEATURE.printLog(&markdownString, "Features", skipped)
8280
logs.FIX.printLog(&markdownString, "Fixes", skipped)
@@ -187,9 +185,10 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
187185
logContainer.OTHER.include = inclusions.checkInclusion("other")
188186

189187
for _, c := range commits {
190-
normalizedHash := c.Hash.String() + " - " + normalizeCommit(c.Message)
191-
key := findKeyInCommit(SupportedKeys, c.Message)
188+
key, scopedKey := findKeyInCommit(SupportedKeys, c.Message)
189+
fmt.Printf("key: %v,scopedKey:%v \n", key, scopedKey)
192190
key = strings.SplitN(strings.TrimSpace(key), ":", 2)[0]
191+
normalizedHash := c.Hash.String() + " - " + normalizeCommit(c.Message, scopedKey)
193192

194193
logContainer.AddCommit(key, normalizedHash, skipClassification)
195194

@@ -214,15 +213,20 @@ func (inclusions *commitTypeInclusions) checkInclusion(flagToCheck string) bool
214213
return false
215214
}
216215

217-
func findKeyInCommit(key string, commitMessage string) string {
216+
func findKeyInCommit(key string, commitMessage string) (string, string) {
218217
re := regexp.MustCompile(`^(` + key + `)[:]|^((` + key + `)\((\w+[, /\\]*)+\)[:])`)
219-
if len(re.FindAllStringSubmatch(commitMessage, -1)) > 0 {
220-
keyCheckOne := re.FindAllStringSubmatch(commitMessage, -1)[0][3]
221-
if keyCheckOne == "" {
222-
keyCheckTwo := re.FindAllStringSubmatch(commitMessage, -1)[0][1]
223-
return keyCheckTwo
224-
}
225-
return keyCheckOne
218+
keyMatches := re.FindAllStringSubmatch(commitMessage, -1)
219+
fmt.Printf("%v", keyMatches)
220+
if len(keyMatches) == 0 {
221+
return "", ""
222+
}
223+
224+
scopedKey := keyMatches[0][0]
225+
scopelessKey := keyMatches[0][3]
226+
227+
if scopelessKey == "" {
228+
scopelessKey = keyMatches[0][1]
226229
}
227-
return ""
230+
231+
return scopelessKey, scopedKey
228232
}

0 commit comments

Comments
 (0)