Skip to content

Commit

Permalink
fix!: remove ai changelog generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Feb 12, 2025
1 parent 1b4c1aa commit 5d9ebdb
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 89 deletions.
5 changes: 0 additions & 5 deletions extension/shopware-extension-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
"default": false,
"description": "Enables the changelog generation."
},
"ai_enabled": {
"type": "boolean",
"default": false,
"description": "Enables the changelog generation with OpenAI (Requires OPENAI_TOKEN environment variable)."
},
"pattern": {
"type": "string",
"default": "",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/microcosm-cc/bluemonday v1.0.27
github.com/olekukonko/tablewriter v0.0.5
github.com/otiai10/copy v1.14.1
github.com/sashabaranov/go-openai v1.37.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0
github.com/tetratelabs/wazero v1.8.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sashabaranov/go-openai v1.37.0 h1:hQQowgYm4OXJ1Z/wTrE+XZaO20BYsL0R3uRPSpfNZkY=
github.com/sashabaranov/go-openai v1.37.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/shyim/go-htmlprinter v0.0.0-20250212091723-cc11f7bf036d h1:H4beXhaWS4edAoYRzbdszvIfL9bHt4jUbGgt5G+QdGY=
github.com/shyim/go-htmlprinter v0.0.0-20250212091723-cc11f7bf036d/go.mod h1:7pOn8MeVA6hUnFkgkXpNFVjGtNnh2/AeZTDwXwWtNp8=
github.com/shyim/go-mad v0.0.0-20250212101107-a15f8dde1bce h1:xQidim5dm481TchU2tzi7SjQwfmD6ombHKPHFsUL8Z4=
Expand Down
51 changes: 2 additions & 49 deletions internal/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"context"
_ "embed"
"fmt"
"os"
"regexp"
"strings"
"text/template"

"github.com/sashabaranov/go-openai"

"github.com/shopware/shopware-cli/internal/git"
)

Expand Down Expand Up @@ -94,15 +91,9 @@ func renderChangelog(commits []git.GitCommit, cfg Config) (string, error) {

templateParsed := template.Must(template.New("changelog").Parse(cfg.Template))

aiMessage, err := generateAiMessage(changelog, cfg)
if err != nil {
return "", fmt.Errorf("failed to generate AI message: %v", err)
}

templateContext := map[string]interface{}{
"Commits": changelog,
"Config": cfg,
"AiSummarize": aiMessage,
"Commits": changelog,
"Config": cfg,
}

var buf bytes.Buffer
Expand All @@ -112,41 +103,3 @@ func renderChangelog(commits []git.GitCommit, cfg Config) (string, error) {

return strings.Trim(buf.String(), "\n"), nil
}

func generateAiMessage(changelog []Commit, cfg Config) (string, error) {
if !cfg.AiEnabled {
return "", nil
}

aiRequestBody := ""

for _, commit := range changelog {
aiRequestBody += commit.Message + "\n"
}

aiRequestBody += "Please summarize the changelog into 1-2 sentences and ignore chore or build things"

client := openai.NewClient(os.Getenv("OPENAI_TOKEN"))
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Stream: false,
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: aiRequestBody,
},
},
},
)
if err != nil {
return "", err
}

if len(resp.Choices) > 0 {
return resp.Choices[0].Message.Content, nil
}

return "", fmt.Errorf("got no response from openai: %w", err)
}
32 changes: 0 additions & 32 deletions internal/changelog/changelog_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changelog

import (
"os"
"testing"

"github.com/shopware/shopware-cli/internal/git"
Expand Down Expand Up @@ -69,34 +68,3 @@ func TestIncludeFilters(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "- [NEXT-1234 - Fooo](/1234567890)", changelog)
}

func TestLetAiGenerateText(t *testing.T) {
if os.Getenv("OPENAI_TOKEN") == "" {
t.Skip("Need OPENAI_TOKEN env")
}

commits := []git.GitCommit{
{
Message: "fix: task checker interval compare minutes instead of months",
Hash: "1234567890",
},
{
Message: "fix: correct detection of delayed scheduled tasks (#197)",
Hash: "1234567890",
},
{
Message: "feature: read messenger stats from transports",
Hash: "123",
},
}

cfg := Config{
AiEnabled: true,
Template: defaultChangelogTpl,
}

changelog, err := renderChangelog(commits, cfg)

assert.NoError(t, err)
assert.Contains(t, changelog, "Commits:")
}

0 comments on commit 5d9ebdb

Please sign in to comment.