Skip to content

Commit

Permalink
chore: (DSO-2004) Improve debug experience on githubComments package
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercm1410 committed Jul 15, 2024
1 parent e6ed3bf commit 7a22e49
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/comments/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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
}
Expand All @@ -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
}

0 comments on commit 7a22e49

Please sign in to comment.