Skip to content

Commit fae8178

Browse files
author
{cocoide}
committed
- Update suggestCmd to generate multiple commit messages asynchronously
1 parent 7ae38ee commit fae8178

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

cmd/suggest.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (m model) View() string {
6565
b.WriteString(fmt.Sprintf(" %s\n", choice))
6666
}
6767
}
68-
69-
b.WriteString("\nUse the arrow keys to navigate and press Enter to select.")
68+
green := color.New(color.FgGreen).SprintFunc()
69+
b.WriteString(green("\nUse the arrow keys to navigate and press Enter to select."))
7070
return b.String()
7171
}
7272

@@ -79,13 +79,14 @@ var suggestCmd = &cobra.Command{
7979
ctx := context.Background()
8080
og := gateway.NewOpenAIGateway(ctx)
8181
ms := service.NewMessageService(og)
82-
msgCh, err := ms.AsyncGenerateCommitMessage()
82+
messages, err := ms.AsyncGenerateCommitMessage()
8383
if err != nil {
8484
log.Fatal(err.Error())
8585
}
86-
suggestMsg := <-msgCh
87-
fmt.Println(suggestMsg)
88-
choices := []string{suggestMsg, "!", "!#!"}
86+
var choices []string
87+
for _, v := range messages {
88+
choices = append(choices, v)
89+
}
8990
m := model{choices: choices}
9091
p := tea.NewProgram(m)
9192
p.Run()

internal/service/message.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ package service
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/cocoide/commitify/internal/gateway"
78
"github.com/cocoide/commitify/util"
89
)
910

1011
const (
11-
CommitMessagePrompt = "Generate 3 commit messages for [%s], each message separated by a comma and a space"
12+
CommitMessagePrompt = "Generate commit messages for [%s]. Each message should be separated by only space"
1213
FormatNotice = ", format commit as:\n- feat: [feature description]\n- bugfix: [bugfix description]"
1314
)
1415

1516
// メッセージの生成、加工に関するクラス
1617
type MessageService interface {
17-
AsyncGenerateCommitMessage() (<-chan string, error)
18+
AsyncGenerateCommitMessage() ([]string, error)
1819
}
1920

2021
type messageService struct {
@@ -25,13 +26,14 @@ func NewMessageService(og gateway.OpenAIGateway) MessageService {
2526
return &messageService{og: og}
2627
}
2728

28-
func (s *messageService) AsyncGenerateCommitMessage() (<-chan string, error) {
29+
func (s *messageService) AsyncGenerateCommitMessage() ([]string, error) {
2930
var result <-chan string
3031
stagingCode := util.ExecGetStagingCode()
3132
if len(stagingCode) < 1 {
3233
return nil, fmt.Errorf("There is no staging code")
3334
}
3435
prompt := fmt.Sprintf(CommitMessagePrompt, string(stagingCode))
3536
result = s.og.AsyncGetAnswerFromPrompt(prompt, 0.01)
36-
return result, nil
37+
messages := strings.Split(<-result, "\n")
38+
return messages, nil
3739
}

0 commit comments

Comments
 (0)