Migrate gitea-sdk to v0.12.0 (#133)

Migrate

Update code.gitea.io/sdk/gitea to v0.12.0.

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/133
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
6543
2020-05-27 13:48:09 +00:00
committed by Lunny Xiao
parent 3c312cb409
commit 59fe58577a
50 changed files with 1625 additions and 308 deletions

View File

@@ -22,7 +22,7 @@ var jsonHeader = http.Header{"content-type": []string{"application/json"}}
// Version return the library version
func Version() string {
return "0.11.1"
return "0.12.0"
}
// Client represents a Gitea API client.
@@ -31,6 +31,7 @@ type Client struct {
accessToken string
username string
password string
otp string
sudo string
client *http.Client
serverVersion *version.Version
@@ -58,6 +59,11 @@ func (c *Client) SetBasicAuth(username, password string) {
c.username, c.password = username, password
}
// SetOTP sets OTP for 2FA
func (c *Client) SetOTP(otp string) {
c.otp = otp
}
// SetHTTPClient replaces default http.Client with user given one.
func (c *Client) SetHTTPClient(client *http.Client) {
c.client = client
@@ -76,10 +82,13 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
if len(c.accessToken) != 0 {
req.Header.Set("Authorization", "token "+c.accessToken)
}
if len(c.otp) != 0 {
req.Header.Set("X-GITEA-OTP", c.otp)
}
if len(c.username) != 0 {
req.SetBasicAuth(c.username, c.password)
}
if c.sudo != "" {
if len(c.sudo) != 0 {
req.Header.Set("Sudo", c.sudo)
}
for k, v := range header {