| 1 |
// Copyright 2018 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 |
// DiscussionComment represents a GitHub dicussion in a team. |
| 14 |
type DiscussionComment struct { |
| 15 |
Author *User `json:"author,omitempty"` |
| 16 |
Body *string `json:"body,omitempty"` |
| 17 |
BodyHTML *string `json:"body_html,omitempty"` |
| 18 |
BodyVersion *string `json:"body_version,omitempty"` |
| 19 |
CreatedAt *Timestamp `json:"created_at,omitempty"` |
| 20 |
LastEditedAt *Timestamp `json:"last_edited_at,omitempty"` |
| 21 |
DiscussionURL *string `json:"discussion_url,omitempty"` |
| 22 |
HTMLURL *string `json:"html_url,omitempty"` |
| 23 |
NodeID *string `json:"node_id,omitempty"` |
| 24 |
Number *int `json:"number,omitempty"` |
| 25 |
UpdatedAt *Timestamp `json:"updated_at,omitempty"` |
| 26 |
URL *string `json:"url,omitempty"` |
| 27 |
Reactions *Reactions `json:"reactions,omitempty"` |
| 28 |
} |
| 29 |
|
| 30 |
func (c DiscussionComment) String() string { |
| 31 |
return Stringify(c) |
| 32 |
} |
| 33 |
|
| 34 |
// DiscussionCommentListOptions specifies optional parameters to the |
| 35 |
// TeamServices.ListComments method. |
| 36 |
type DiscussionCommentListOptions struct { |
| 37 |
// Sorts the discussion comments by the date they were created. |
| 38 |
// Accepted values are asc and desc. Default is desc. |
| 39 |
Direction string `url:"direction,omitempty"` |
| 40 |
ListOptions |
| 41 |
} |
| 42 |
|
| 43 |
// ListCommentsByID lists all comments on a team discussion by team ID. |
| 44 |
// Authenticated user must grant read:discussion scope. |
| 45 |
// |
| 46 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#list-discussion-comments |
| 47 |
// |
| 48 |
//meta:operation GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments |
| 49 |
func (s *TeamsService) ListCommentsByID(ctx context.Context, orgID, teamID int64, discussionNumber int, options *DiscussionCommentListOptions) ([]*DiscussionComment, *Response, error) { |
| 50 |
u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments", orgID, teamID, discussionNumber) |
| 51 |
u, err := addOptions(u, options) |
| 52 |
if err != nil { |
| 53 |
return nil, nil, err |
| 54 |
} |
| 55 |
|
| 56 |
req, err := s.client.NewRequest("GET", u, nil) |
| 57 |
if err != nil { |
| 58 |
return nil, nil, err |
| 59 |
} |
| 60 |
|
| 61 |
var comments []*DiscussionComment |
| 62 |
resp, err := s.client.Do(ctx, req, &comments) |
| 63 |
if err != nil { |
| 64 |
return nil, resp, err |
| 65 |
} |
| 66 |
|
| 67 |
return comments, resp, nil |
| 68 |
} |
| 69 |
|
| 70 |
// ListCommentsBySlug lists all comments on a team discussion by team slug. |
| 71 |
// Authenticated user must grant read:discussion scope. |
| 72 |
// |
| 73 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#list-discussion-comments |
| 74 |
// |
| 75 |
//meta:operation GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments |
| 76 |
func (s *TeamsService) ListCommentsBySlug(ctx context.Context, org, slug string, discussionNumber int, options *DiscussionCommentListOptions) ([]*DiscussionComment, *Response, error) { |
| 77 |
u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments", org, slug, discussionNumber) |
| 78 |
u, err := addOptions(u, options) |
| 79 |
if err != nil { |
| 80 |
return nil, nil, err |
| 81 |
} |
| 82 |
|
| 83 |
req, err := s.client.NewRequest("GET", u, nil) |
| 84 |
if err != nil { |
| 85 |
return nil, nil, err |
| 86 |
} |
| 87 |
|
| 88 |
var comments []*DiscussionComment |
| 89 |
resp, err := s.client.Do(ctx, req, &comments) |
| 90 |
if err != nil { |
| 91 |
return nil, resp, err |
| 92 |
} |
| 93 |
|
| 94 |
return comments, resp, nil |
| 95 |
} |
| 96 |
|
| 97 |
// GetCommentByID gets a specific comment on a team discussion by team ID. |
| 98 |
// Authenticated user must grant read:discussion scope. |
| 99 |
// |
| 100 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#get-a-discussion-comment |
| 101 |
// |
| 102 |
//meta:operation GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number} |
| 103 |
func (s *TeamsService) GetCommentByID(ctx context.Context, orgID, teamID int64, discussionNumber, commentNumber int) (*DiscussionComment, *Response, error) { |
| 104 |
u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v", orgID, teamID, discussionNumber, commentNumber) |
| 105 |
req, err := s.client.NewRequest("GET", u, nil) |
| 106 |
if err != nil { |
| 107 |
return nil, nil, err |
| 108 |
} |
| 109 |
|
| 110 |
discussionComment := &DiscussionComment{} |
| 111 |
resp, err := s.client.Do(ctx, req, discussionComment) |
| 112 |
if err != nil { |
| 113 |
return nil, resp, err |
| 114 |
} |
| 115 |
|
| 116 |
return discussionComment, resp, nil |
| 117 |
} |
| 118 |
|
| 119 |
// GetCommentBySlug gets a specific comment on a team discussion by team slug. |
| 120 |
// Authenticated user must grant read:discussion scope. |
| 121 |
// |
| 122 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#get-a-discussion-comment |
| 123 |
// |
| 124 |
//meta:operation GET /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number} |
| 125 |
func (s *TeamsService) GetCommentBySlug(ctx context.Context, org, slug string, discussionNumber, commentNumber int) (*DiscussionComment, *Response, error) { |
| 126 |
u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v", org, slug, discussionNumber, commentNumber) |
| 127 |
|
| 128 |
req, err := s.client.NewRequest("GET", u, nil) |
| 129 |
if err != nil { |
| 130 |
return nil, nil, err |
| 131 |
} |
| 132 |
|
| 133 |
discussionComment := &DiscussionComment{} |
| 134 |
resp, err := s.client.Do(ctx, req, discussionComment) |
| 135 |
if err != nil { |
| 136 |
return nil, resp, err |
| 137 |
} |
| 138 |
|
| 139 |
return discussionComment, resp, nil |
| 140 |
} |
| 141 |
|
| 142 |
// CreateCommentByID creates a new comment on a team discussion by team ID. |
| 143 |
// Authenticated user must grant write:discussion scope. |
| 144 |
// |
| 145 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#create-a-discussion-comment |
| 146 |
// |
| 147 |
//meta:operation POST /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments |
| 148 |
func (s *TeamsService) CreateCommentByID(ctx context.Context, orgID, teamID int64, discsusionNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) { |
| 149 |
u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments", orgID, teamID, discsusionNumber) |
| 150 |
req, err := s.client.NewRequest("POST", u, comment) |
| 151 |
if err != nil { |
| 152 |
return nil, nil, err |
| 153 |
} |
| 154 |
|
| 155 |
discussionComment := &DiscussionComment{} |
| 156 |
resp, err := s.client.Do(ctx, req, discussionComment) |
| 157 |
if err != nil { |
| 158 |
return nil, resp, err |
| 159 |
} |
| 160 |
|
| 161 |
return discussionComment, resp, nil |
| 162 |
} |
| 163 |
|
| 164 |
// CreateCommentBySlug creates a new comment on a team discussion by team slug. |
| 165 |
// Authenticated user must grant write:discussion scope. |
| 166 |
// |
| 167 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#create-a-discussion-comment |
| 168 |
// |
| 169 |
//meta:operation POST /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments |
| 170 |
func (s *TeamsService) CreateCommentBySlug(ctx context.Context, org, slug string, discsusionNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) { |
| 171 |
u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments", org, slug, discsusionNumber) |
| 172 |
req, err := s.client.NewRequest("POST", u, comment) |
| 173 |
if err != nil { |
| 174 |
return nil, nil, err |
| 175 |
} |
| 176 |
|
| 177 |
discussionComment := &DiscussionComment{} |
| 178 |
resp, err := s.client.Do(ctx, req, discussionComment) |
| 179 |
if err != nil { |
| 180 |
return nil, resp, err |
| 181 |
} |
| 182 |
|
| 183 |
return discussionComment, resp, nil |
| 184 |
} |
| 185 |
|
| 186 |
// EditCommentByID edits the body text of a discussion comment by team ID. |
| 187 |
// Authenticated user must grant write:discussion scope. |
| 188 |
// User is allowed to edit body of a comment only. |
| 189 |
// |
| 190 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#update-a-discussion-comment |
| 191 |
// |
| 192 |
//meta:operation PATCH /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number} |
| 193 |
func (s *TeamsService) EditCommentByID(ctx context.Context, orgID, teamID int64, discussionNumber, commentNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) { |
| 194 |
u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v", orgID, teamID, discussionNumber, commentNumber) |
| 195 |
req, err := s.client.NewRequest("PATCH", u, comment) |
| 196 |
if err != nil { |
| 197 |
return nil, nil, err |
| 198 |
} |
| 199 |
|
| 200 |
discussionComment := &DiscussionComment{} |
| 201 |
resp, err := s.client.Do(ctx, req, discussionComment) |
| 202 |
if err != nil { |
| 203 |
return nil, resp, err |
| 204 |
} |
| 205 |
|
| 206 |
return discussionComment, resp, nil |
| 207 |
} |
| 208 |
|
| 209 |
// EditCommentBySlug edits the body text of a discussion comment by team slug. |
| 210 |
// Authenticated user must grant write:discussion scope. |
| 211 |
// User is allowed to edit body of a comment only. |
| 212 |
// |
| 213 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#update-a-discussion-comment |
| 214 |
// |
| 215 |
//meta:operation PATCH /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number} |
| 216 |
func (s *TeamsService) EditCommentBySlug(ctx context.Context, org, slug string, discussionNumber, commentNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) { |
| 217 |
u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v", org, slug, discussionNumber, commentNumber) |
| 218 |
req, err := s.client.NewRequest("PATCH", u, comment) |
| 219 |
if err != nil { |
| 220 |
return nil, nil, err |
| 221 |
} |
| 222 |
|
| 223 |
discussionComment := &DiscussionComment{} |
| 224 |
resp, err := s.client.Do(ctx, req, discussionComment) |
| 225 |
if err != nil { |
| 226 |
return nil, resp, err |
| 227 |
} |
| 228 |
|
| 229 |
return discussionComment, resp, nil |
| 230 |
} |
| 231 |
|
| 232 |
// DeleteCommentByID deletes a comment on a team discussion by team ID. |
| 233 |
// Authenticated user must grant write:discussion scope. |
| 234 |
// |
| 235 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#delete-a-discussion-comment |
| 236 |
// |
| 237 |
//meta:operation DELETE /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number} |
| 238 |
func (s *TeamsService) DeleteCommentByID(ctx context.Context, orgID, teamID int64, discussionNumber, commentNumber int) (*Response, error) { |
| 239 |
u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v", orgID, teamID, discussionNumber, commentNumber) |
| 240 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 241 |
if err != nil { |
| 242 |
return nil, err |
| 243 |
} |
| 244 |
|
| 245 |
return s.client.Do(ctx, req, nil) |
| 246 |
} |
| 247 |
|
| 248 |
// DeleteCommentBySlug deletes a comment on a team discussion by team slug. |
| 249 |
// Authenticated user must grant write:discussion scope. |
| 250 |
// |
| 251 |
// GitHub API docs: https://docs.github.com/rest/teams/discussion-comments#delete-a-discussion-comment |
| 252 |
// |
| 253 |
//meta:operation DELETE /orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments/{comment_number} |
| 254 |
func (s *TeamsService) DeleteCommentBySlug(ctx context.Context, org, slug string, discussionNumber, commentNumber int) (*Response, error) { |
| 255 |
u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v", org, slug, discussionNumber, commentNumber) |
| 256 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 257 |
if err != nil { |
| 258 |
return nil, err |
| 259 |
} |
| 260 |
|
| 261 |
return s.client.Do(ctx, req, nil) |
| 262 |
} |