Skip to content

Commit

Permalink
fix: Treat http no content as success
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Makhlin committed May 23, 2024
1 parent a6cd810 commit 32636d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/events/vcs/bitbucketcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
10 changes: 9 additions & 1 deletion server/events/vcs/bitbucketcloud/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 32636d0

Please sign in to comment.