Skip to content

Commit 2e4ffe0

Browse files
refactor: Refactor commit message printing and improve user interaction.
1 parent b75708e commit 2e4ffe0

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

main.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func main() {
3434
if err != nil {
3535
explain, err := explainError(context.Background(), client, err)
3636
if err != nil {
37-
printError("failed to explain error: " + err.Error())
37+
printError(err.Error())
3838
os.Exit(1)
3939
}
4040
printError(explain)
@@ -45,37 +45,41 @@ func main() {
4545
if isDirty() {
4646
fmt.Println("Please stage your changes and try again")
4747
} else {
48-
fmt.Println("Nothing to commit")
48+
fmt.Println("Nothing to commit, working tree clean")
4949
}
50+
5051
os.Exit(0)
5152
}
5253

5354
commitMessage := ""
55+
// loop until the commit message is generated
5456
for {
5557
ctx, _ := context.WithTimeout(context.Background(), time.Second*10)
5658
messages = append(messages, &Message{
5759
Role: "user",
5860
Content: diff,
5961
})
6062

63+
// generate commit message
6164
printNormal("Assistant: " + generateLoadingMessage())
6265
commitMessage, err = client.ChatComplete(ctx, messages)
6366
if err != nil {
6467
explain, err := explainError(ctx, client, err)
6568
if err != nil {
66-
printError("failed to explain error: " + err.Error())
69+
printError(err.Error())
6770
os.Exit(1)
6871
}
6972
printError(explain)
7073
os.Exit(1)
7174
}
7275

7376
if commitMessage == "" {
74-
printNormal("No commit message generated, please try again")
77+
printNormal("Assistant: I don't know what to say about this diff, please give me a hint")
7578
} else {
7679
printNormal("Assistant: " + commitMessage)
7780
}
7881

82+
// Loop until the user response
7983
userRequest := ""
8084
for {
8185
fmt.Println("Assistant: " + generateInteractiveMessage())
@@ -85,7 +89,7 @@ func main() {
8589
if err != nil {
8690
explain, err := explainError(ctx, client, err)
8791
if err != nil {
88-
printError("failed to explain error: " + err.Error())
92+
printError(err.Error())
8993
os.Exit(1)
9094
}
9195
printError(explain)
@@ -95,7 +99,7 @@ func main() {
9599
userRequest = strings.TrimSpace(userRequest)
96100

97101
if userRequest == "" {
98-
printWarning("Please enter your response, say yes if you want to use the message or press Ctrl+C to exit")
102+
printWarning("Assistant: Please enter your response, say yes if you want to use the message or press Ctrl+C to exit")
99103
continue
100104
}
101105

@@ -121,11 +125,11 @@ func main() {
121125
commitMessage = joinPrefix(prefix, commitMessage)
122126

123127
if err := commit(commitMessage); err != nil {
124-
printError("failed to commit: " + err.Error())
128+
printError("Assistant: failed to commit: " + err.Error())
125129
os.Exit(1)
126130
}
127131

128-
printSuccess("Commit successfully with message: " + commitMessage)
132+
printSuccess("Assistant: Commit successfully with message: " + commitMessage)
129133
}
130134

131135
func joinPrefix(prefix string, message string) string {

0 commit comments

Comments
 (0)