go-sdk/gitea/issue_comment.go

73 строки
2.6 KiB
Go
Исходник Обычный вид История

2016-08-25 06:58:09 +03: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
2016-08-25 06:49:11 +03:00
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
// Comment represents a comment in commit and issue page.
type Comment struct {
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"`
Created time.Time `json:"created_at"`
Updated time.Time `json:"updated_at"`
2016-08-25 06:49:11 +03:00
}
2016-08-25 06:58:09 +03:00
// ListIssueComments list comments on an issue.
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
2016-08-25 06:49:11 +03:00
comments := make([]*Comment, 0, 10)
2016-08-25 06:58:09 +03:00
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
2016-08-25 06:49:11 +03: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)
}
2016-08-25 06:58:09 +03:00
// CreateIssueCommentOption is option when creating an issue comment.
2016-08-25 06:49:11 +03:00
type CreateIssueCommentOption struct {
2016-08-25 06:58:09 +03:00
Body string `json:"body" binding:"Required"`
2016-08-25 06:49:11 +03:00
}
2016-08-25 06:58:09 +03:00
// CreateIssueComment create comment on an issue.
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
2016-08-25 06:49:11 +03:00
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
comment := new(Comment)
2016-08-25 06:58:09 +03: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 06:49:11 +03:00
}
2016-08-25 06:58:09 +03:00
// EditIssueCommentOption is option when editing an issue comment.
2016-08-25 06:49:11 +03:00
type EditIssueCommentOption struct {
2016-08-25 06:58:09 +03:00
Body string `json:"body" binding:"Required"`
2016-08-25 06:49:11 +03:00
}
2016-08-25 06:58:09 +03:00
// EditIssueComment edits an issue comment.
func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
2016-08-25 06:49:11 +03:00
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
comment := new(Comment)
2016-08-25 06:58:09 +03: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 06:49:11 +03: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
}