From 3ab8e177192500c96f9f12dbfbcbe5399e9ad5d4 Mon Sep 17 00:00:00 2001 From: hau Date: Tue, 10 Nov 2020 15:39:54 +0700 Subject: [PATCH] refactor: remove body and footers in convention --- pkg/convention/commit.go | 16 ++-------- pkg/convention/commit_test.go | 31 +++++++------------ ...cription_and_breaking_change_footer.golden | 6 ---- ...description_and_breaking_change_footer.txt | 3 -- ...paragraph_body_and_multiple_footers.golden | 6 ---- ...ti-paragraph_body_and_multiple_footers.txt | 8 ----- .../Commit_message_with_no_body.golden | 3 +- .../Commit_message_with_no_body.txt | 1 - ...o_draw_attention_to_breaking_change.golden | 3 +- ...r_to_draw_attention_to_breaking_change.txt | 1 - .../Commit_message_with_scope.golden | 3 +- .../Commit_message_with_scope.txt | 1 - 12 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.golden delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.txt delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.golden delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.txt delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.txt delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.txt delete mode 100644 pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.txt diff --git a/pkg/convention/commit.go b/pkg/convention/commit.go index d6e1668..124ac26 100644 --- a/pkg/convention/commit.go +++ b/pkg/convention/commit.go @@ -18,10 +18,9 @@ var ( ) type Commit struct { - Type string - Scope string - Description string - BodyAndFooters string + Type string + Scope string + Description string } func NewCommit(c git.Commit) (result Commit, err error) { @@ -37,9 +36,6 @@ func NewCommit(c git.Commit) (result Commit, err error) { return } - bodyAndFooters := message[len(header):] - parseBodyAndFooters(bodyAndFooters, &result) - return } @@ -60,9 +56,3 @@ func parseHeader(header string, commit *Commit) error { return nil } - -func parseBodyAndFooters(bodyAndFooters string, commit *Commit) { - bodyAndFooters = strings.TrimSpace(bodyAndFooters) - - commit.BodyAndFooters = bodyAndFooters -} diff --git a/pkg/convention/commit_test.go b/pkg/convention/commit_test.go index 0ca28ce..0f9ba87 100644 --- a/pkg/convention/commit_test.go +++ b/pkg/convention/commit_test.go @@ -1,9 +1,6 @@ package convention import ( - "fmt" - "io/ioutil" - "strings" "testing" "github.com/haunt98/changeloguru/pkg/comparision" @@ -14,40 +11,34 @@ import ( func TestNewCommit(t *testing.T) { tests := []struct { name string + c git.Commit wantErr error }{ - { - name: "Commit message with description and breaking change footer", - }, { name: "Commit message with not character to draw attention to breaking change", + c: git.Commit{ + Message: "refactor!: drop support for Node 6", + }, }, { name: "Commit message with no body", + c: git.Commit{ + Message: "docs: correct spelling of CHANGELOG", + }, }, { name: "Commit message with scope", - }, - { - name: "Commit message with multi-paragraph body and multiple footers", + c: git.Commit{ + Message: "feat(lang): add polish language", + }, }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { g := goldie.New(t) - gName := g.GoldenFileName(t, t.Name()) - inputName := strings.TrimSuffix(gName, ".golden") + ".txt" - fmt.Println("inputName", inputName) - bytes, err := ioutil.ReadFile(inputName) - if err != nil { - t.Error(err) - } - - gotResult, gotErr := NewCommit(git.Commit{ - Message: string(bytes), - }) + gotResult, gotErr := NewCommit(tc.c) comparision.Diff(t, tc.wantErr, gotErr) if tc.wantErr != nil { return diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.golden deleted file mode 100644 index f027876..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.golden +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Type": "feat", - "Scope": "", - "Description": "allow provided config object to extend other configs", - "BodyAndFooters": "BREAKING CHANGE: `extends` key in config file is now used for extending other config files" -} \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.txt b/pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.txt deleted file mode 100644 index 32b0813..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_description_and_breaking_change_footer.txt +++ /dev/null @@ -1,3 +0,0 @@ -feat: allow provided config object to extend other configs - -BREAKING CHANGE: `extends` key in config file is now used for extending other config files diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.golden deleted file mode 100644 index 39c3f92..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.golden +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Type": "fix", - "Scope": "", - "Description": "correct minor typos in code", - "BodyAndFooters": "see the issue for details\n\non typos fixed.\n\nReviewed-by: Z\nRefs #133" -} \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.txt b/pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.txt deleted file mode 100644 index a0f4f55..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_multi-paragraph_body_and_multiple_footers.txt +++ /dev/null @@ -1,8 +0,0 @@ -fix: correct minor typos in code - -see the issue for details - -on typos fixed. - -Reviewed-by: Z -Refs #133 diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden index 9cbdefd..3f4313d 100644 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden +++ b/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.golden @@ -1,6 +1,5 @@ { "Type": "docs", "Scope": "", - "Description": "correct spelling of CHANGELOG", - "BodyAndFooters": "" + "Description": "correct spelling of CHANGELOG" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.txt b/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.txt deleted file mode 100644 index 43edabc..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_no_body.txt +++ /dev/null @@ -1 +0,0 @@ -docs: correct spelling of CHANGELOG diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden index 001d04f..5c03cdf 100644 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden +++ b/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.golden @@ -1,6 +1,5 @@ { "Type": "refactor", "Scope": "", - "Description": "drop support for Node 6", - "BodyAndFooters": "" + "Description": "drop support for Node 6" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.txt b/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.txt deleted file mode 100644 index bade5d2..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_not_character_to_draw_attention_to_breaking_change.txt +++ /dev/null @@ -1 +0,0 @@ -refactor!: drop support for Node 6 diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden b/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden index c6114b6..fbab8ee 100644 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden +++ b/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.golden @@ -1,6 +1,5 @@ { "Type": "feat", "Scope": "lang", - "Description": "add polish language", - "BodyAndFooters": "" + "Description": "add polish language" } \ No newline at end of file diff --git a/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.txt b/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.txt deleted file mode 100644 index 5a16252..0000000 --- a/pkg/convention/testdata/TestNewCommit/Commit_message_with_scope.txt +++ /dev/null @@ -1 +0,0 @@ -feat(lang): add polish language