diff options
author | 6543 <6543@obermui.de> | 2021-01-21 20:33:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 20:33:58 +0100 |
commit | 81c833d92d04e0a5579e7168aba548dad7e17451 (patch) | |
tree | c928f1b43fc6e2f27603193f0eed657f0760c96d /vendor/github.com/gogs/go-gogs-client/issue_comment.go | |
parent | b5570d3e680570343c1552bfc972b19b161209cd (diff) | |
download | gitea-81c833d92d04e0a5579e7168aba548dad7e17451.tar.gz gitea-81c833d92d04e0a5579e7168aba548dad7e17451.zip |
Add support to migrate from gogs (#14342)
Add support to migrate gogs:
* issues
* comments
* labels
* milestones
* wiki
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'vendor/github.com/gogs/go-gogs-client/issue_comment.go')
-rw-r--r-- | vendor/github.com/gogs/go-gogs-client/issue_comment.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/github.com/gogs/go-gogs-client/issue_comment.go b/vendor/github.com/gogs/go-gogs-client/issue_comment.go new file mode 100644 index 0000000000..246af0d93e --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/issue_comment.go @@ -0,0 +1,70 @@ +// 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 gogs + +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"` + Poster *User `json:"user"` + Body string `json:"body"` + Created time.Time `json:"created_at"` + Updated time.Time `json:"updated_at"` +} + +// 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) +} + +// 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) +} + +// CreateIssueCommentOption is option when creating an issue comment. +type CreateIssueCommentOption struct { + 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) + return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment) +} + +// EditIssueCommentOption is option when editing an issue comment. +type EditIssueCommentOption struct { + 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) +} + +// 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 +} |