diff --git a/cmd/release-tool/changelog.go b/cmd/release-tool/changelog.go index e6e5d68..0525724 100644 --- a/cmd/release-tool/changelog.go +++ b/cmd/release-tool/changelog.go @@ -46,6 +46,16 @@ 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\n")) for _, release := range res { if !release.IsReleased() { // If the release is not an actual release don't add in changelog.md @@ -53,6 +63,9 @@ var autoChangelog = &cobra.Command{ } 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 @@ -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", @@ -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") } diff --git a/cmd/release-tool/main.go b/cmd/release-tool/main.go index d6127d5..719e0f9 100644 --- a/cmd/release-tool/main.go +++ b/cmd/release-tool/main.go @@ -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{ diff --git a/go.mod b/go.mod index 2d1a395..4cb2583 100644 --- a/go.mod +++ b/go.mod @@ -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