c02398aaf3
enable race test make go-vet happy code format secound Func RWMutex fix prevent race condition add TEST cleanup make go-version work without vendoring dont change library version use Server Version Check on NewClient save serverVersion Makefile: export test env var (#234) exporte test var to env on test target Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/234 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: John Olheiser <john.olheiser@gmail.com> use golangci-lint and revive for linting (match main repo) (#220) Co-authored-by: 6543 <6543@noreply.gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/220 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: John Olheiser <john.olheiser@gmail.com> [Makefile] Add "test-instance"; Add "help" (#231) PASSWORD_COMPLEXITY = off fix test Makefile: add "test-instance" (start a gitea instance for test) and add a help menue Fix ListIssue Functions (now respect ListIssueOption's) (#225) fix test add Test add more test cases and fix nice log add Issue Tests impruve more Repo Tests and mv createTestRepo introduce "createTestRepo" a standad func to create a repo for testing add workaround * Update Dates * Fix ListIssueOption Fix ListRepoPullRequests (#219) add ToDo notice add ListRepoPullRequests TEST remove useless drone config emtrys fmt ping CI add new Options from PR #217 use query params Add some PR list options (#217) Empty Commit Add enums Add some PR list options Add test framework (#227) [Extend] StopWatch struct & functions (#211) add StopWatch struct & functions [Add] reaction struct and functions (#213) add struct and functions Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] issue Un-/Subscription function (#214) fix lint add issue subscription function Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] GetBlob (#212) fix header from PR 206 add GetBlob Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: 6543 <6543@noreply.gitea.io> Add test framework (#227) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Add some PR list options (#217) Empty Commit Add enums Add some PR list options Add test framework (#227) [Extend] StopWatch struct & functions (#211) add StopWatch struct & functions [Add] reaction struct and functions (#213) add struct and functions Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] issue Un-/Subscription function (#214) fix lint add issue subscription function Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] GetBlob (#212) fix header from PR 206 add GetBlob Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: 6543 <6543@noreply.gitea.io> Add test framework (#227) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/225 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/231 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Fix ListIssue Functions (now respect ListIssueOption's) (#225) fix test add Test add more test cases and fix nice log add Issue Tests impruve more Repo Tests and mv createTestRepo introduce "createTestRepo" a standad func to create a repo for testing add workaround * Update Dates * Fix ListIssu... Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/215 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: lafriks <lafriks@noreply.gitea.io>
98 lines
3.6 KiB
Go
98 lines
3.6 KiB
Go
// Copyright 2020 The Gitea 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"
|
|
)
|
|
|
|
// Reaction contain one reaction
|
|
type Reaction struct {
|
|
User *User `json:"user"`
|
|
Reaction string `json:"content"`
|
|
Created time.Time `json:"created_at"`
|
|
}
|
|
|
|
// GetIssueReactions get a list reactions of an issue
|
|
func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction, error) {
|
|
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
|
return nil, err
|
|
}
|
|
reactions := make([]*Reaction, 0, 10)
|
|
return reactions, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), nil, nil, &reactions)
|
|
}
|
|
|
|
// GetIssueCommentReactions get a list of reactions from a comment of an issue
|
|
func (c *Client) GetIssueCommentReactions(owner, repo string, commentID int64) ([]*Reaction, error) {
|
|
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
|
return nil, err
|
|
}
|
|
reactions := make([]*Reaction, 0, 10)
|
|
return reactions, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID), nil, nil, &reactions)
|
|
}
|
|
|
|
// editReactionOption contain the reaction type
|
|
type editReactionOption struct {
|
|
Reaction string `json:"content"`
|
|
}
|
|
|
|
// PostIssueReaction add a reaction to an issue
|
|
func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction string) (*Reaction, error) {
|
|
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
|
return nil, err
|
|
}
|
|
reactionResponse := new(Reaction)
|
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return reactionResponse, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index),
|
|
jsonHeader, bytes.NewReader(body), reactionResponse)
|
|
}
|
|
|
|
// DeleteIssueReaction remove a reaction from an issue
|
|
func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction string) error {
|
|
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
|
return err
|
|
}
|
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
|
return err
|
|
}
|
|
|
|
// PostIssueCommentReaction add a reaction to a comment of an issue
|
|
func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Reaction, error) {
|
|
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
|
return nil, err
|
|
}
|
|
reactionResponse := new(Reaction)
|
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return reactionResponse, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
|
jsonHeader, bytes.NewReader(body), reactionResponse)
|
|
}
|
|
|
|
// DeleteIssueCommentReaction remove a reaction from a comment of an issue
|
|
func (c *Client) DeleteIssueCommentReaction(owner, repo string, commentID int64, reaction string) error {
|
|
if err := c.CheckServerVersionConstraint(">=1.11.0"); err != nil {
|
|
return err
|
|
}
|
|
// swagger:operation DELETE /repos/{owner}/{repo}/issues/comments/{id}/reactions issue issueDeleteCommentReaction
|
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
|
jsonHeader, bytes.NewReader(body))
|
|
return err
|
|
}
|