MCPcopy Index your code
hub / github.com/bytebase/bytebase / createComment

Method createComment

action/github/api.go:35–64  ·  view source on GitHub ↗
(repo, pr, msg string)

Source from the content-addressed store, hash-verified

33}
34
35func (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
66func (g *githubClient) listComments(repo, pr string) ([]comment, error) {
67 url := fmt.Sprintf("%s/repos/%s/issues/%s/comments", g.apiURL, repo, pr)

Callers 1

upsertCommentFunction · 0.80

Calls 4

DoMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected