-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from git-chglog/feat/0.0.3
v0.0.3
- Loading branch information
Showing
27 changed files
with
1,198 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
// Builder ... | ||
type Builder interface { | ||
Build(*Answer) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ConfigBuilder ... | ||
type ConfigBuilder interface { | ||
Builder | ||
} | ||
|
||
type configBuilderImpl struct{} | ||
|
||
// NewConfigBuilder ... | ||
func NewConfigBuilder() ConfigBuilder { | ||
return &configBuilderImpl{} | ||
} | ||
|
||
// Build ... | ||
func (*configBuilderImpl) Build(ans *Answer) (string, error) { | ||
var msgFormat *CommitMessageFormat | ||
|
||
for _, f := range formats { | ||
if f.Display == ans.CommitMessageFormat { | ||
msgFormat = f | ||
break | ||
} | ||
} | ||
|
||
if msgFormat == nil { | ||
return "", fmt.Errorf("\"%s\" is an invalid commit message format", ans.CommitMessageFormat) | ||
} | ||
|
||
repoURL := strings.TrimRight(ans.RepositoryURL, "/") | ||
if repoURL == "" { | ||
repoURL = "\"\"" | ||
} | ||
|
||
config := fmt.Sprintf(`style: %s | ||
template: %s | ||
info: | ||
title: CHANGELOG | ||
repository_url: %s | ||
options: | ||
commits: | ||
# filters: | ||
# Type: | ||
# - feat | ||
# - fix | ||
# - perf | ||
# - refactor | ||
commit_groups: | ||
# title_maps: | ||
# feat: Features | ||
# fix: Bug Fixes | ||
# perf: Performance Improvements | ||
# refactor: Code Refactoring | ||
header: | ||
pattern: "%s" | ||
pattern_maps:%s | ||
notes: | ||
keywords: | ||
- BREAKING CHANGE`, | ||
ans.Style, | ||
defaultTemplateFilename, | ||
repoURL, | ||
msgFormat.Pattern, | ||
msgFormat.PatternMapString(), | ||
) | ||
|
||
return config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
type mockConfigBuilderImpl struct { | ||
ReturnBuild func(*Answer) (string, error) | ||
} | ||
|
||
func (m *mockConfigBuilderImpl) Build(ans *Answer) (string, error) { | ||
return m.ReturnBuild(ans) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigBulider(t *testing.T) { | ||
assert := assert.New(t) | ||
builder := NewConfigBuilder() | ||
|
||
out, err := builder.Build(&Answer{ | ||
RepositoryURL: "https://github.com/git-chglog/git-chglog/git-chglog/", | ||
Style: styleNone, | ||
CommitMessageFormat: fmtGitBasic.Display, | ||
Template: tplStandard, | ||
}) | ||
|
||
assert.Nil(err) | ||
assert.Contains(out, "style: none") | ||
assert.Contains(out, "template: CHANGELOG.tpl.md") | ||
assert.Contains(out, " repository_url: https://github.com/git-chglog/git-chglog/git-chglog") | ||
assert.Contains(out, fmt.Sprintf(" pattern: \"%s\"", fmtGitBasic.Pattern)) | ||
assert.Contains(out, fmt.Sprintf( | ||
` pattern_maps: | ||
- %s | ||
- %s`, | ||
fmtGitBasic.PatternMaps[0], | ||
fmtGitBasic.PatternMaps[1], | ||
)) | ||
} | ||
|
||
func TestConfigBuliderEmptyRepoURL(t *testing.T) { | ||
assert := assert.New(t) | ||
builder := NewConfigBuilder() | ||
|
||
out, err := builder.Build(&Answer{ | ||
RepositoryURL: "", | ||
Style: styleNone, | ||
CommitMessageFormat: fmtGitBasic.Display, | ||
Template: tplStandard, | ||
}) | ||
|
||
assert.Nil(err) | ||
assert.Contains(out, " repository_url: \"\"") | ||
} | ||
|
||
func TestConfigBuliderInvalidFormat(t *testing.T) { | ||
assert := assert.New(t) | ||
builder := NewConfigBuilder() | ||
|
||
_, err := builder.Build(&Answer{ | ||
RepositoryURL: "", | ||
Style: styleNone, | ||
CommitMessageFormat: "", | ||
Template: tplStandard, | ||
}) | ||
|
||
assert.Contains(err.Error(), "invalid commit message format") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.