From 5df5a3e70ac9ee45cf3f638b25e455fa51b6acb0 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Thu, 19 Oct 2023 14:39:01 +0200 Subject: [PATCH] feat: add changelog extraction command --- cmd/extension/extension_changelog.go | 60 ++++++++++++++++++++++++++++ extension/zip.go | 2 + 2 files changed, 62 insertions(+) create mode 100644 cmd/extension/extension_changelog.go diff --git a/cmd/extension/extension_changelog.go b/cmd/extension/extension_changelog.go new file mode 100644 index 00000000..31f6a6fb --- /dev/null +++ b/cmd/extension/extension_changelog.go @@ -0,0 +1,60 @@ +package extension + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/spf13/cobra" + + "github.com/FriendsOfShopware/shopware-cli/extension" +) + +var extensionChangelogCmd = &cobra.Command{ + Use: "changelog [path]", + Short: "Get the changelog", + Args: cobra.MinimumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + path, err := filepath.Abs(args[0]) + if err != nil { + return fmt.Errorf("cannot find path: %w", err) + } + + stat, err := os.Stat(path) + if err != nil { + return fmt.Errorf("cannot find path: %w", err) + } + + var ext extension.Extension + + if stat.IsDir() { + ext, err = extension.GetExtensionByFolder(path) + } else { + ext, err = extension.GetExtensionByZip(path) + } + + if err != nil { + return fmt.Errorf("changelog: cannot open extension %w", err) + } + + changelog, err := ext.GetChangelog() + if err != nil { + return fmt.Errorf("cannot generate changelog: %w", err) + } + + isGermanChangelog, _ := cmd.PersistentFlags().GetBool("german") + + if isGermanChangelog { + fmt.Println(changelog.German) + } else { + fmt.Println(changelog.English) + } + + return nil + }, +} + +func init() { + extensionRootCmd.AddCommand(extensionChangelogCmd) + extensionChangelogCmd.PersistentFlags().Bool("german", false, "Get the german changelog") +} diff --git a/extension/zip.go b/extension/zip.go index af6fe946..2d1a988e 100644 --- a/extension/zip.go +++ b/extension/zip.go @@ -456,6 +456,8 @@ func PrepareExtensionForRelease(ctx context.Context, sourceRoot, extensionRoot s if ext.GetExtensionConfig().Changelog.Enabled { v, _ := ext.GetVersion() + logging.FromContext(ctx).Infof("Generated changelog for version %s", v.String()) + content, err := changelog.GenerateChangelog(ctx, sourceRoot, ext.GetExtensionConfig().Changelog) if err != nil { return err