Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/api/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ func (c *RESTClient) DoWithContext(ctx context.Context, method string, path stri
return err
}

err = json.Unmarshal(b, &response)
if err != nil {
return err
if len(b) > 0 {
err = json.Unmarshal(b, &response)
if err != nil {
return err
}
}

return nil
Expand Down
19 changes: 19 additions & 0 deletions pkg/api/rest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,25 @@ func TestRESTClientPatch(t *testing.T) {
assert.True(t, gock.IsDone(), printPendingMocks(gock.Pending()))
}

// Covers https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#mark-a-thread-as-read
func TestRESTClientPatchNoResponseBody(t *testing.T) {
t.Cleanup(gock.Off)
gock.New("https://api.github.com").
Patch("/some/path/here").
BodyString(`{}`).
Reply(205).
BodyString("")
client, _ := NewRESTClient(ClientOptions{
Host: "github.com",
AuthToken: "token",
Transport: http.DefaultTransport,
})
r := bytes.NewReader([]byte(`{}`))
err := client.Patch("some/path/here", r, nil)
assert.NoError(t, err)
assert.True(t, gock.IsDone(), printPendingMocks(gock.Pending()))
}

func TestRESTClientPost(t *testing.T) {
t.Cleanup(gock.Off)
gock.New("https://api.github.com").
Expand Down