-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
executable file
·59 lines (53 loc) · 1.58 KB
/
main.go
File metadata and controls
executable file
·59 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
)
func main() {
stats := flag.Bool("stats", false, "display stats")
ask := flag.String("ask", "", "ask a question")
//use github.com/spf13/cobra if more feature are needed
flag.Parse()
if *ask != "" {
response, err := getChatCompletionResponse(getPrompt(*ask))
if err != nil {
fmt.Printf("Error: %v\n", err)
} else {
fmt.Println(response)
}
}
if *stats {
fmt.Println("Usage: gh-commit")
numCommits, wordCount, err := getCommitStats()
hoursSaved := calculateTimeSaved(numCommits, wordCount)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
} else {
emoji := "🤖"
message := fmt.Sprintf(
"Git commit stats:\n"+
"Number of commits: %d\n"+
"Number of words in the commit message: %d\n"+
"Format the git commit stats data and figure out profound insights on how writing these commit messages by AI is saving human hours? Use relevant emojis, use real-world stats in calculations and explain.\n"+
"If all commit messages were written by %s, you would have saved %.1f hours! %s",
numCommits, wordCount, "AI", hoursSaved, emoji)
completionResponse, err := getChatCompletionResponse(getPrompt(message))
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(completionResponse)
}
}
if flag.NFlag() == 0 {
diff, err := getGitDiff()
completionResponse, err := getChatCompletionResponse(getDiffPrompt(diff))
completionResponse = formatResponse(completionResponse)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(completionResponse)
}
}