From 18fc5f6c40e88cbc84ecd60e23a03a493b5bd466 Mon Sep 17 00:00:00 2001 From: Edvard Makhlin Date: Thu, 23 May 2024 14:09:58 +0200 Subject: [PATCH] fix: Treat http no content as success --- server/events/vcs/bitbucketcloud/client.go | 2 +- server/events/vcs/bitbucketcloud/client_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/events/vcs/bitbucketcloud/client.go b/server/events/vcs/bitbucketcloud/client.go index a99c10c002..0d257da084 100644 --- a/server/events/vcs/bitbucketcloud/client.go +++ b/server/events/vcs/bitbucketcloud/client.go @@ -337,7 +337,7 @@ func (b *Client) makeRequest(method string, path string, reqBody io.Reader) ([]b defer resp.Body.Close() // nolint: errcheck requestStr := fmt.Sprintf("%s %s", method, path) - if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent { respBody, _ := io.ReadAll(resp.Body) return nil, fmt.Errorf("making request %q unexpected status code: %d, body: %s", requestStr, resp.StatusCode, string(respBody)) } diff --git a/server/events/vcs/bitbucketcloud/client_test.go b/server/events/vcs/bitbucketcloud/client_test.go index d3832f09e8..eb7b19ecbb 100644 --- a/server/events/vcs/bitbucketcloud/client_test.go +++ b/server/events/vcs/bitbucketcloud/client_test.go @@ -431,7 +431,9 @@ func TestClient_DeleteComment(t *testing.T) { testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.RequestURI { case "/2.0/repositories/myorg/myrepo/pullrequests/5/comments/1": - w.Write([]byte("")) // nolint: errcheck + if r.Method == "DELETE" { + w.WriteHeader(http.StatusNoContent) + } return default: t.Errorf("got unexpected request at %q", r.RequestURI) @@ -472,11 +474,17 @@ func TestClient_HidePRComments(t *testing.T) { // we have two comments in the test file // The code is going to delete them all and then create a new one case "/2.0/repositories/myorg/myrepo/pullrequests/5/comments/498931882": + if r.Method == "DELETE" { + w.WriteHeader(http.StatusNoContent) + } w.Write([]byte("")) // nolint: errcheck called += 1 return // This is the second one case "/2.0/repositories/myorg/myrepo/pullrequests/5/comments/498931784": + if r.Method == "DELETE" { + http.Error(w, "", http.StatusNoContent) + } w.Write([]byte("")) // nolint: errcheck called += 1 return