Skip to content

Commit

Permalink
changelog utility for merging stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nfuden committed Nov 21, 2024
1 parent f51fc89 commit 8e69f31
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
4 changes: 4 additions & 0 deletions changelog/v0.27.2/expose-morechangelogstuff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: NON_USER_FACING
description: >
Expose a feature of changelogutils to allow for more control over the changelog outputs
46 changes: 39 additions & 7 deletions changeloggenutils/minor_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,55 @@ func NewMinorReleaseGroupedChangelogGenerator(opts Options, client *github.Clien
}
}

// Entry point for generating changelog JSON
func (g *MinorReleaseGroupedChangelogGenerator) GenerateJSON(ctx context.Context) (string, error) {
type changelogOutput struct {
Opts Options
ReleaseData *ReleaseData
}

// AddReleaseData without overriding the options.
// Only adopt info that is not already present in the output.
func (c changelogOutput) AddReleaseData(donorOutput changelogOutput) error {
if donorOutput.ReleaseData == nil {
return fmt.Errorf("donorOutput ReleaseData is nil")
}
for k, v := range donorOutput.ReleaseData.Releases {
if c.ReleaseData.Releases[k] == nil {
c.ReleaseData.Releases[k] = v
}
}
return nil
}

// GenerateJSON from a changelogoutput.
// This simply marches the output to a JSON string.
func (c changelogOutput) GenerateJSON() (string, error) {
res, err := json.Marshal(c)
return string(res), err
}

func (g *MinorReleaseGroupedChangelogGenerator) AddToOutput(ctx context.Context) (changelogOutput, error) {
var out changelogOutput
var err error
releaseData, err := g.GetReleaseData(ctx, g.opts.MainRepoReleases)
if err != nil {
return "", err
}
var out struct {
Opts Options
ReleaseData *ReleaseData
return out, err
}

out.Opts = Options{
RepoOwner: g.opts.RepoOwner,
MainRepo: g.opts.MainRepo,
DependentRepo: g.opts.DependentRepo,
}
out.ReleaseData = releaseData
return out, nil
}

// Entry point for generating changelog JSON
func (g *MinorReleaseGroupedChangelogGenerator) GenerateJSON(ctx context.Context) (string, error) {
out, err := g.AddToOutput(ctx)
if err != nil {
return "", err
}
res, err := json.Marshal(out)
return string(res), err
}
Expand Down

0 comments on commit 8e69f31

Please sign in to comment.