Rely on HTTP status instead of HTTP response body
Context
Closes #1441 (closed)
What does this MR do and why?
Rely on the HTTP status code instead of the HTTP response body for the CommonRoomApiClient
class.
Reproduce locally
Clone the branch locally, and run the following:
bundle exec rack-console
HTTP 400 status
[1] pry(main)> CommonRoomApiClient.new.add_activity(activityType: 'test', id: 1234)
StandardError: Error sending test-1234 to Common Room: {"status":"invalid-request-body","docs":"https://api.commonroom.io/docs/community.html"} (HTTP code: 400)
from /Users/gitlab/src/triage-ops/triage/triage/common_room_api_client.rb:23:in `add_activity'
HTTP 403 status
[3] pry(main)> CommonRoomApiClient.new.add_activity(activityType: 'test', id: 1234)
StandardError: Error sending test-1234 to Common Room: {"reason":"Token not valid"} (HTTP code: 403)
HTTP 200 status
For this one, I didn't want to do the original query, as it is a POST. Instead, I'll use a GET
endpoint to just test we can retrieve resources from the API correctly:
# triage/triage/common_room_api_client.rb
# Before
response = self.class.post('/source/22150/activity', headers: @headers, body: body.to_json)
# After
response = self.class.get('/activityTypes', headers: @headers, body: body.to_json)
=> nil
# Using the debugger before the guard clause, we indeed receive a JSON object from the API
Expected impact & dry-runs
These are strongly recommended to assist reviewers and reduce the time to merge your change.
See https://gitlab.com/gitlab-org/quality/triage-ops/-/tree/master/doc/scheduled#testing-policies-with-a-dry-run on how to perform dry-runs for new policies.
See https://gitlab.com/gitlab-org/quality/triage-ops/-/blob/master/doc/reactive/best_practices.md#use-the-sandbox-to-test-new-processors on how to make sure a new processor can be tested.
Action items
-
If adding environment variables for reactive processors, update config/triage-web.yaml
and.gitlab/ci/triage-web.yml
-
(If applicable) Add documentation to the handbook pages for Triage Operations => - (If applicable) Identify the affected groups and how to communicate to them:
-
/cc @ person_or_group
=> -
Relevant Slack channels => -
Engineering week-in-review
-
Closes #1441 (closed)