Skip to content

Commit

Permalink
Also use pointers for components
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrizic committed May 13, 2024
1 parent 7283458 commit a3866ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion changelog/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (clg *ChangelogGenerator) Generate(ctx context.Context) (changelog *output.
Releases: &[]output.Release{
{
Tag: "0.0.0",
Components: []output.Component{},
Components: &[]output.Component{},
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions changelog/output/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type Component struct {
}

type Release struct {
Tag string `json:"tag"`
Components []Component `json:"components"`
Tag string `json:"tag"`
Components *[]Component `json:"components"`
}

type Changelog struct {
Expand All @@ -36,7 +36,7 @@ func (c *Changelog) AddEntry(entry Entry) {
// no releaes, create it anyways
*c.Releases = append(*c.Releases, Release{
Tag: entry.Tag,
Components: []Component{}})
Components: &[]Component{}})
} else {
// find the right place to insert the release
for _, r := range *c.Releases {
Expand All @@ -50,7 +50,7 @@ func (c *Changelog) AddEntry(entry Entry) {
// add release before the current release
*c.Releases = append(*c.Releases, Release{
Tag: entry.Tag,
Components: []Component{}})
Components: &[]Component{}})
}
break
}
Expand All @@ -59,7 +59,7 @@ func (c *Changelog) AddEntry(entry Entry) {
// find the right release and add the component
for i, release := range *c.Releases {
if release.Tag == entry.Tag {
(*c.Releases)[i].Components = append((*c.Releases)[i].Components, Component{
*(*c.Releases)[i].Components = append(*(*c.Releases)[i].Components, Component{
Name: entry.Component,
Description: entry.Description,
})
Expand Down
12 changes: 6 additions & 6 deletions changelog/output/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ func TestChangelog_AddEntry(t *testing.T) {
t.Errorf("expected 3 releases, got %d", len(*changelog.Releases))
}

if len((*changelog.Releases)[0].Components) != 1 {
t.Errorf("expected 2 components, got %d", len((*changelog.Releases)[0].Components))
if len(*(*changelog.Releases)[0].Components) != 1 {
t.Errorf("expected 2 components, got %d", len(*(*changelog.Releases)[0].Components))
}

if len((*changelog.Releases)[1].Components) != 2 {
t.Errorf("expected 2 components, got %d", len((*changelog.Releases)[1].Components))
if len(*(*changelog.Releases)[1].Components) != 2 {
t.Errorf("expected 2 components, got %d", len(*(*changelog.Releases)[1].Components))
}

if len((*changelog.Releases)[2].Components) != 2 {
t.Errorf("expected 1 component, got %d", len((*changelog.Releases)[2].Components))
if len(*(*changelog.Releases)[2].Components) != 2 {
t.Errorf("expected 1 component, got %d", len(*(*changelog.Releases)[2].Components))
}

// expect that the first release is 1.2.0
Expand Down

0 comments on commit a3866ce

Please sign in to comment.