123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package github
- import (
- "context"
- "fmt"
- "time"
- )
- type IssueComment struct {
- ID *int64 `json:"id,omitempty"`
- Body *string `json:"body,omitempty"`
- User *User `json:"user,omitempty"`
- Reactions *Reactions `json:"reactions,omitempty"`
- CreatedAt *time.Time `json:"created_at,omitempty"`
- UpdatedAt *time.Time `json:"updated_at,omitempty"`
-
-
- AuthorAssociation *string `json:"author_association,omitempty"`
- URL *string `json:"url,omitempty"`
- HTMLURL *string `json:"html_url,omitempty"`
- IssueURL *string `json:"issue_url,omitempty"`
- }
- func (i IssueComment) String() string {
- return Stringify(i)
- }
- type IssueListCommentsOptions struct {
-
- Sort string `url:"sort,omitempty"`
-
- Direction string `url:"direction,omitempty"`
-
- Since time.Time `url:"since,omitempty"`
- ListOptions
- }
- func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opt *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
- var u string
- if number == 0 {
- u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
- } else {
- u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
- }
- u, err := addOptions(u, opt)
- if err != nil {
- return nil, nil, err
- }
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- req.Header.Set("Accept", mediaTypeReactionsPreview)
- var comments []*IssueComment
- resp, err := s.client.Do(ctx, req, &comments)
- if err != nil {
- return nil, resp, err
- }
- return comments, resp, nil
- }
- func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, commentID int64) (*IssueComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- req.Header.Set("Accept", mediaTypeReactionsPreview)
- comment := new(IssueComment)
- resp, err := s.client.Do(ctx, req, comment)
- if err != nil {
- return nil, resp, err
- }
- return comment, resp, nil
- }
- func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
- req, err := s.client.NewRequest("POST", u, comment)
- if err != nil {
- return nil, nil, err
- }
- c := new(IssueComment)
- resp, err := s.client.Do(ctx, req, c)
- if err != nil {
- return nil, resp, err
- }
- return c, resp, nil
- }
- func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *IssueComment) (*IssueComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
- req, err := s.client.NewRequest("PATCH", u, comment)
- if err != nil {
- return nil, nil, err
- }
- c := new(IssueComment)
- resp, err := s.client.Do(ctx, req, c)
- if err != nil {
- return nil, resp, err
- }
- return c, resp, nil
- }
- func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*Response, error) {
- u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, commentID)
- req, err := s.client.NewRequest("DELETE", u, nil)
- if err != nil {
- return nil, err
- }
- return s.client.Do(ctx, req, nil)
- }
|