mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-07-02 03:55:55 +00:00
Add pull-request implementation for bitbucket forge (#1889)
This commit is contained in:
parent
3033abc3b4
commit
456725dde7
|
@ -302,8 +302,21 @@ func (c *config) BranchHead(_ context.Context, _ *model.User, _ *model.Repo, _ s
|
||||||
return "", forge_types.ErrNotImplemented
|
return "", forge_types.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) PullRequests(_ context.Context, _ *model.User, _ *model.Repo, _ *model.ListOptions) ([]*model.PullRequest, error) {
|
// PullRequests returns the pull requests of the named repository.
|
||||||
return nil, forge_types.ErrNotImplemented
|
func (c *config) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) {
|
||||||
|
opts := internal.ListOpts{Page: p.Page, PageLen: p.Page}
|
||||||
|
pullRequests, err := c.newClient(ctx, u).ListPullRequests(r.Owner, r.Name, &opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := []*model.PullRequest{}
|
||||||
|
for _, pullRequest := range pullRequests {
|
||||||
|
result = append(result, &model.PullRequest{
|
||||||
|
Index: int64(pullRequest.ID),
|
||||||
|
Title: pullRequest.Title,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook parses the incoming Bitbucket hook and returns the Repository and
|
// Hook parses the incoming Bitbucket hook and returns the Repository and
|
||||||
|
|
|
@ -34,18 +34,19 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pathUser = "%s/2.0/user/"
|
pathUser = "%s/2.0/user/"
|
||||||
pathEmails = "%s/2.0/user/emails"
|
pathEmails = "%s/2.0/user/emails"
|
||||||
pathPermissions = "%s/2.0/user/permissions/repositories?q=repository.full_name=%q"
|
pathPermissions = "%s/2.0/user/permissions/repositories?q=repository.full_name=%q"
|
||||||
pathWorkspace = "%s/2.0/workspaces/?%s"
|
pathWorkspace = "%s/2.0/workspaces/?%s"
|
||||||
pathRepo = "%s/2.0/repositories/%s/%s"
|
pathRepo = "%s/2.0/repositories/%s/%s"
|
||||||
pathRepos = "%s/2.0/repositories/%s?%s"
|
pathRepos = "%s/2.0/repositories/%s?%s"
|
||||||
pathHook = "%s/2.0/repositories/%s/%s/hooks/%s"
|
pathHook = "%s/2.0/repositories/%s/%s/hooks/%s"
|
||||||
pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s"
|
pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s"
|
||||||
pathSource = "%s/2.0/repositories/%s/%s/src/%s/%s"
|
pathSource = "%s/2.0/repositories/%s/%s/src/%s/%s"
|
||||||
pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build"
|
pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build"
|
||||||
pathBranches = "%s/2.0/repositories/%s/%s/refs/branches"
|
pathBranches = "%s/2.0/repositories/%s/%s/refs/branches"
|
||||||
pathOrgPerms = "%s/2.0/workspaces/%s/permissions?%s"
|
pathOrgPerms = "%s/2.0/workspaces/%s/permissions?%s"
|
||||||
|
pathPullRequests = "%s/2.0/repositories/%s/%s/pullrequests"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -204,6 +205,13 @@ func (c *Client) GetUserWorkspaceMembership(workspace, user string) (string, err
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) ListPullRequests(owner, name string, opts *ListOpts) ([]*PullRequest, error) {
|
||||||
|
out := new(PullRequestResp)
|
||||||
|
uri := fmt.Sprintf(pathPullRequests, c.base, owner, name)
|
||||||
|
_, err := c.do(uri, get, opts.Encode(), out)
|
||||||
|
return out.Values, err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) do(rawurl, method string, in, out interface{}) (*string, error) {
|
func (c *Client) do(rawurl, method string, in, out interface{}) (*string, error) {
|
||||||
uri, err := url.Parse(rawurl)
|
uri, err := url.Parse(rawurl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -259,3 +259,15 @@ type BranchResp struct {
|
||||||
type Branch struct {
|
type Branch struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PullRequestResp struct {
|
||||||
|
Page uint `json:"page"`
|
||||||
|
PageLen uint `json:"pagelen"`
|
||||||
|
Size uint `json:"size"`
|
||||||
|
Values []*PullRequest `json:"values"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PullRequest struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue