...

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

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

     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  	"time"
    12  )
    13  
    14  // GistComment represents a Gist comment.
    15  type GistComment struct {
    16  	ID        *int64     `json:"id,omitempty"`
    17  	URL       *string    `json:"url,omitempty"`
    18  	Body      *string    `json:"body,omitempty"`
    19  	User      *User      `json:"user,omitempty"`
    20  	CreatedAt *time.Time `json:"created_at,omitempty"`
    21  }
    22  
    23  func (g GistComment) String() string {
    24  	return Stringify(g)
    25  }
    26  
    27  // ListComments lists all comments for a gist.
    28  //
    29  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#list-gist-comments
    30  func (s *GistsService) ListComments(ctx context.Context, gistID string, opts *ListOptions) ([]*GistComment, *Response, error) {
    31  	u := fmt.Sprintf("gists/%v/comments", gistID)
    32  	u, err := addOptions(u, opts)
    33  	if err != nil {
    34  		return nil, nil, err
    35  	}
    36  
    37  	req, err := s.client.NewRequest("GET", u, nil)
    38  	if err != nil {
    39  		return nil, nil, err
    40  	}
    41  
    42  	var comments []*GistComment
    43  	resp, err := s.client.Do(ctx, req, &comments)
    44  	if err != nil {
    45  		return nil, resp, err
    46  	}
    47  
    48  	return comments, resp, nil
    49  }
    50  
    51  // GetComment retrieves a single comment from a gist.
    52  //
    53  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#get-a-gist-comment
    54  func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int64) (*GistComment, *Response, error) {
    55  	u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
    56  	req, err := s.client.NewRequest("GET", u, nil)
    57  	if err != nil {
    58  		return nil, nil, err
    59  	}
    60  
    61  	c := new(GistComment)
    62  	resp, err := s.client.Do(ctx, req, c)
    63  	if err != nil {
    64  		return nil, resp, err
    65  	}
    66  
    67  	return c, resp, nil
    68  }
    69  
    70  // CreateComment creates a comment for a gist.
    71  //
    72  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#create-a-gist-comment
    73  func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment *GistComment) (*GistComment, *Response, error) {
    74  	u := fmt.Sprintf("gists/%v/comments", gistID)
    75  	req, err := s.client.NewRequest("POST", u, comment)
    76  	if err != nil {
    77  		return nil, nil, err
    78  	}
    79  
    80  	c := new(GistComment)
    81  	resp, err := s.client.Do(ctx, req, c)
    82  	if err != nil {
    83  		return nil, resp, err
    84  	}
    85  
    86  	return c, resp, nil
    87  }
    88  
    89  // EditComment edits an existing gist comment.
    90  //
    91  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#update-a-gist-comment
    92  func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int64, comment *GistComment) (*GistComment, *Response, error) {
    93  	u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
    94  	req, err := s.client.NewRequest("PATCH", u, comment)
    95  	if err != nil {
    96  		return nil, nil, err
    97  	}
    98  
    99  	c := new(GistComment)
   100  	resp, err := s.client.Do(ctx, req, c)
   101  	if err != nil {
   102  		return nil, resp, err
   103  	}
   104  
   105  	return c, resp, nil
   106  }
   107  
   108  // DeleteComment deletes a gist comment.
   109  //
   110  // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/gists/#delete-a-gist-comment
   111  func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int64) (*Response, error) {
   112  	u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
   113  	req, err := s.client.NewRequest("DELETE", u, nil)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  
   118  	return s.client.Do(ctx, req, nil)
   119  }
   120  

View as plain text