Skip to content

Commit

Permalink
feat: add changelog extraction command
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Oct 19, 2023
1 parent 52b774e commit 5df5a3e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions cmd/extension/extension_changelog.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 2 additions & 0 deletions extension/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5df5a3e

Please sign in to comment.