diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /lib/atlassian | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'lib/atlassian')
-rw-r--r-- | lib/atlassian/jira_connect.rb | 8 | ||||
-rw-r--r-- | lib/atlassian/jira_connect/client.rb | 36 | ||||
-rw-r--r-- | lib/atlassian/jira_connect/jwt/asymmetric.rb | 6 | ||||
-rw-r--r-- | lib/atlassian/jira_connect/serializers/build_entity.rb | 10 |
4 files changed, 33 insertions, 27 deletions
diff --git a/lib/atlassian/jira_connect.rb b/lib/atlassian/jira_connect.rb index 595cf0ac465..3ebed08280a 100644 --- a/lib/atlassian/jira_connect.rb +++ b/lib/atlassian/jira_connect.rb @@ -17,8 +17,16 @@ module Atlassian private def gitlab_host + return host_from_settings if Gitlab::CurrentSettings.jira_connect_proxy_url? + Gitlab.config.gitlab.host end + + def host_from_settings + uri = URI(Gitlab::CurrentSettings.jira_connect_proxy_url) + + uri.hostname + uri.path + end end end end diff --git a/lib/atlassian/jira_connect/client.rb b/lib/atlassian/jira_connect/client.rb index 3c999920d39..96e285f4eea 100644 --- a/lib/atlassian/jira_connect/client.rb +++ b/lib/atlassian/jira_connect/client.rb @@ -76,7 +76,7 @@ module Atlassian return if items.empty? r = post('/rest/deployments/0.1/bulk', { deployments: items }) - handle_response(r, 'deployments') { |data| errors(data, 'rejectedDeployments') } + handle_response(r, 'deployments') { |data| errors(data, 'rejectedDeployments', r) } end def store_build_info(project:, pipelines:, update_sequence_id: nil) @@ -92,7 +92,7 @@ module Atlassian return if builds.empty? r = post('/rest/builds/0.1/bulk', { builds: builds }) - handle_response(r, 'builds') { |data| errors(data, 'rejectedBuilds') } + handle_response(r, 'builds') { |data| errors(data, 'rejectedBuilds', r) } end def store_dev_info(project:, commits: nil, branches: nil, merge_requests: nil, update_sequence_id: nil) @@ -132,22 +132,20 @@ module Atlassian if [200, 202].include?(response.code) yield data else - message = case response.code - when 400 then { 'errorMessages' => data.map { |e| e['message'] } } - when 401 then { 'errorMessages' => ['Invalid JWT'] } - when 403 then { 'errorMessages' => ["App does not support #{name}"] } - when 413 then { 'errorMessages' => ['Data too large'] + data.map { |e| e['message'] } } - when 429 then { 'errorMessages' => ['Rate limit exceeded'] } - when 503 then { 'errorMessages' => ['Service unavailable'] } - else - { 'errorMessages' => ['Unknown error'], 'response' => data } - end - - message.merge('responseCode' => response.code) + case response.code + when 400 then { 'errorMessages' => data.map { |e| e['message'] } } + when 401 then { 'errorMessages' => ['Invalid JWT'] } + when 403 then { 'errorMessages' => ["App does not support #{name}"] } + when 413 then { 'errorMessages' => ['Data too large'] + data.map { |e| e['message'] } } + when 429 then { 'errorMessages' => ['Rate limit exceeded'] } + when 503 then { 'errorMessages' => ['Service unavailable'] } + else + { 'errorMessages' => ['Unknown error'], 'response' => data } + end.merge('responseCode' => response.code) end end - def errors(data, key) + def errors(data, key, response) messages = if data[key].present? data[key].flat_map do |rejection| rejection['errors'].map { |e| e['message'] } @@ -156,7 +154,13 @@ module Atlassian [] end - { 'errorMessages' => messages } + { 'errorMessages' => messages, 'responseCode' => response.code, 'requestBody' => request_body_schema(response) } + end + + def request_body_schema(response) + Oj.load(response.request.raw_body).deep_transform_values! {} + rescue Oj::ParseError, EncodingError, Encoding::UndefinedConversionError + 'Request body includes invalid JSON' end def user_notes_count(merge_requests) diff --git a/lib/atlassian/jira_connect/jwt/asymmetric.rb b/lib/atlassian/jira_connect/jwt/asymmetric.rb index 573a8022752..7c1cf1cabb6 100644 --- a/lib/atlassian/jira_connect/jwt/asymmetric.rb +++ b/lib/atlassian/jira_connect/jwt/asymmetric.rb @@ -77,11 +77,7 @@ module Atlassian end def public_key_cdn_url - if public_key_cdn_url_setting.blank? || Feature.disabled?(:jira_connect_oauth_self_managed) - return DEFAULT_PUBLIC_KEY_CDN_URL - end - - public_key_cdn_url_setting + public_key_cdn_url_setting.presence || DEFAULT_PUBLIC_KEY_CDN_URL end def public_key_cdn_url_setting diff --git a/lib/atlassian/jira_connect/serializers/build_entity.rb b/lib/atlassian/jira_connect/serializers/build_entity.rb index 10e4bb0e709..aa864cb268f 100644 --- a/lib/atlassian/jira_connect/serializers/build_entity.rb +++ b/lib/atlassian/jira_connect/serializers/build_entity.rb @@ -24,12 +24,10 @@ module Atlassian def issue_keys # extract Jira issue keys from either the source branch/ref or the # merge request title. - @issue_keys ||= begin - pipeline.all_merge_requests.flat_map do |mr| - src = "#{mr.source_branch} #{mr.title} #{mr.description}" - JiraIssueKeyExtractor.new(src).issue_keys - end.uniq - end + @issue_keys ||= pipeline.all_merge_requests.flat_map do |mr| + src = "#{mr.source_branch} #{mr.title} #{mr.description}" + JiraIssueKeyExtractor.new(src).issue_keys + end.uniq end private |