Skip to content

Commit

Permalink
feat(changelog.md): merge changelog from repo and childRepo
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Dziedziak <[email protected]>
  • Loading branch information
lukidzi committed Jan 14, 2025
1 parent 00cd1cc commit fb96563
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
22 changes: 22 additions & 0 deletions cmd/release-tool/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,26 @@ var autoChangelog = &cobra.Command{
}
return res[i].PublishedAt.After(res[j].PublishedAt)
})
childReleases := map[string]github.GQLRelease{}
if config.childRepo != "" {
childResources, err := gqlClient.ReleaseGraphQL(config.childRepo)
if err != nil {
return err
}
for _, release := range childResources {
childReleases[release.Name] = release
}
}
_, _ = cmd.OutOrStdout().Write([]byte("# Changelog\n<!-- Autogenerated with (github.com/kumahq/ci-tools) release-tool changelog.md -->\n"))
for _, release := range res {
if !release.IsReleased() { // If the release is not an actual release don't add in changelog.md
continue
}
if strings.Contains(release.Description, "## Changelog") {
changelog := strings.SplitN(release.Description, "## Changelog", 2)[1]
if childChangelog, found := getChildChangelog(release, childReleases); found {
changelog += childChangelog
}
_, _ = cmd.OutOrStdout().Write([]byte(fmt.Sprintf(`
## %s
> Released on %s%s
Expand All @@ -64,6 +77,14 @@ var autoChangelog = &cobra.Command{
},
}

func getChildChangelog(release github.GQLRelease, childReleases map[string]github.GQLRelease) (string, bool) {
childRelease, found := childReleases[release.Name]
if !found || !childRelease.IsReleased() || !strings.Contains(release.Description, "## Changelog") { // If the release is not an actual release don't add in changelog.md
return "", false
}
return strings.SplitN(childRelease.Description, "## Changelog", 2)[1], true
}

var versionChangelog = &cobra.Command{
Use: "version-changelog",
Short: "Generate the changelog for a specific release using the github graphql api",
Expand Down Expand Up @@ -147,4 +168,5 @@ func init() {
versionChangelog.Flags().StringVar(&config.format, "format", string(FormatMarkdown), fmt.Sprintf("The output format (%s, %s)", FormatJson, FormatMarkdown))
versionChangelog.Flags().StringVar(&config.repo, "repo", "kumahq/kuma", "The repository to query")
autoChangelog.Flags().StringVar(&config.repo, "repo", "kumahq/kuma", "The repository to query")
autoChangelog.Flags().StringVar(&config.childRepo, "childRepo", "", "The child repository to query")
}
11 changes: 6 additions & 5 deletions cmd/release-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ func main() {
var config Config

type Config struct {
branch string
repo string
fromTag string
format string
release string
branch string
repo string
childRepo string
fromTag string
format string
release string
}

var rootCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kumahq/ci-tools

go 1.22
go 1.23.4

require (
github.com/Masterminds/semver/v3 v3.3.1
Expand Down

0 comments on commit fb96563

Please sign in to comment.