Skip to content

Commit 72ef49a

Browse files
committed
docs: make code comments more informative
1 parent da7c187 commit 72ef49a

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

cmd/commitmsg/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// CLI tool to get staged changes in a git repository and print them to the console
1+
// CLI tool to generate AI-powered commit messages based on staged changes.
22
package main
33

44
import (
@@ -48,8 +48,9 @@ func runCommitMsg(_ *cobra.Command, _ []string) error {
4848
return nil
4949
}
5050

51+
// Add examples of previous commit messages to context if the flag is set
5152
latestCommitMessages := ""
52-
if flagExamples{
53+
if flagExamples {
5354
latestCommitMessages, err = git.GetCommitMessages(3)
5455
if err != nil {
5556
return fmt.Errorf("failed to get latest commit messages: %w", err)

internal/git/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os/exec"
77
)
88

9-
// GetStagedChanges executes the command git diff --staged and returns its output
9+
// GetStainedChanges returns the staged changes (git diff --staged) as a string.
1010
func GetStagedChanges() (string, error) {
1111
// Check if we are in a git repository
1212
if !isGitRepository() {
@@ -23,7 +23,7 @@ func GetStagedChanges() (string, error) {
2323
return string(output), nil
2424
}
2525

26-
// GetCommitMessages retrieves the last <count> commit messages from the git repository
26+
// GetCommitMessages retrieves the last <count> commit messages from the git repository.
2727
func GetCommitMessages(count int) (string, error) {
2828
// Check if we are in a git repository
2929
if !isGitRepository() {

internal/llm/client.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,27 @@ import (
1818
//go:embed commitmsg.prompt.yml
1919
var commitmsgPromptYAML []byte
2020

21-
// PromptConfig represents the structure of the prompt configuration file
22-
// It includes the model parameters and the messages to be sent to the model.
21+
// PromptConfig represents the structure of the prompt configuration file.
2322
type PromptConfig struct {
2423
Name string `yaml:"name"`
2524
Description string `yaml:"description"`
2625
ModelParameters ModelParameters `yaml:"modelParameters"`
2726
Messages []PromptMessage `yaml:"messages"`
2827
}
2928

30-
// ModelParameters defines the parameters for the model
29+
// ModelParameters defines the parameters for the large language model.
3130
type ModelParameters struct {
3231
Temperature float64 `yaml:"temperature"`
3332
TopP float64 `yaml:"topP"`
3433
}
3534

36-
// PromptMessage represents a single message in the prompt configuration
35+
// PromptMessage represents a single message in the prompt configuration.
3736
type PromptMessage struct {
3837
Role string `yaml:"role"`
3938
Content string `yaml:"content"`
4039
}
4140

42-
// Request represents the structure of the request to the GitHub Models API
41+
// Request represents the request payload for the GitHub Models API.
4342
type Request struct {
4443
Messages []Message `json:"messages"`
4544
Model string `json:"model"`
@@ -48,13 +47,13 @@ type Request struct {
4847
Stream bool `json:"stream"`
4948
}
5049

51-
// Message represents a single message in the request to the GitHub Models API
50+
// Message represents a single message in the request payload.
5251
type Message struct {
5352
Role string `json:"role"`
5453
Content string `json:"content"`
5554
}
5655

57-
// Response represents the structure of the response from the GitHub Models API
56+
// Response represents the response payload from the GitHub Models API.
5857
type Response struct {
5958
Choices []struct {
6059
Message struct {
@@ -68,8 +67,8 @@ type Client struct {
6867
token string
6968
}
7069

71-
// NewClient initializes a new GitHub Models API client
72-
// It retrieves the GitHub token from the environment installed by the `gh` CLI tool.
70+
// NewClient initializes a new GitHub Models API client.
71+
// It retrieves the GitHub token using gh auth token command.
7372
func NewClient() (*Client, error) {
7473
fmt.Print(" Checking GitHub token... ")
7574

@@ -100,6 +99,7 @@ func (c *Client) GenerateCommitMessage(
10099
}
101100
fmt.Println("Done")
102101

102+
// Build messages from the prompt config, replacing template variables
103103
selectedModel := model
104104
selectedLanguage := language
105105

@@ -125,6 +125,7 @@ func (c *Client) GenerateCommitMessage(
125125
}
126126
}
127127

128+
// Prepare the request for the GitHub Models API
128129
request := Request{
129130
Messages: messages,
130131
Model: selectedModel,
@@ -141,6 +142,7 @@ func (c *Client) GenerateCommitMessage(
141142
}
142143
fmt.Println("Done")
143144

145+
// Extract the generated commit message from the response
144146
if len(response.Choices) == 0 {
145147
return "", fmt.Errorf("no response generated from the model")
146148
}

0 commit comments

Comments
 (0)