Skip to content

Commit

Permalink
fix(github): squash commits done by github broken
Browse files Browse the repository at this point in the history
The way github auto squash formats messages would break the relase notes.

Closes #299
  • Loading branch information
fallion committed Jan 1, 2022
1 parent a39889f commit 3a4f67b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist
testdata/*
!testdata/*.bundle
!testdata/setup_test_repos.sh
.idea
.idea
testrepo
2 changes: 1 addition & 1 deletion internal/text/build_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func BuildHistory(messages []quoad.Commit) string {
builder.WriteString("- ")
builder.WriteString(messages[i].Category)
builder.WriteString(" ")
builder.WriteString(messages[i].Heading)
builder.WriteString(TrimMessage(messages[i].Heading))
builder.WriteString("\n")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/text/build_single_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func buildSimpleCommit(commit quoad.Commit) string {
builder.WriteString(" ")
}

builder.WriteString(commit.Heading)
builder.WriteString(TrimMessage(commit.Heading))

for _, refID := range commit.Issues {
builder.WriteString(fmt.Sprintf(" #%d", refID))
Expand All @@ -60,7 +60,7 @@ func buildFullCommit(commit quoad.Commit, open bool) string {
builder.WriteString("<summary>")
builder.WriteString(commit.Hash.String()[:7])
builder.WriteString(" ")
builder.WriteString(commit.Heading)
builder.WriteString(TrimMessage(commit.Heading))
builder.WriteString("</summary>")
builder.WriteString("\n\n")
builder.WriteString(commit.Body)
Expand Down
18 changes: 9 additions & 9 deletions internal/text/release_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func TestReleaseNotes(t *testing.T) {
expected := string(b)

sections := map[string][]quoad.Commit{
"features": []quoad.Commit{quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test", Body: "- Body"}},
"chores": []quoad.Commit{quoad.Commit{Category: "chore", Scope: "", Heading: "testing", Body: "- Body"}, quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores", Issues: []int{12}}},
"bugs": []quoad.Commit{quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug", Body: "Body"}},
"others": []quoad.Commit{quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"}, quoad.Commit{Category: "bs", Scope: "", Heading: "random"}},
"features": {quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test", Body: "- Body"}},
"chores": {quoad.Commit{Category: "chore", Scope: "", Heading: "testing", Body: "- Body"}, quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores", Issues: []int{12}}},
"bugs": {quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug", Body: "Body"}},
"others": {quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"}, quoad.Commit{Category: "bs", Scope: "", Heading: "random"}},
}

releaseNotes := notes.Generate(sections, false)
Expand All @@ -50,10 +50,10 @@ func TestReleaseNotesSimple(t *testing.T) {
expected := string(b)

sections := map[string][]quoad.Commit{
"features": []quoad.Commit{quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test"}},
"chores": []quoad.Commit{quoad.Commit{Category: "chore", Scope: "", Heading: "testing"}, quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores", Issues: []int{12}}},
"bugs": []quoad.Commit{quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug"}},
"others": []quoad.Commit{quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"}, quoad.Commit{Category: "bs", Scope: "", Heading: "random"}},
"features": {quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test"}},
"chores": {quoad.Commit{Category: "chore", Scope: "", Heading: "testing"}, quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores", Issues: []int{12}}},
"bugs": {quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug"}},
"others": {quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"}, quoad.Commit{Category: "bs", Scope: "", Heading: "random"}},
}

releaseNotes := notes.Generate(sections, false)
Expand All @@ -66,7 +66,7 @@ func TestReleaseNotesWithMissingSections(t *testing.T) {
expected := "\n\n## :rocket: Features\n\n- 0000000 ci test\n\n"

sections := map[string][]quoad.Commit{
"features": []quoad.Commit{quoad.Commit{Heading: "ci test"}},
"features": {quoad.Commit{Heading: "ci test"}},
}

releaseNotes := notes.Generate(sections, false)
Expand Down
22 changes: 11 additions & 11 deletions internal/text/split_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (

func TestSplitSections(t *testing.T) {
dataset := []quoad.Commit{
quoad.Commit{Category: "chore", Scope: "", Heading: "testing"},
quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test"},
quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"},
quoad.Commit{Category: "bs", Scope: "", Heading: "random"},
quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores"},
quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug"},
quoad.Commit{Category: "fix", Scope: "", Heading: "bug fix"},
{Category: "chore", Scope: "", Heading: "testing"},
{Category: "feat", Scope: "ci", Heading: "ci test"},
{Category: "other", Scope: "", Heading: "merge master in something"},
{Category: "bs", Scope: "", Heading: "random"},
{Category: "improvement", Scope: "", Heading: "this should end up in chores"},
{Category: "bug", Scope: "", Heading: "huge bug"},
{Category: "fix", Scope: "", Heading: "bug fix"},
}

expected := map[string][]quoad.Commit{
"features": []quoad.Commit{quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test"}},
"chores": []quoad.Commit{quoad.Commit{Category: "chore", Scope: "", Heading: "testing"}, quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores"}},
"bugs": []quoad.Commit{quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug"}, quoad.Commit{Category: "fix", Scope: "", Heading: "bug fix"}},
"others": []quoad.Commit{quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"}, quoad.Commit{Category: "bs", Scope: "", Heading: "random"}},
"features": {quoad.Commit{Category: "feat", Scope: "ci", Heading: "ci test"}},
"chores": {quoad.Commit{Category: "chore", Scope: "", Heading: "testing"}, quoad.Commit{Category: "improvement", Scope: "", Heading: "this should end up in chores"}},
"bugs": {quoad.Commit{Category: "bug", Scope: "", Heading: "huge bug"}, quoad.Commit{Category: "fix", Scope: "", Heading: "bug fix"}},
"others": {quoad.Commit{Category: "other", Scope: "", Heading: "merge master in something"}, quoad.Commit{Category: "bs", Scope: "", Heading: "random"}},
}

sections := SplitSections(dataset)
Expand Down
9 changes: 3 additions & 6 deletions internal/text/trim_message.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package text

import (
"regexp"
"strings"
)

var messageRegex = regexp.MustCompile("^.*\n")

// TrimMessage returns only the first line of commit message
func TrimMessage(message string) string {
match := messageRegex.FindString(message)
match := strings.Split(message, "\n")

match = strings.Replace(match, "\n", "", 1)
final := strings.TrimRight(match[0], " ")

return match
return final
}
21 changes: 21 additions & 0 deletions internal/text/trim_message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package text

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestTrimMessage(t *testing.T) {
testset := map[string]string{
"ci: sometest \n": "ci: sometest",
"ci: sometest\n": "ci: sometest",
"chore: some github message\n some more text here": "chore: some github message",
"chore: someother thing": "chore: someother thing",
}

for input, expected := range testset {
assert.Equal(t, expected, TrimMessage(input))
}

}
6 changes: 3 additions & 3 deletions internal/text/urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
)

type urlTestStruct struct {
url string
url string
commit string
}

func TestLinkToCommit(t *testing.T) {
tests := map[string]urlTestStruct{
"https://github.com/commisar-app/commitsar/commit/12345": urlTestStruct{url: "https://github.com/commisar-app/commitsar", commit:"12345"},
"https://github.com/commisar-app/commitsar/commit/12345": {url: "https://github.com/commisar-app/commitsar", commit: "12345"},
}

for expected, test := range tests {
link := LinkToCommit(test.url, test.commit)
assert.Equal(t, expected, link)
}
}
}

0 comments on commit 3a4f67b

Please sign in to comment.