Add GetIssueComment (#216)

Merge branch 'master' into update-comment-api

Fix & Refactor UserApp Functions (#247)

Merge branch 'master' into refactor-user-app

Add SearchRepo API Call (#254)

Merge branch 'master' into search_repo

IssueSubscribtion: Check http Status responce (#242)

Merge branch 'master' into impruve-issueWatch

Refactor RepoWatch (#241)

Merge branch 'master' into refactor-repoWatch

Add ListMilestoneOption to ListRepoMilestones (#244)

use StateType

use PageSize

adjut test since gitea bug got fixed (#gitea/10047)

add TestMilestones

add optional ListMilestoneOption

format

Add ListOptions struct (#249)

same struct as in models/list_options.go

add mising license header

add ListOptions struct

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/249
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: lafriks <lafriks@noreply.gitea.io>

[README] add import path (#239)

add import path

add import path to readme

Changelog v0.11.0 (#235)

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/235
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>

Add TestMyUser (#237)

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/237
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/239
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/244
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Merge branch 'master' into refactor-repoWatch

Add ListOptions struct (#249)

same struct as in models/list_options.go

add mising license header

add ListOptions struct

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/249
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: lafriks <lafriks@noreply.gitea.io>

add TEST

fix GetMyWatchedRepos

[README] add import path (#239)

add import path

add import path to readme

Changelog v0.11.0 (#235)

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/235
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>

Add TestMyUser (#237)

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/237
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/239
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>

refactor RepoWatch
 * add CheckRepoWatch
 * add GetMyWatchedRepos
 * minimize func_options on GetWatchedRepos
 * WatchRepo return nil/error
 * UnWatchRepo return nil/error

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/241
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>

Merge branch 'master' into impruve-issueWatch

Add ListMilestoneOption to ListRepoMilestones (#244)

use StateType

use PageSize

adjut test since gitea bug got fixed (#gitea/10047)

add TestMilestones

add optional ListMilestoneOption

format

Add ListOptions struct (#249)

same struct as in models/list_options.go

add mising license header

add ListOptions struct

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/249
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: lafriks <lafriks@noreply.gitea.io>

[README] add import path (#239)

add import path

add import path to readme

Changelog v0.11.0 (#235)

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/235
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>

Add TestMyUser (#237)

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/237
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/239
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/244
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>

Add ListOptions struct (#249)

same struct as in models/list_options.go

add mising license header

add ListOptions struct
...

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: spawn2kill <spawn2kill@noreply.gitea.io>
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/216
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543 2020-02-02 09:03:40 +00:00 committed by Lunny Xiao
parent 1fdd832cc2
commit 740b6fd1cc
3 changed files with 102 additions and 0 deletions

View file

@ -37,6 +37,15 @@ func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
} }
// GetIssueComment get a comment for a given repo by id.
func (c *Client) GetIssueComment(owner, repo string, id int64) (*Comment, error) {
comment := new(Comment)
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
return comment, err
}
return comment, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, id), nil, nil, &comment)
}
// CreateIssueCommentOption options for creating a comment on an issue // CreateIssueCommentOption options for creating a comment on an issue
type CreateIssueCommentOption struct { type CreateIssueCommentOption struct {
Body string `json:"body"` Body string `json:"body"`

View file

@ -0,0 +1,82 @@
// 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 (
"github.com/stretchr/testify/assert"
"log"
"testing"
)
// TestIssueComment creat a issue and test comment creation/edit/deletion on it
func TestIssueComment(t *testing.T) {
log.Println("== TestIssueComment ==")
c := newTestClient()
user, err := c.GetMyUserInfo()
assert.NoError(t, err)
repo, err := createTestRepo(t, "TestIssueCommentRepo", c)
assert.NoError(t, err)
issue1, err := c.CreateIssue(user.UserName, repo.Name, CreateIssueOption{Title: "issue1", Body: "body", Closed: false})
assert.EqualValues(t, 1, issue1.Index)
issue2, err := c.CreateIssue(user.UserName, repo.Name, CreateIssueOption{Title: "issue1", Body: "body", Closed: false})
assert.EqualValues(t, 2, issue2.Index)
assert.NoError(t, err)
tUser2 := createTestUser(t, "Commenter2", c)
tUser3 := createTestUser(t, "Commenter3", c)
createOne := func(u *User, issue int64, text string) {
c.sudo = u.UserName
comment, e := c.CreateIssueComment(user.UserName, repo.Name, issue, CreateIssueCommentOption{Body: text})
c.sudo = ""
assert.NoError(t, e)
assert.NotEmpty(t, comment)
assert.EqualValues(t, text, comment.Body)
assert.EqualValues(t, u.ID, comment.Poster.ID)
}
// CreateIssue
createOne(user, 1, "what a nice issue")
createOne(tUser2, 1, "dont think so")
createOne(tUser3, 1, "weow weow")
createOne(user, 1, "spam isn't it?")
createOne(tUser3, 2, "hehe first commit")
createOne(tUser2, 2, "second")
createOne(user, 2, "3")
assert.NoError(t, c.AdminDeleteUser(tUser3.UserName))
// ListRepoIssueComments
comments, err := c.ListRepoIssueComments(user.UserName, repo.Name)
assert.NoError(t, err)
assert.Len(t, comments, 7)
// ListIssueComments
comments, err = c.ListIssueComments(user.UserName, repo.Name, 2)
assert.NoError(t, err)
assert.Len(t, comments, 3)
// GetIssueComment
comment, err := c.GetIssueComment(user.UserName, repo.Name, comments[1].ID)
assert.NoError(t, err)
assert.EqualValues(t, comment.Poster.ID, comments[1].Poster.ID)
assert.EqualValues(t, comment.Body, comments[1].Body)
assert.EqualValues(t, comment.Updated.Unix(), comments[1].Updated.Unix())
// EditIssueComment
comment, err = c.EditIssueComment(user.UserName, repo.Name, comments[1].ID, EditIssueCommentOption{
Body: "changed my mind",
})
assert.NoError(t, err)
assert.EqualValues(t, "changed my mind", comment.Body)
assert.NotEqual(t, comment.Updated.Unix(), comments[1].Updated.Unix())
// DeleteIssueComment
assert.NoError(t, c.DeleteIssueComment(user.UserName, repo.Name, comments[1].ID))
_, err = c.GetIssueComment(user.UserName, repo.Name, comments[1].ID)
assert.Error(t, err)
}

View file

@ -45,3 +45,14 @@ func TestUserApp(t *testing.T) {
result, _ = c.ListAccessTokens(c.username, c.password) result, _ = c.ListAccessTokens(c.username, c.password)
assert.Len(t, result, 1) assert.Len(t, result, 1)
} }
func createTestUser(t *testing.T, username string, client *Client) *User {
bFalse := false
user, _ := client.GetUserInfo(username)
if user.ID != 0 {
return user
}
user, err := client.AdminCreateUser(CreateUserOption{Username: username, Password: username + "!1234", Email: username + "@gitea.io", MustChangePassword: &bFalse, SendNotify: bFalse})
assert.NoError(t, err)
return user
}