diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-23 12:09:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-23 12:09:51 +0300 |
commit | 66e4d1bf78b3ec2075135173b12767692ced242c (patch) | |
tree | 1ea67cbc46ee2c6b61e0872699a89f0fb600bef1 /qa | |
parent | 1d659e434d7c966a8a0c27fb17dc36d80ae70180 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/resource/api_fabricator.rb | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/qa/qa/resource/api_fabricator.rb b/qa/qa/resource/api_fabricator.rb index c1533577657..b94fa543b48 100644 --- a/qa/qa/resource/api_fabricator.rb +++ b/qa/qa/resource/api_fabricator.rb @@ -96,31 +96,35 @@ module QA end def api_post - if api_post_path == "/graphql" - graphql_response = post( - Runtime::API::Request.new(api_client, api_post_path).url, - query: api_post_body) + process_api_response(api_post_to(api_post_path, api_post_body)) + end + + def api_post_to(post_path, post_body) + if post_path == "/graphql" + graphql_response = post(Runtime::API::Request.new(api_client, post_path).url, query: post_body) - flattened_response = flatten_hash(parse_body(graphql_response)) + body = flatten_hash(parse_body(graphql_response)) - unless graphql_response.code == HTTP_STATUS_OK && flattened_response[:errors].empty? - raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{graphql_response.code}) with `#{graphql_response}`." + unless graphql_response.code == HTTP_STATUS_OK && (body[:errors].nil? || body[:errors].empty?) + raise(ResourceFabricationFailedError, <<~MSG) + Fabrication of #{self.class.name} using the API failed (#{graphql_response.code}) with `#{graphql_response}`. + MSG end - flattened_response[:web_url] = flattened_response.delete(:webUrl) - flattened_response[:id] = flattened_response.fetch(:id).split('/')[-1] + body[:id] = body.fetch(:id).split('/').last - process_api_response(flattened_response) + body.transform_keys { |key| key.to_s.underscore.to_sym } else - response = post( - Runtime::API::Request.new(api_client, api_post_path).url, - api_post_body) + response = post(Runtime::API::Request.new(api_client, post_path).url, post_body) unless response.code == HTTP_STATUS_CREATED - raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{response}`." + raise( + ResourceFabricationFailedError, + "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{response}`." + ) end - process_api_response(parse_body(response)) + parse_body(response) end end |