github.com/brandonmanuel/git-chglog@v0.0.0-20200903004639-7a62fa08787a/cmd/git-chglog/config_builder.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // ConfigBuilder ... 9 type ConfigBuilder interface { 10 Builder 11 } 12 13 type configBuilderImpl struct{} 14 15 // NewConfigBuilder ... 16 func NewConfigBuilder() ConfigBuilder { 17 return &configBuilderImpl{} 18 } 19 20 // Build ... 21 func (*configBuilderImpl) Build(ans *Answer) (string, error) { 22 var msgFormat *CommitMessageFormat 23 24 for _, ff := range formats { 25 f, _ := ff.(*CommitMessageFormat) 26 if f.display == ans.CommitMessageFormat { 27 msgFormat = f 28 break 29 } 30 } 31 32 if msgFormat == nil { 33 return "", fmt.Errorf("\"%s\" is an invalid commit message format", ans.CommitMessageFormat) 34 } 35 36 repoURL := strings.TrimRight(ans.RepositoryURL, "/") 37 if repoURL == "" { 38 repoURL = "\"\"" 39 } 40 41 config := fmt.Sprintf(`style: %s 42 template: %s 43 info: 44 title: CHANGELOG 45 repository_url: %s 46 options: 47 commits: 48 # filters: 49 # Type:%s 50 commit_groups: 51 # title_maps:%s 52 header: 53 pattern: "%s" 54 pattern_maps:%s 55 notes: 56 keywords: 57 - BREAKING CHANGE`, 58 ans.Style, 59 defaultTemplateFilename, 60 repoURL, 61 msgFormat.FilterTypesString(), 62 msgFormat.TitleMapsString(), 63 msgFormat.pattern, 64 msgFormat.PatternMapString(), 65 ) 66 67 return config, nil 68 }