123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package github
- import (
- "context"
- "fmt"
- "time"
- )
- type RepositoryComment struct {
- HTMLURL *string `json:"html_url,omitempty"`
- URL *string `json:"url,omitempty"`
- ID *int64 `json:"id,omitempty"`
- CommitID *string `json:"commit_id,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"`
-
- Body *string `json:"body"`
-
- Path *string `json:"path,omitempty"`
- Position *int `json:"position,omitempty"`
- }
- func (r RepositoryComment) String() string {
- return Stringify(r)
- }
- func (s *RepositoriesService) ListComments(ctx context.Context, owner, repo string, opt *ListOptions) ([]*RepositoryComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/comments", owner, repo)
- 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 []*RepositoryComment
- resp, err := s.client.Do(ctx, req, &comments)
- if err != nil {
- return nil, resp, err
- }
- return comments, resp, nil
- }
- func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, repo, sha string, opt *ListOptions) ([]*RepositoryComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
- 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 []*RepositoryComment
- resp, err := s.client.Do(ctx, req, &comments)
- if err != nil {
- return nil, resp, err
- }
- return comments, resp, nil
- }
- func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
- req, err := s.client.NewRequest("POST", u, comment)
- if err != nil {
- return nil, nil, err
- }
- c := new(RepositoryComment)
- resp, err := s.client.Do(ctx, req, c)
- if err != nil {
- return nil, resp, err
- }
- return c, resp, nil
- }
- func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int64) (*RepositoryComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- req.Header.Set("Accept", mediaTypeReactionsPreview)
- c := new(RepositoryComment)
- resp, err := s.client.Do(ctx, req, c)
- if err != nil {
- return nil, resp, err
- }
- return c, resp, nil
- }
- func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int64, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
- req, err := s.client.NewRequest("PATCH", u, comment)
- if err != nil {
- return nil, nil, err
- }
- c := new(RepositoryComment)
- resp, err := s.client.Do(ctx, req, c)
- if err != nil {
- return nil, resp, err
- }
- return c, resp, nil
- }
- func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int64) (*Response, error) {
- u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
- req, err := s.client.NewRequest("DELETE", u, nil)
- if err != nil {
- return nil, err
- }
- return s.client.Do(ctx, req, nil)
- }
|