2016-08-25 04:58:09 +01: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.
|
|
|
|
|
2016-11-07 01:57:49 +00:00
|
|
|
package gitea
|
2016-08-25 04:49:11 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2019-05-11 16:38:52 +01:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2016-08-25 04:49:11 +01:00
|
|
|
)
|
|
|
|
|
2019-05-11 16:38:52 +01:00
|
|
|
// Comment is equal to structs.Comment
|
|
|
|
type Comment = structs.Comment
|
2016-08-25 04:49:11 +01:00
|
|
|
|
2016-08-25 04:58:09 +01:00
|
|
|
// ListIssueComments list comments on an issue.
|
|
|
|
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
|
2016-08-25 04:49:11 +01:00
|
|
|
comments := make([]*Comment, 0, 10)
|
2016-08-25 04:58:09 +01:00
|
|
|
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
|
2016-08-25 04:49:11 +01:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:57:33 +00:00
|
|
|
// ListRepoIssueComments list comments for a given repo.
|
2016-11-10 15:08:54 +00:00
|
|
|
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
|
2016-11-09 15:57:33 +00:00
|
|
|
comments := make([]*Comment, 0, 10)
|
|
|
|
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
|
|
|
|
}
|
|
|
|
|
2016-08-25 04:58:09 +01:00
|
|
|
// CreateIssueComment create comment on an issue.
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt structs.CreateIssueCommentOption) (*Comment, error) {
|
2016-08-25 04:49:11 +01:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
comment := new(Comment)
|
2017-03-13 01:37:12 +00:00
|
|
|
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
2016-08-25 04:49:11 +01:00
|
|
|
}
|
|
|
|
|
2016-08-25 04:58:09 +01:00
|
|
|
// EditIssueComment edits an issue comment.
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt structs.EditIssueCommentOption) (*Comment, error) {
|
2016-08-25 04:49:11 +01:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
comment := new(Comment)
|
2016-08-25 04:58:09 +01:00
|
|
|
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
|
2016-08-25 04:49:11 +01:00
|
|
|
}
|
2016-11-09 15:57:33 +00: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
|
|
|
|
}
|