| 64 | } |
| 65 | |
| 66 | func (g *githubClient) listComments(repo, pr string) ([]comment, error) { |
| 67 | url := fmt.Sprintf("%s/repos/%s/issues/%s/comments", g.apiURL, repo, pr) |
| 68 | req, err := http.NewRequest("GET", url, nil) |
| 69 | if err != nil { |
| 70 | return nil, errors.Wrap(err, "failed to create request") |
| 71 | } |
| 72 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", g.token)) |
| 73 | req.Header.Set("Accept", "application/vnd.github.raw+json") |
| 74 | req.Header.Set("X-GitHub-Api-Version", "2022-11-28") |
| 75 | |
| 76 | resp, err := g.client.Do(req) |
| 77 | if err != nil { |
| 78 | return nil, errors.Wrap(err, "failed to send request") |
| 79 | } |
| 80 | defer resp.Body.Close() |
| 81 | |
| 82 | if resp.StatusCode != http.StatusOK { |
| 83 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 84 | return nil, errors.Errorf("failed to list comments: %s", string(bodyBytes)) |
| 85 | } |
| 86 | |
| 87 | bodyBytes, err := io.ReadAll(resp.Body) |
| 88 | if err != nil { |
| 89 | return nil, errors.Wrap(err, "failed to read response body") |
| 90 | } |
| 91 | |
| 92 | var comments []comment |
| 93 | if err := json.Unmarshal(bodyBytes, &comments); err != nil { |
| 94 | return nil, errors.Wrap(err, "failed to unmarshal response body") |
| 95 | } |
| 96 | |
| 97 | return comments, nil |
| 98 | } |
| 99 | |
| 100 | func (g *githubClient) updateComment(repo string, commentID int64, msg string) error { |
| 101 | body := map[string]string{ |