Tune CheckNotifications for api change (#308)
notification Check now always return json make fmt relicts CheckNotifications: one api call is enouth add getResponseWithStatus to handle Response customized based on Status Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/308 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
2f920dbb01
commit
50efd911c8
3 changed files with 5 additions and 13 deletions
|
@ -6,7 +6,6 @@ package gitea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -67,18 +66,11 @@ func (c *Client) CheckNotifications() (int64, error) {
|
||||||
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
status, err := c.getStatusCode("GET", "/notifications/new", nil, nil)
|
|
||||||
if err != nil || status == http.StatusNoContent {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
new := struct {
|
new := struct {
|
||||||
New int64 `json:"new"`
|
New int64 `json:"new"`
|
||||||
}{}
|
}{}
|
||||||
if err := c.getParsedResponse("GET", "/notifications/new", nil, nil, &new); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return new.New, nil
|
|
||||||
|
|
||||||
|
return new.New, c.getParsedResponse("GET", "/notifications/new", jsonHeader, nil, &new)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotification get notification thread by ID
|
// GetNotification get notification thread by ID
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestOauth2(t *testing.T) {
|
||||||
user := createTestUser(t, "oauth2_user", c)
|
user := createTestUser(t, "oauth2_user", c)
|
||||||
c.SetSudo(user.UserName)
|
c.SetSudo(user.UserName)
|
||||||
|
|
||||||
newApp, err := c.CreateOauth2(CreateOauth2Option{Name: "test", RedirectURIs: []string{"http://test/test",}})
|
newApp, err := c.CreateOauth2(CreateOauth2Option{Name: "test", RedirectURIs: []string{"http://test/test"}})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, newApp)
|
assert.NotNil(t, newApp)
|
||||||
assert.EqualValues(t, "test", newApp.Name)
|
assert.EqualValues(t, "test", newApp.Name)
|
||||||
|
|
Loading…
Reference in a new issue