diff --git a/.changes/unreleased/added-20240907-165020.yaml b/.changes/unreleased/added-20240907-165020.yaml new file mode 100644 index 00000000..e89b76c1 --- /dev/null +++ b/.changes/unreleased/added-20240907-165020.yaml @@ -0,0 +1,5 @@ +kind: added +body: KindKey and KindLabel values to Change data to be used in formats +time: 2024-09-07T16:50:20.010876435-07:00 +custom: + Issue: "706" diff --git a/core/change.go b/core/change.go index 21e358f8..3c53e03b 100644 --- a/core/change.go +++ b/core/change.go @@ -52,7 +52,8 @@ type Change struct { Project string `yaml:",omitempty" default:""` // Component of our change, if one was provided. Component string `yaml:",omitempty" default:""` - // Kind of our change, if one was provided. + // Kind key of our change, if one was provided. + // Backwards compatible alias for [KindKey]. Kind string `yaml:",omitempty" default:""` // Body message of our change, if one was provided. Body string `yaml:",omitempty" default:""` @@ -74,6 +75,10 @@ type Change struct { Env map[string]string `yaml:"-" default:"nil"` // Filename the change was saved to. Filename string `yaml:"-"` + // Kind key of our change, if one was provided. + KindKey string `yaml:"-" default:""` + // Kind label of our change, if one was provided. + KindLabel string `yaml:"-" default:""` } // WriteTo will write a change to the writer as YAML @@ -130,6 +135,7 @@ func LoadChange(path string) (Change, error) { } c.Filename = path + c.KindKey = c.Kind return c, nil } diff --git a/core/config.go b/core/config.go index 89e67cac..786c0c8c 100644 --- a/core/config.go +++ b/core/config.go @@ -268,7 +268,7 @@ type Config struct { // The default uses the component and kind only if configured for your project. // The file is placed in the unreleased directory, so the full path is: // - // "{{.ChangesDir}}/{{.UnreleasedDir}}/{{.FragmentFileFormat}}.yaml" + // `{{.ChangesDir}}/{{.UnreleasedDir}}/{{.FragmentFileFormat}}.yaml` // example: yaml // fragmentFileFormat: "{{.Kind}}-{{.Custom.Issue}}" FragmentFileFormat string `yaml:"fragmentFileFormat,omitempty" default:"{{.Project}}-{{.Component}}-{{.Kind}}-{{.Time.Format \"20060102-150405\"}}" templateType:"Change"` diff --git a/core/utils.go b/core/utils.go index 8645797c..b20eecc6 100644 --- a/core/utils.go +++ b/core/utils.go @@ -306,6 +306,12 @@ func GetChanges( } c.Env = cfg.EnvVars() + + kc := cfg.KindFromKeyOrLabel(c.KindKey) + if kc != nil { + c.KindLabel = kc.Label + } + changes = append(changes, c) } diff --git a/core/utils_test.go b/core/utils_test.go index 9895dd2e..6d38c402 100644 --- a/core/utils_test.go +++ b/core/utils_test.go @@ -641,6 +641,8 @@ func TestGetAllChangesWithProject(t *testing.T) { Key: "web_hook_sender", }, } + cfg.Kinds[0].Key = "added" + cfg.Kinds[0].Label = "Added Label" changes := []Change{ {Kind: "added", Body: "first", Project: "web_hook_sender"}, @@ -656,6 +658,10 @@ func TestGetAllChangesWithProject(t *testing.T) { then.Equals(t, 2, len(changes)) then.Equals(t, "first", changes[0].Body) then.Equals(t, "second", changes[1].Body) + then.Equals(t, "added", changes[0].KindKey) + then.Equals(t, "added", changes[1].KindKey) + then.Equals(t, "Added Label", changes[0].KindLabel) + then.Equals(t, "Added Label", changes[1].KindLabel) } func TestFileExists(t *testing.T) {