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>
This commit is contained in:
parent
55dc2f1a68
commit
b24cfd841c
3 changed files with 83 additions and 10 deletions
|
@ -34,6 +34,7 @@ steps:
|
||||||
image: golang:1.13
|
image: golang:1.13
|
||||||
environment:
|
environment:
|
||||||
GOPROXY: https://goproxy.cn
|
GOPROXY: https://goproxy.cn
|
||||||
|
HTTP_PROXY: ""
|
||||||
GITEA_SDK_TEST_URL: "http://gitea:3000"
|
GITEA_SDK_TEST_URL: "http://gitea:3000"
|
||||||
GITEA_SDK_TEST_USERNAME: "test01"
|
GITEA_SDK_TEST_USERNAME: "test01"
|
||||||
GITEA_SDK_TEST_PASSWORD: "test01"
|
GITEA_SDK_TEST_PASSWORD: "test01"
|
||||||
|
@ -41,11 +42,9 @@ steps:
|
||||||
commands:
|
commands:
|
||||||
- make clean
|
- make clean
|
||||||
- make vet
|
- make vet
|
||||||
#- make lint
|
|
||||||
- make build
|
- make build
|
||||||
- export HTTP_PROXY=""
|
|
||||||
- curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance
|
- curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance
|
||||||
- HTTP_PROXY="" http_proxy="" make test
|
- make test
|
||||||
|
|
||||||
- name: discord
|
- name: discord
|
||||||
pull: always
|
pull: always
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,12 +69,26 @@ type ListPullRequestsOptions struct {
|
||||||
|
|
||||||
// ListRepoPullRequests list PRs of one repository
|
// ListRepoPullRequests list PRs of one repository
|
||||||
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
|
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
|
||||||
body, err := json.Marshal(&opt)
|
// declare variables
|
||||||
if err != nil {
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/pulls", owner, repo))
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
prs := make([]*PullRequest, 0, 10)
|
prs := make([]*PullRequest, 0, 10)
|
||||||
return prs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo), jsonHeader, bytes.NewReader(body), &prs)
|
query := make(url.Values)
|
||||||
|
// add options to query
|
||||||
|
if opt.Page > 0 {
|
||||||
|
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||||
|
}
|
||||||
|
if len(opt.State) > 0 {
|
||||||
|
query.Add("state", opt.State)
|
||||||
|
}
|
||||||
|
if len(opt.Sort) > 0 {
|
||||||
|
query.Add("sort", opt.Sort)
|
||||||
|
}
|
||||||
|
if opt.Milestone > 0 {
|
||||||
|
query.Add("milestone", fmt.Sprintf("%d", opt.Milestone))
|
||||||
|
}
|
||||||
|
link.RawQuery = query.Encode()
|
||||||
|
// request
|
||||||
|
return prs, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &prs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPullRequest get information of one PR
|
// GetPullRequest get information of one PR
|
||||||
|
|
59
gitea/pull_test.go
Normal file
59
gitea/pull_test.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
// 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 (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPull(t *testing.T) {
|
||||||
|
c := newTestClient()
|
||||||
|
user, err := c.GetMyUserInfo()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var repoName = "repo_pull_test"
|
||||||
|
repo, err := c.GetRepo(user.UserName, repoName)
|
||||||
|
if err != nil {
|
||||||
|
repo, err = c.CreateRepo(CreateRepoOption{
|
||||||
|
Name: repoName,
|
||||||
|
Description: "PullTests",
|
||||||
|
AutoInit: true,
|
||||||
|
Gitignores: "C,C++",
|
||||||
|
License: "MIT",
|
||||||
|
Readme: "Default",
|
||||||
|
Private: false,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoPullRequests list PRs of one repository
|
||||||
|
pulls, err := c.ListRepoPullRequests(user.UserName, repoName, ListPullRequestsOptions{
|
||||||
|
Page: 1,
|
||||||
|
State: "all",
|
||||||
|
Sort: "leastupdate",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, pulls, 0)
|
||||||
|
|
||||||
|
//ToDo add git stuff to have different branches witch can be used to create PRs and test merge etc ...
|
||||||
|
|
||||||
|
// GetPullRequest get information of one PR
|
||||||
|
//func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, error)
|
||||||
|
|
||||||
|
// CreatePullRequest create pull request with options
|
||||||
|
//func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error)
|
||||||
|
|
||||||
|
// EditPullRequest modify pull request with PR id and options
|
||||||
|
//func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, error)
|
||||||
|
|
||||||
|
// MergePullRequest merge a PR to repository by PR id
|
||||||
|
//func (c *Client) MergePullRequest(owner, repo string, index int64, opt MergePullRequestOption) (*MergePullRequestResponse, error)
|
||||||
|
|
||||||
|
// IsPullRequestMerged test if one PR is merged to one repository
|
||||||
|
//func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, error)
|
||||||
|
}
|
Loading…
Reference in a new issue