Skip to content

issues comment API client #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions issue_comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package gogs

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)

// CommentType is type of a comment
type CommentType int

// Comment represents a comment in commit and issue page.
type Comment struct {
ID int64 `json:"id"`
Type CommentType `json:"type"`
Poster *User `json:"poster"`
IssueID int64 `json:"issue_id"`
CommitID int64 `json:"commit_id"`
Line int64 `json:"line"`
Content string `json:"content"`

Created time.Time `json:"created"`
CreatedUnix int64 `json:"created_unix"`

// Reference issue in commit message
CommitSHA string `json:"commit_sha"`

//Attachments []*Attachment `json:"attachments"`
}

// ListRepoIssueComments list comments on an issue
func (c *Client) ListRepoIssueComments(owner, repo string, issueID int64) ([]*Comment, error) {
comments := make([]*Comment, 0, 10)
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, issueID), nil, nil, &comments)
}

// CreateIssueCommentOption is option when creating an issue comment
type CreateIssueCommentOption struct {
Content string `json:"content" binding:"required"`
}

// CreateIssueComment create comment on an issue
func (c *Client) CreateIssueComment(owner, repo string, issueID 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, issueID),
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), comment)
}

// EditIssueCommentOption is option when editing an issue comment
type EditIssueCommentOption struct {
Content string `json:"content" binding:"required"`
}

// EditIssueComment edits an issue comment
func (c *Client) EditIssueComment(owner, repo string, issueID, 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, issueID, commentID),
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), comment)
}