Skip to content

Commit

Permalink
KindKey and KindLabel values to Change data to be used in formats
Browse files Browse the repository at this point in the history
  • Loading branch information
miniscruff committed Sep 7, 2024
1 parent 0f99293 commit 453b3f4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/added-20240907-165020.yaml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 7 additions & 1 deletion core/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:""`
Expand All @@ -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
Expand Down Expand Up @@ -130,6 +135,7 @@ func LoadChange(path string) (Change, error) {
}

c.Filename = path
c.KindKey = c.Kind

return c, nil
}
2 changes: 1 addition & 1 deletion core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions core/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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) {
Expand Down

0 comments on commit 453b3f4

Please sign in to comment.