From 50efd911c8ecab6d7c6e026fd3e637b415f14fd9 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Tue, 14 Apr 2020 13:29:44 +0000 Subject: [PATCH] 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 Reviewed-by: Andrew Thornton --- gitea/notifications.go | 10 +--------- gitea/oauth2.go | 6 +++--- gitea/oauth2_test.go | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/gitea/notifications.go b/gitea/notifications.go index 29bf40f..d588bf7 100644 --- a/gitea/notifications.go +++ b/gitea/notifications.go @@ -6,7 +6,6 @@ package gitea import ( "fmt" - "net/http" "net/url" "time" ) @@ -67,18 +66,11 @@ func (c *Client) CheckNotifications() (int64, error) { if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { return 0, err } - status, err := c.getStatusCode("GET", "/notifications/new", nil, nil) - if err != nil || status == http.StatusNoContent { - return 0, err - } new := struct { 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 diff --git a/gitea/oauth2.go b/gitea/oauth2.go index 8f619e7..4f0e712 100644 --- a/gitea/oauth2.go +++ b/gitea/oauth2.go @@ -28,8 +28,8 @@ type ListOauth2Option struct { // CreateOauth2Option required options for creating an Application type CreateOauth2Option struct { - Name string `json:"name"` - RedirectURIs []string `json:"redirect_uris"` + Name string `json:"name"` + RedirectURIs []string `json:"redirect_uris"` } // CreateOauth2 create an Oauth2 Application and returns a completed Oauth2 object. @@ -56,7 +56,7 @@ func (c *Client) ListOauth2(opt ListOauth2Option) ([]*Oauth2, error) { } // DeleteOauth2 delete an Oauth2 application by name -func (c *Client) DeleteOauth2(oauth2id int64) error { +func (c *Client) DeleteOauth2(oauth2id int64) error { if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil { return e } diff --git a/gitea/oauth2_test.go b/gitea/oauth2_test.go index c335fad..3b4ae0e 100644 --- a/gitea/oauth2_test.go +++ b/gitea/oauth2_test.go @@ -18,7 +18,7 @@ func TestOauth2(t *testing.T) { user := createTestUser(t, "oauth2_user", c) 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.NotNil(t, newApp) assert.EqualValues(t, "test", newApp.Name)