Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config overhaul #633

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (b *Batch) Run(cmd *cobra.Command, args []string) error {
}

if len(b.config.Projects) > 0 {
var pc *core.ProjectConfig
var pc *core.ProjectConfigOptions

pc, err = b.config.Project(b.Project)
pc, err = b.config.ProjectFromLabel(b.Project)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func batchTestConfig() *core.Config {
KindFormat: "### {{.Kind}}",
ChangeFormat: "* {{.Body}}",
FragmentFileFormat: "",
Kinds: []core.KindConfig{
Kinds: []core.KindConfigOld{
{Label: "added"},
{Label: "removed"},
{Label: "other"},
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestBatchCanBatch(t *testing.T) {

func TestBatchCanBatchWithProject(t *testing.T) {
cfg := batchTestConfig()
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "A",
Key: "a",
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestBatchCanBatchWithProject(t *testing.T) {

func TestBatchProjectFailsIfUnableToMakeProjectDir(t *testing.T) {
cfg := batchTestConfig()
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "A",
Key: "a",
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestBatchProjectFailsIfUnableToMakeProjectDir(t *testing.T) {

func TestBatchProjectFailsIfUnableToFindProject(t *testing.T) {
cfg := batchTestConfig()
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "A",
Key: "a",
Expand Down
1 change: 1 addition & 0 deletions cmd/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func testMerge(t *testing.T, cmd *cobra.Command) {
then.FileContents(t, changeContents, "CHANGELOG.md")
}

// TODO: create a second test with the old init before the new config format
func TestFullRun(t *testing.T) {
cmd := RootCmd()

Expand Down
62 changes: 32 additions & 30 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,47 @@ Default values follow keep a changelog and semver specs but are customizable.`,
func (i *Init) Run(cmd *cobra.Command, args []string) error {
config := core.Config{
ChangesDir: i.ChangesDir,
EnvPrefix: "CHANGIE_",
UnreleasedDir: "unreleased",
HeaderPath: "header.tpl.md",
ChangelogPath: i.ChangelogPath,
VersionExt: "md",
VersionFormat: "## {{.Version}} - {{.Time.Format \"2006-01-02\"}}",
KindFormat: "### {{.Kind}}",
ChangeFormat: "* {{.Body}}",
Kinds: []core.KindConfig{
{
Label: "Added",
AutoLevel: core.MinorLevel,
/*
Kinds: []core.KindConfig{
{
Label: "Added",
AutoLevel: core.MinorLevel,
},
{
Label: "Changed",
AutoLevel: core.MajorLevel,
},
{
Label: "Deprecated",
AutoLevel: core.MinorLevel,
},
{
Label: "Removed",
AutoLevel: core.MajorLevel,
},
{
Label: "Fixed",
AutoLevel: core.PatchLevel,
},
{
Label: "Security",
AutoLevel: core.PatchLevel,
},
},
{
Label: "Changed",
AutoLevel: core.MajorLevel,
Newlines: core.NewlinesConfig{
AfterChangelogHeader: 1,
BeforeChangelogVersion: 1,
EndOfVersion: 1,
},
{
Label: "Deprecated",
AutoLevel: core.MinorLevel,
},
{
Label: "Removed",
AutoLevel: core.MajorLevel,
},
{
Label: "Fixed",
AutoLevel: core.PatchLevel,
},
{
Label: "Security",
AutoLevel: core.PatchLevel,
},
},
Newlines: core.NewlinesConfig{
AfterChangelogHeader: 1,
BeforeChangelogVersion: 1,
EndOfVersion: 1,
},
EnvPrefix: "CHANGIE_",
*/
}

headerPath := filepath.Join(config.ChangesDir, config.HeaderPath)
Expand Down
2 changes: 1 addition & 1 deletion cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func initConfig() *core.Config {
VersionFormat: "",
KindFormat: "",
ChangeFormat: "",
Kinds: []core.KindConfig{},
Kinds: []core.KindConfigOld{},
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (l *Latest) Run(cmd *cobra.Command, args []string) error {
}

if len(config.Projects) > 0 {
var pc *core.ProjectConfig
var pc *core.ProjectConfigOptions

pc, err = config.Project(l.Project)
pc, err = config.ProjectFromLabel(l.Project)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func latestConfig() *core.Config {
VersionFormat: "",
KindFormat: "",
ChangeFormat: "",
Kinds: []core.KindConfig{},
Kinds: []core.KindConfigOld{},
}
}

Expand Down Expand Up @@ -84,7 +84,7 @@ func TestLatestWithoutPrefix(t *testing.T) {

func TestLatestVersionWithProject(t *testing.T) {
cfg := latestConfig()
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "r project",
Key: "r",
Expand All @@ -111,7 +111,7 @@ func TestLatestVersionWithProject(t *testing.T) {

func TestLatestVersionWithBadProject(t *testing.T) {
cfg := latestConfig()
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "r project",
Key: "r",
Expand Down
2 changes: 1 addition & 1 deletion cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (m *Merge) Run(cmd *cobra.Command, args []string) error {
// If we have projects, merge all of them.
if len(cfg.Projects) > 0 {
for _, pc := range cfg.Projects {
err = m.mergeProject(cfg, pc.Key, pc.ChangelogPath, pc.Replacements)
err = m.mergeProject(cfg, pc.Key, pc.Changelog.Output, pc.Changelog.Replacements)
if err != nil {
return err
}
Expand Down
52 changes: 30 additions & 22 deletions cmd/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func mergeTestConfig() *core.Config {
VersionFormat: "## {{.Version}}",
KindFormat: "### {{.Kind}}",
ChangeFormat: "* {{.Body}}",
Kinds: []core.KindConfig{
Kinds: []core.KindConfigOld{
{Label: "added"},
{Label: "removed"},
{Label: "other"},
},
Newlines: core.NewlinesConfig{
Newlines: core.NewlinesConfigOld{
// BeforeVersion: 1,
// AfterVersion: 1,
AfterChange: 1,
Expand Down Expand Up @@ -73,16 +73,18 @@ func TestMergeVersionsSuccessfullyWithProject(t *testing.T) {
cfg := mergeTestConfig()
cfg.HeaderPath = ""
cfg.Replacements = nil
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "A thing",
Key: "a",
ChangelogPath: "a/thing/CHANGELOG.md",
Replacements: []core.Replacement{
{
Path: "a/VERSION",
Find: "version",
Replace: "{{.Version}}",
Label: "A thing",
Key: "a",
Changelog: core.ChangelogConfig{
Output: "a/thing/CHANGELOG.md",
Replacements: []core.Replacement{
{
Path: "a/VERSION",
Find: "version",
Replace: "{{.Version}}",
},
},
},
},
Expand Down Expand Up @@ -117,11 +119,13 @@ func TestMergeVersionsErrorMissingProjectDir(t *testing.T) {
cfg := mergeTestConfig()
cfg.HeaderPath = ""
cfg.Replacements = nil
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "A thing",
Key: "a",
ChangelogPath: "a/thing/CHANGELOG.md",
Label: "A thing",
Key: "a",
Changelog: core.ChangelogConfig{
Output: "a/thing/CHANGELOG.md",
},
},
}
then.WithTempDirConfig(t, cfg)
Expand Down Expand Up @@ -233,16 +237,20 @@ func TestMergeVersionsWithUnreleasedChangesInOneProject(t *testing.T) {
cfg := mergeTestConfig()
cfg.HeaderPath = ""
cfg.Replacements = nil
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "A thing",
Key: "a",
ChangelogPath: "a/thing/CHANGELOG.md",
Label: "A thing",
Key: "a",
Changelog: core.ChangelogConfig{
Output: "a/thing/CHANGELOG.md",
},
},
{
Label: "B thing",
Key: "b",
ChangelogPath: "b/thing/CHANGELOG.md",
Label: "B thing",
Key: "b",
Changelog: core.ChangelogConfig{
Output: "b/thing/CHANGELOG.md",
},
},
}
then.WithTempDirConfig(t, cfg)
Expand Down
4 changes: 2 additions & 2 deletions cmd/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func newTestConfig() *core.Config {
KindFormat: "### {{.Kind}}",
ChangeFormat: "* {{.Body}}",
EnvPrefix: "ENVPREFIX_",
Kinds: []core.KindConfig{
Kinds: []core.KindConfigOld{
{Label: "added"},
{Label: "removed"},
{Label: "other"},
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestErrorNewFragmentTemplate(t *testing.T) {

func TestNewOutputsToCmdOutWhenDry(t *testing.T) {
cfg := newTestConfig()
cfg.Kinds = []core.KindConfig{}
cfg.Kinds = []core.KindConfigOld{}
then.WithTempDirConfig(t, cfg)
reader, writer := then.WithReadWritePipe(t)

Expand Down
4 changes: 2 additions & 2 deletions cmd/next.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func (n *Next) Run(cmd *cobra.Command, args []string) error {
}

if len(config.Projects) > 0 {
var pc *core.ProjectConfig
var pc *core.ProjectConfigOptions

pc, err = config.Project(n.Project)
pc, err = config.ProjectFromLabel(n.Project)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/next_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func nextTestConfig() *core.Config {
VersionFormat: "",
KindFormat: "",
ChangeFormat: "",
Kinds: []core.KindConfig{},
Kinds: []core.KindConfigOld{},
}
}

Expand All @@ -47,7 +47,7 @@ func TestNextVersionWithPatch(t *testing.T) {
func TestNextVersionWithProject(t *testing.T) {
cfg := nextTestConfig()
cfg.ProjectsVersionSeparator = "|"
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "W things",
Key: "w",
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestNextVersionWithProject(t *testing.T) {
func TestNextVersionWithProjectBadProject(t *testing.T) {
cfg := nextTestConfig()
cfg.ProjectsVersionSeparator = "|"
cfg.Projects = []core.ProjectConfig{
cfg.Projects = []core.ProjectConfigOptions{
{
Label: "W things",
Key: "w",
Expand All @@ -101,7 +101,7 @@ func TestNextVersionWithProjectBadProject(t *testing.T) {

func TestNextVersionWithAuto(t *testing.T) {
cfg := nextTestConfig()
cfg.Kinds = []core.KindConfig{
cfg.Kinds = []core.KindConfigOld{
{
Label: "Feature",
AutoLevel: core.MinorLevel,
Expand Down
4 changes: 2 additions & 2 deletions core/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ func (change Change) WriteTo(writer io.Writer) (int64, error) {
return int64(n), err
}

func (change *Change) PostProcess(cfg *Config, kind *KindConfig) error {
func (change *Change) PostProcess(cfg *Config, kind *KindOptions) error {
postConfigs := make([]PostProcessConfig, 0)

if kind == nil || !kind.SkipGlobalPost {
if kind == nil || !kind.Skip.DefaultPost {
postConfigs = append(postConfigs, cfg.Post...)
}

Expand Down
4 changes: 2 additions & 2 deletions core/change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestSortByTime(t *testing.T) {

func TestSortByKindThenTime(t *testing.T) {
config := &Config{
Kinds: []KindConfig{
Kinds: []KindConfigOld{
{Label: "A"},
{Label: "B"},
},
Expand All @@ -129,7 +129,7 @@ func TestSortByKindThenTime(t *testing.T) {

func TestSortByComponentThenKind(t *testing.T) {
config := &Config{
Kinds: []KindConfig{
Kinds: []KindConfigOld{
{Label: "D"},
{Label: "E"},
},
Expand Down
Loading
Loading