diff --git a/src/comments/comments.go b/src/comments/comments.go index 553aed1..2221711 100644 --- a/src/comments/comments.go +++ b/src/comments/comments.go @@ -7,6 +7,7 @@ import ( files "github.com/gbh-tech/github-pr-commenter/src/utils" + "github.com/charmbracelet/log" "github.com/google/go-github/v61/github" ) @@ -18,7 +19,7 @@ type GithubClient struct { // NewClient creates a new GithubClient with the provided token func NewClient(token string, client *GithubClient) error { if token == "" { - return fmt.Errorf("unauthorized: no token present") + return fmt.Errorf("Unauthorized: GitHub Token not present.") } client.Ctx = context.Background() client.Client = github.NewClient(nil).WithAuthToken(token) @@ -28,7 +29,7 @@ func NewClient(token string, client *GithubClient) error { func (client *GithubClient) GetUserComments(pull int, org, repo, content, filePath string) (int64, error) { comments, _, err := client.Client.Issues.ListComments(client.Ctx, org, repo, pull, nil) if err != nil { - return 0, fmt.Errorf("error listing comments: %v", err) + return 0, fmt.Errorf("PR ID: %v\nError listing comments: %v", pull, err) } commentBody := files.GetCommentBody(content, filePath) @@ -38,7 +39,7 @@ func (client *GithubClient) GetUserComments(pull int, org, repo, content, filePa } } - return 0, fmt.Errorf("comment not found") + return 0, fmt.Errorf("PR ID: %v\nComment not found", pull) } func (client *GithubClient) CreateComment(pull int, org, repo, content, filePath string) (*github.IssueComment, error) { @@ -47,8 +48,9 @@ func (client *GithubClient) CreateComment(pull int, org, repo, content, filePath commentResp, _, err := client.Client.Issues.CreateComment(client.Ctx, org, repo, pull, comment) if err != nil { - return nil, fmt.Errorf("error creating comment: %v", err) + return nil, fmt.Errorf("PR ID: %v\nError creating comment: %v", pull, err) } + log.Info("Comment Created successfully") return commentResp, nil } @@ -59,8 +61,9 @@ func (client *GithubClient) UpdateComment(commentID int64, org, repo, content, f commentResp, _, err := client.Client.Issues.EditComment(client.Ctx, org, repo, commentID, comment) if err != nil { - return nil, fmt.Errorf("error updating comment: %v", err) + return nil, fmt.Errorf("Comment ID: %v\nError updating comment: %v", commentID, err) } + log.Info("Comment updated successfully") return commentResp, nil }