2016-11-07 22:53:13 +09:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-11-13 16:02:25 +09:00
|
|
|
// Comment represents a comment on a commit or issue
|
2016-11-07 22:53:13 +09:00
|
|
|
type Comment struct {
|
2018-03-06 10:22:16 +09:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
HTMLURL string `json:"html_url"`
|
|
|
|
PRURL string `json:"pull_request_url"`
|
|
|
|
IssueURL string `json:"issue_url"`
|
|
|
|
Poster *User `json:"user"`
|
|
|
|
Body string `json:"body"`
|
2017-11-13 16:02:25 +09:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 10:22:16 +09:00
|
|
|
Created time.Time `json:"created_at"`
|
2017-11-13 16:02:25 +09:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 10:22:16 +09:00
|
|
|
Updated time.Time `json:"updated_at"`
|
2016-11-07 22:53:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListIssueComments list comments on an issue.
|
|
|
|
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
|
|
|
|
comments := make([]*Comment, 0, 10)
|
|
|
|
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
|
|
|
|
}
|
|
|
|
|
2016-11-29 17:09:17 +09:00
|
|
|
// ListRepoIssueComments list comments for a given repo.
|
|
|
|
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
|
|
|
|
comments := make([]*Comment, 0, 10)
|
|
|
|
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
|
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:25 +09:00
|
|
|
// CreateIssueCommentOption options for creating a comment on an issue
|
2016-11-07 22:53:13 +09:00
|
|
|
type CreateIssueCommentOption struct {
|
2017-11-13 16:02:25 +09:00
|
|
|
// required:true
|
2016-11-07 22:53:13 +09:00
|
|
|
Body string `json:"body" binding:"Required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateIssueComment create comment on an issue.
|
|
|
|
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
|
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
comment := new(Comment)
|
2017-04-16 21:51:04 +09:00
|
|
|
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
2016-11-07 22:53:13 +09:00
|
|
|
}
|
|
|
|
|
2017-11-13 16:02:25 +09:00
|
|
|
// EditIssueCommentOption options for editing a comment
|
2016-11-07 22:53:13 +09:00
|
|
|
type EditIssueCommentOption struct {
|
2017-11-13 16:02:25 +09:00
|
|
|
// required: true
|
2016-11-07 22:53:13 +09:00
|
|
|
Body string `json:"body" binding:"Required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// EditIssueComment edits an issue comment.
|
|
|
|
func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
|
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
comment := new(Comment)
|
|
|
|
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
|
|
|
|
}
|
2016-11-29 17:09:17 +09:00
|
|
|
|
|
|
|
// DeleteIssueComment deletes an issue comment.
|
|
|
|
func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error {
|
|
|
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil)
|
|
|
|
return err
|
|
|
|
}
|