(repo, pr, msg string)
| 33 | } |
| 34 | |
| 35 | func (g *githubClient) createComment(repo, pr, msg string) error { |
| 36 | body := map[string]string{ |
| 37 | "body": msg, |
| 38 | } |
| 39 | bodyBytes, err := json.Marshal(body) |
| 40 | if err != nil { |
| 41 | return errors.Wrap(err, "failed to marshal request body") |
| 42 | } |
| 43 | |
| 44 | url := fmt.Sprintf("%s/repos/%s/issues/%s/comments", g.apiURL, repo, pr) |
| 45 | req, err := http.NewRequest("POST", url, bytes.NewReader(bodyBytes)) |
| 46 | if err != nil { |
| 47 | return errors.Wrap(err, "failed to create request") |
| 48 | } |
| 49 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", g.token)) |
| 50 | req.Header.Set("Accept", "application/vnd.github.raw+json") |
| 51 | req.Header.Set("X-GitHub-Api-Version", "2022-11-28") |
| 52 | |
| 53 | resp, err := g.client.Do(req) |
| 54 | if err != nil { |
| 55 | return errors.Wrap(err, "failed to send request") |
| 56 | } |
| 57 | defer resp.Body.Close() |
| 58 | |
| 59 | if resp.StatusCode != http.StatusCreated { |
| 60 | return errors.Errorf("failed to create comment, status code: %d", resp.StatusCode) |
| 61 | } |
| 62 | |
| 63 | return nil |
| 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) |
no test coverage detected