Debian Codegraph @

github/gists_comments.go

raw
1 // Copyright 2013 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13 // GistComment represents a Gist comment.
14 type GistComment struct {
15 ID *int64 `json:"id,omitempty"`
16 URL *string `json:"url,omitempty"`
17 Body *string `json:"body,omitempty"`
18 User *User `json:"user,omitempty"`
19 CreatedAt *Timestamp `json:"created_at,omitempty"`
20 }
21
22 func (g GistComment) String() string {
23 return Stringify(g)
24 }
25
26 // ListComments lists all comments for a gist.
27 //
28 // GitHub API docs: https://docs.github.com/rest/gists/comments#list-gist-comments
29 //
30 //meta:operation GET /gists/{gist_id}/comments
31 func (s *GistsService) ListComments(ctx context.Context, gistID string, opts *ListOptions) ([]*GistComment, *Response, error) {
32 u := fmt.Sprintf("gists/%v/comments", gistID)
33 u, err := addOptions(u, opts)
34 if err != nil {
35 return nil, nil, err
36 }
37
38 req, err := s.client.NewRequest("GET", u, nil)
39 if err != nil {
40 return nil, nil, err
41 }
42
43 var comments []*GistComment
44 resp, err := s.client.Do(ctx, req, &comments)
45 if err != nil {
46 return nil, resp, err
47 }
48
49 return comments, resp, nil
50 }
51
52 // GetComment retrieves a single comment from a gist.
53 //
54 // GitHub API docs: https://docs.github.com/rest/gists/comments#get-a-gist-comment
55 //
56 //meta:operation GET /gists/{gist_id}/comments/{comment_id}
57 func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int64) (*GistComment, *Response, error) {
58 u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
59 req, err := s.client.NewRequest("GET", u, nil)
60 if err != nil {
61 return nil, nil, err
62 }
63
64 c := new(GistComment)
65 resp, err := s.client.Do(ctx, req, c)
66 if err != nil {
67 return nil, resp, err
68 }
69
70 return c, resp, nil
71 }
72
73 // CreateComment creates a comment for a gist.
74 //
75 // GitHub API docs: https://docs.github.com/rest/gists/comments#create-a-gist-comment
76 //
77 //meta:operation POST /gists/{gist_id}/comments
78 func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment *GistComment) (*GistComment, *Response, error) {
79 u := fmt.Sprintf("gists/%v/comments", gistID)
80 req, err := s.client.NewRequest("POST", u, comment)
81 if err != nil {
82 return nil, nil, err
83 }
84
85 c := new(GistComment)
86 resp, err := s.client.Do(ctx, req, c)
87 if err != nil {
88 return nil, resp, err
89 }
90
91 return c, resp, nil
92 }
93
94 // EditComment edits an existing gist comment.
95 //
96 // GitHub API docs: https://docs.github.com/rest/gists/comments#update-a-gist-comment
97 //
98 //meta:operation PATCH /gists/{gist_id}/comments/{comment_id}
99 func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, comment *GistComment) (*GistComment, *Response, error) {
100 u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
101 req, err := s.client.NewRequest("PATCH", u, comment)
102 if err != nil {
103 return nil, nil, err
104 }
105
106 c := new(GistComment)
107 resp, err := s.client.Do(ctx, req, c)
108 if err != nil {
109 return nil, resp, err
110 }
111
112 return c, resp, nil
113 }
114
115 // DeleteComment deletes a gist comment.
116 //
117 // GitHub API docs: https://docs.github.com/rest/gists/comments#delete-a-gist-comment
118 //
119 //meta:operation DELETE /gists/{gist_id}/comments/{comment_id}
120 func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int64) (*Response, error) {
121 u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
122 req, err := s.client.NewRequest("DELETE", u, nil)
123 if err != nil {
124 return nil, err
125 }
126
127 return s.client.Do(ctx, req, nil)
128 }