Add the Accept/Reject transfer of a repository. (#586)

- Allow to Accept or Reject a transfer of a repository via the API. Only
- available for v1.16+
- Ref: https://github.com/go-gitea/gitea/pull/17963

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/586
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-committed-by: Gusted <williamzijl7@hotmail.com>
This commit is contained in:
Gusted 2022-04-28 09:27:56 +08:00 committed by John Olheiser
parent 559cc2fb2a
commit ad3580e44d
2 changed files with 28 additions and 1 deletions

View file

@ -34,3 +34,29 @@ func (c *Client) TransferRepo(owner, reponame string, opt TransferRepoOption) (*
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/transfer", owner, reponame), jsonHeader, bytes.NewReader(body), repo) resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/transfer", owner, reponame), jsonHeader, bytes.NewReader(body), repo)
return repo, resp, err return repo, resp, err
} }
// AcceptRepoTransfer accepts a repo transfer.
func (c *Client) AcceptRepoTransfer(owner, reponame string) (*Repository, *Response, error) {
if err := escapeValidatePathSegments(&owner, &reponame); err != nil {
return nil, nil, err
}
if err := c.checkServerVersionGreaterThanOrEqual(version1_16_0); err != nil {
return nil, nil, err
}
repo := new(Repository)
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/transfer/accept", owner, reponame), jsonHeader, nil, repo)
return repo, resp, err
}
// RejectRepoTransfer rejects a repo transfer.
func (c *Client) RejectRepoTransfer(owner, reponame string) (*Repository, *Response, error) {
if err := escapeValidatePathSegments(&owner, &reponame); err != nil {
return nil, nil, err
}
if err := c.checkServerVersionGreaterThanOrEqual(version1_16_0); err != nil {
return nil, nil, err
}
repo := new(Repository)
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/transfer/reject", owner, reponame), jsonHeader, nil, repo)
return repo, resp, err
}

View file

@ -12,7 +12,7 @@ import (
// ServerVersion returns the version of the server // ServerVersion returns the version of the server
func (c *Client) ServerVersion() (string, *Response, error) { func (c *Client) ServerVersion() (string, *Response, error) {
var v = struct { v := struct {
Version string `json:"version"` Version string `json:"version"`
}{} }{}
resp, err := c.getParsedResponse("GET", "/version", nil, nil, &v) resp, err := c.getParsedResponse("GET", "/version", nil, nil, &v)
@ -65,6 +65,7 @@ var (
version1_13_0, _ = version.NewVersion("1.13.0") version1_13_0, _ = version.NewVersion("1.13.0")
version1_14_0, _ = version.NewVersion("1.14.0") version1_14_0, _ = version.NewVersion("1.14.0")
version1_15_0, _ = version.NewVersion("1.15.0") version1_15_0, _ = version.NewVersion("1.15.0")
version1_16_0, _ = version.NewVersion("1.16.0")
) )
// checkServerVersionGreaterThanOrEqual is the canonical way in the SDK to check for versions for API compatibility reasons // checkServerVersionGreaterThanOrEqual is the canonical way in the SDK to check for versions for API compatibility reasons