github.com/crosbymichael/octokat@v0.0.0-20160826194511-076a32289ed5/comments.go (about) 1 package octokat 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 type Comment struct { 9 Url string `json:"url,omitempty,omitempty"` 10 Id int `json:"id,omitempty"` 11 Body string `json:"body,omitempty"` 12 Path string `json:"path,omitempty"` 13 Position int `json:"position,omitempty"` 14 User User `json:"user,omitempty"` 15 CreatedAt time.Time `json:"created_at,omitempty"` 16 UpdatedAt time.Time `json:"updated_at,omitempty"` 17 } 18 19 // Get comments for an issue for pull request 20 // 21 // See http://developer.github.com/v3/pulls/comments/ 22 func (c *Client) Comments(repo Repo, number string, options *Options) (comments []Comment, err error) { 23 path := fmt.Sprintf("repos/%s/issues/%s/comments", repo, number) 24 err = c.jsonGet(path, options, &comments) 25 return 26 } 27 28 // Add a comment to an issue or pull request 29 // 30 // See http://developer.github.com/v3/issues/comments/#create-a-comment 31 func (c *Client) AddComment(repo Repo, number, body string) (comment Comment, err error) { 32 path := fmt.Sprintf("repos/%s/issues/%s/comments", repo, number) 33 options := &Options{Params: map[string]string{"body": body}} 34 35 err = c.jsonPost(path, options, &comment) 36 return 37 } 38 39 // Add a comment to an issue or pull request 40 // 41 // See https://developer.github.com/v3/issues/comments/#edit-a-comment 42 func (c *Client) PatchComment(repo Repo, number, body string) (comment Comment, err error) { 43 path := fmt.Sprintf("repos/%s/issues/%s/comments", repo, number) 44 options := &Options{Params: map[string]string{"body": body}} 45 46 err = c.jsonPatch(path, options, &comment) 47 return 48 } 49 50 func (c *Client) RemoveComment(repo Repo, commentId int) error { 51 path := fmt.Sprintf("repos/%s/issues/comments/%d", repo, commentId) 52 return c.delete(path, Headers{}) 53 }