...

Source file src/github.com/google/go-github/v33/github/teams_discussion_comments.go

Documentation: github.com/google/go-github/v33/github

     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/en/free-pro-team@latest/rest/reference/teams/#list-discussion-comments
    47  func (s *TeamsService) ListCommentsByID(ctx context.Context, orgID, teamID int64, discussionNumber int, options *DiscussionCommentListOptions) ([]*DiscussionComment, *Response, error) {
    48  	u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments", orgID, teamID, discussionNumber)
    49  	u, err := addOptions(u, options)
    50  	if err != nil {
    51  		return nil, nil, err
    52  	}
    53  
    54  	req, err := s.client.NewRequest("GET", u, nil)
    55  	if err != nil {
    56  		return nil, nil, err
    57  	}
    58  
    59  	var comments []*DiscussionComment
    60  	resp, err := s.client.Do(ctx, req, &comments)
    61  	if err != nil {
    62  		return nil, resp, err
    63  	}
    64  
    65  	return comments, resp, nil
    66  }
    67  
    68  // ListCommentsBySlug lists all comments on a team discussion by team slug.
    69  // Authenticated user must grant read:discussion scope.
    70  //
    71  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#list-discussion-comments
    72  func (s *TeamsService) ListCommentsBySlug(ctx context.Context, org, slug string, discussionNumber int, options *DiscussionCommentListOptions) ([]*DiscussionComment, *Response, error) {
    73  	u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments", org, slug, discussionNumber)
    74  	u, err := addOptions(u, options)
    75  	if err != nil {
    76  		return nil, nil, err
    77  	}
    78  
    79  	req, err := s.client.NewRequest("GET", u, nil)
    80  	if err != nil {
    81  		return nil, nil, err
    82  	}
    83  
    84  	var comments []*DiscussionComment
    85  	resp, err := s.client.Do(ctx, req, &comments)
    86  	if err != nil {
    87  		return nil, resp, err
    88  	}
    89  
    90  	return comments, resp, nil
    91  }
    92  
    93  // GetCommentByID gets a specific comment on a team discussion by team ID.
    94  // Authenticated user must grant read:discussion scope.
    95  //
    96  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#get-a-discussion-comment
    97  func (s *TeamsService) GetCommentByID(ctx context.Context, orgID, teamID int64, discussionNumber, commentNumber int) (*DiscussionComment, *Response, error) {
    98  	u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v", orgID, teamID, discussionNumber, commentNumber)
    99  	req, err := s.client.NewRequest("GET", u, nil)
   100  	if err != nil {
   101  		return nil, nil, err
   102  	}
   103  
   104  	discussionComment := &DiscussionComment{}
   105  	resp, err := s.client.Do(ctx, req, discussionComment)
   106  	if err != nil {
   107  		return nil, resp, err
   108  	}
   109  
   110  	return discussionComment, resp, nil
   111  }
   112  
   113  // GetCommentBySlug gets a specific comment on a team discussion by team slug.
   114  // Authenticated user must grant read:discussion scope.
   115  //
   116  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#get-a-discussion-comment
   117  func (s *TeamsService) GetCommentBySlug(ctx context.Context, org, slug string, discussionNumber, commentNumber int) (*DiscussionComment, *Response, error) {
   118  	u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v", org, slug, discussionNumber, commentNumber)
   119  
   120  	req, err := s.client.NewRequest("GET", u, nil)
   121  	if err != nil {
   122  		return nil, nil, err
   123  	}
   124  
   125  	discussionComment := &DiscussionComment{}
   126  	resp, err := s.client.Do(ctx, req, discussionComment)
   127  	if err != nil {
   128  		return nil, resp, err
   129  	}
   130  
   131  	return discussionComment, resp, nil
   132  }
   133  
   134  // CreateCommentByID creates a new comment on a team discussion by team ID.
   135  // Authenticated user must grant write:discussion scope.
   136  //
   137  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#create-a-discussion-comment
   138  func (s *TeamsService) CreateCommentByID(ctx context.Context, orgID, teamID int64, discsusionNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) {
   139  	u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments", orgID, teamID, discsusionNumber)
   140  	req, err := s.client.NewRequest("POST", u, comment)
   141  	if err != nil {
   142  		return nil, nil, err
   143  	}
   144  
   145  	discussionComment := &DiscussionComment{}
   146  	resp, err := s.client.Do(ctx, req, discussionComment)
   147  	if err != nil {
   148  		return nil, resp, err
   149  	}
   150  
   151  	return discussionComment, resp, nil
   152  }
   153  
   154  // CreateCommentBySlug creates a new comment on a team discussion by team slug.
   155  // Authenticated user must grant write:discussion scope.
   156  //
   157  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#create-a-discussion-comment
   158  func (s *TeamsService) CreateCommentBySlug(ctx context.Context, org, slug string, discsusionNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) {
   159  	u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments", org, slug, discsusionNumber)
   160  	req, err := s.client.NewRequest("POST", u, comment)
   161  	if err != nil {
   162  		return nil, nil, err
   163  	}
   164  
   165  	discussionComment := &DiscussionComment{}
   166  	resp, err := s.client.Do(ctx, req, discussionComment)
   167  	if err != nil {
   168  		return nil, resp, err
   169  	}
   170  
   171  	return discussionComment, resp, nil
   172  }
   173  
   174  // EditCommentByID edits the body text of a discussion comment by team ID.
   175  // Authenticated user must grant write:discussion scope.
   176  // User is allowed to edit body of a comment only.
   177  //
   178  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#update-a-discussion-comment
   179  func (s *TeamsService) EditCommentByID(ctx context.Context, orgID, teamID int64, discussionNumber, commentNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) {
   180  	u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v", orgID, teamID, discussionNumber, commentNumber)
   181  	req, err := s.client.NewRequest("PATCH", u, comment)
   182  	if err != nil {
   183  		return nil, nil, err
   184  	}
   185  
   186  	discussionComment := &DiscussionComment{}
   187  	resp, err := s.client.Do(ctx, req, discussionComment)
   188  	if err != nil {
   189  		return nil, resp, err
   190  	}
   191  
   192  	return discussionComment, resp, nil
   193  }
   194  
   195  // EditCommentBySlug edits the body text of a discussion comment by team slug.
   196  // Authenticated user must grant write:discussion scope.
   197  // User is allowed to edit body of a comment only.
   198  //
   199  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#update-a-discussion-comment
   200  func (s *TeamsService) EditCommentBySlug(ctx context.Context, org, slug string, discussionNumber, commentNumber int, comment DiscussionComment) (*DiscussionComment, *Response, error) {
   201  	u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v", org, slug, discussionNumber, commentNumber)
   202  	req, err := s.client.NewRequest("PATCH", u, comment)
   203  	if err != nil {
   204  		return nil, nil, err
   205  	}
   206  
   207  	discussionComment := &DiscussionComment{}
   208  	resp, err := s.client.Do(ctx, req, discussionComment)
   209  	if err != nil {
   210  		return nil, resp, err
   211  	}
   212  
   213  	return discussionComment, resp, nil
   214  }
   215  
   216  // DeleteCommentByID deletes a comment on a team discussion by team ID.
   217  // Authenticated user must grant write:discussion scope.
   218  //
   219  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#delete-a-discussion-comment
   220  func (s *TeamsService) DeleteCommentByID(ctx context.Context, orgID, teamID int64, discussionNumber, commentNumber int) (*Response, error) {
   221  	u := fmt.Sprintf("organizations/%v/team/%v/discussions/%v/comments/%v", orgID, teamID, discussionNumber, commentNumber)
   222  	req, err := s.client.NewRequest("DELETE", u, nil)
   223  	if err != nil {
   224  		return nil, err
   225  	}
   226  
   227  	return s.client.Do(ctx, req, nil)
   228  }
   229  
   230  // DeleteCommentBySlug deletes a comment on a team discussion by team slug.
   231  // Authenticated user must grant write:discussion scope.
   232  //
   233  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams/#delete-a-discussion-comment
   234  func (s *TeamsService) DeleteCommentBySlug(ctx context.Context, org, slug string, discussionNumber, commentNumber int) (*Response, error) {
   235  	u := fmt.Sprintf("orgs/%v/teams/%v/discussions/%v/comments/%v", org, slug, discussionNumber, commentNumber)
   236  	req, err := s.client.NewRequest("DELETE", u, nil)
   237  	if err != nil {
   238  		return nil, err
   239  	}
   240  
   241  	return s.client.Do(ctx, req, nil)
   242  }
   243  

View as plain text