From a4ef34ea107455709b76e8c5f31379261548abd5 Mon Sep 17 00:00:00 2001 From: pacificbelt30 <57101176+pacificbelt30@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:38:33 +0900 Subject: [PATCH] Corrected comments throughout the repository. --- cmd/main.go | 6 ++++-- internal/ai/openai.go | 1 + internal/github/github.go | 2 ++ internal/utils/utils.go | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index fef932e..e33c563 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,6 +34,7 @@ func main() { log.Ldate|log.Ltime|log.Llongfile|log.Lmsgprefix, ) + // Pre-define variables for error handling var err error // Read the configuration file @@ -42,10 +43,10 @@ func main() { logger.Fatalf("Error creating comment: %s", err) } - // Create GitHub Issues instance + // Create a GitHub Issues instance. From now on, you can control GitHub from this instance. issue := github.NewIssue(*owner, *repo, *issueNumber, *gh_token) - // Get Issue's info + // Get Issue's information(e.g. Title, Body) and add them to the user prompt except for comments by Actions. title, _ := issue.GetTitle() body, _ := issue.GetBody() if cfg.System.Debug.Log_level == "debug" { @@ -55,6 +56,7 @@ func main() { user_prompt := "Title:" + *title + "\n" user_prompt += "Body:" + *body + "\n" + // Get comments under the Issue and add them to the user prompt except for comments by Actions. comments, _ := issue.GetComments() for _, v := range comments { if *v.User.Login == "github-actions[bot]" { diff --git a/internal/ai/openai.go b/internal/ai/openai.go index 73fc8a7..fea6143 100644 --- a/internal/ai/openai.go +++ b/internal/ai/openai.go @@ -48,6 +48,7 @@ func NewOpenAIClient(apiKey string, model string) *OpenAI { fmt.Println("Error: OPENAI_API_KEY environment variable not set.") return nil } + // Specifying the model to use return &OpenAI{ apiKey: apiKey, diff --git a/internal/github/github.go b/internal/github/github.go index e0d7e84..98f6cce 100644 --- a/internal/github/github.go +++ b/internal/github/github.go @@ -21,6 +21,7 @@ type GitHubIssues struct { } func (gh *GitHubIssues) GetIssue() (*github.Issue, error) { + // Only the first call retrieves information from GitHub, all other calls use cache if gh.cache == nil { issue, _, err := gh.client.Issues.Get(gh.ctx, gh.owner, gh.repo, gh.issueNumber) if err != nil { @@ -82,6 +83,7 @@ func NewIssue(owner string, repo string, issueNumber int, token string) *GitHubI log.Ldate|log.Ltime|log.Llongfile|log.Lmsgprefix, ) + // Create a new GitHubIssues instance issue := &GitHubIssues{owner: owner, repo: repo, issueNumber: issueNumber, token: token, client: client, ctx: ctx, logger: logger} return issue } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 364aac6..5526293 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/viper" ) +// Root structure of information read from config file type Config struct { System System `yaml:"system"` Ai Ai `yaml:"ai"` @@ -54,6 +55,7 @@ func NewConfig(filename string) (*Config, error) { // Get the directory and file name from variable filename dir, file := filepath.Split(filename) base, ext := filepath.Base(file)[:len(filepath.Base(file))-len(filepath.Ext(file))], filepath.Ext(file)[1:] + // Read the config file viper.SetConfigName(base) viper.SetConfigType(ext)