diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 18:07:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 18:07:55 +0300 |
commit | 85e494935a8726dc98bb19ffa584488420e5011e (patch) | |
tree | 5acf279dab81a2363e4504a9679c32c16510542b /lib | |
parent | 4ce0bee95df15c05cdb0d777eba31fe753bc443b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 2 | ||||
-rw-r--r-- | lib/api/issues.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/app_text_logger.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/asciidoc/include_processor.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/github_import/client.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/import/merge_request_helpers.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/legacy_github_import/client.rb | 2 | ||||
-rw-r--r-- | lib/sentry/api_urls.rb | 39 | ||||
-rw-r--r-- | lib/sentry/client.rb | 4 | ||||
-rw-r--r-- | lib/sentry/client/event.rb | 9 | ||||
-rw-r--r-- | lib/sentry/client/issue.rb | 20 | ||||
-rw-r--r-- | lib/sentry/client/projects.rb | 9 |
12 files changed, 71 insertions, 51 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index e8ea4a9fac5..74f8edb0784 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1132,7 +1132,7 @@ module API expose :commit_events, :push_events, :issues_events, :confidential_issues_events expose :merge_requests_events, :tag_push_events, :note_events expose :confidential_note_events, :pipeline_events, :wiki_page_events - expose :job_events + expose :job_events, :comment_on_event_enabled end class ProjectService < ProjectServiceBasic diff --git a/lib/api/issues.rb b/lib/api/issues.rb index d0772c70ffb..4e21815fa35 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -220,18 +220,22 @@ module API issue_params = convert_parameters_from_legacy_format(issue_params) - issue = ::Issues::CreateService.new(user_project, - current_user, - issue_params.merge(request: request, api: true)).execute - - if issue.spam? - render_api_error!({ error: 'Spam detected' }, 400) - end - - if issue.valid? - present issue, with: Entities::Issue, current_user: current_user, project: user_project - else - render_validation_error!(issue) + begin + issue = ::Issues::CreateService.new(user_project, + current_user, + issue_params.merge(request: request, api: true)).execute + + if issue.spam? + render_api_error!({ error: 'Spam detected' }, 400) + end + + if issue.valid? + present issue, with: Entities::Issue, current_user: current_user, project: user_project + else + render_validation_error!(issue) + end + rescue ::ActiveRecord::RecordNotUnique + render_api_error!('Duplicated issue', 409) end end diff --git a/lib/gitlab/app_text_logger.rb b/lib/gitlab/app_text_logger.rb index 59ac57b2bb4..5b0439f43ad 100644 --- a/lib/gitlab/app_text_logger.rb +++ b/lib/gitlab/app_text_logger.rb @@ -7,7 +7,7 @@ module Gitlab end def format_message(severity, timestamp, progname, msg) - "#{timestamp.to_s(:long)}: #{msg}\n" + "#{timestamp.utc.iso8601(3)}: #{msg}\n" end end end diff --git a/lib/gitlab/asciidoc/include_processor.rb b/lib/gitlab/asciidoc/include_processor.rb index c6fbf540e9c..6e0b7ce60ba 100644 --- a/lib/gitlab/asciidoc/include_processor.rb +++ b/lib/gitlab/asciidoc/include_processor.rb @@ -13,7 +13,7 @@ module Gitlab super(logger: Gitlab::AppLogger) @context = context - @repository = context[:project].try(:repository) + @repository = context[:repository] || context[:project].try(:repository) # Note: Asciidoctor calls #freeze on extensions, so we can't set new # instance variables after initialization. @@ -111,7 +111,7 @@ module Gitlab end def ref - context[:ref] || context[:project].default_branch + context[:ref] || repository&.root_ref end def requested_path diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb index 826b35d685c..22803c5cd71 100644 --- a/lib/gitlab/github_import/client.rb +++ b/lib/gitlab/github_import/client.rb @@ -189,7 +189,7 @@ module Gitlab end def default_api_endpoint - OmniAuth::Strategies::GitHub.default_options[:client_options][:site] + OmniAuth::Strategies::GitHub.default_options[:client_options][:site] || ::Octokit::Default.api_endpoint end def verify_ssl diff --git a/lib/gitlab/import/merge_request_helpers.rb b/lib/gitlab/import/merge_request_helpers.rb index 4bc39868389..c5694d95aa1 100644 --- a/lib/gitlab/import/merge_request_helpers.rb +++ b/lib/gitlab/import/merge_request_helpers.rb @@ -60,6 +60,7 @@ module Gitlab diff.importing = true diff.save diff.save_git_content + diff.set_as_latest_diff end end end diff --git a/lib/gitlab/legacy_github_import/client.rb b/lib/gitlab/legacy_github_import/client.rb index b23efd64dee..34634d20a16 100644 --- a/lib/gitlab/legacy_github_import/client.rb +++ b/lib/gitlab/legacy_github_import/client.rb @@ -80,7 +80,7 @@ module Gitlab if host.present? && api_version.present? "#{host}/api/#{api_version}" else - github_options[:site] + github_options[:site] || ::Octokit::Default.api_endpoint end end diff --git a/lib/sentry/api_urls.rb b/lib/sentry/api_urls.rb new file mode 100644 index 00000000000..388d0531da1 --- /dev/null +++ b/lib/sentry/api_urls.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Sentry + class ApiUrls + def initialize(url_base) + @uri = URI(url_base).freeze + end + + def issues_url + with_path(File.join(@uri.path, '/issues/')) + end + + def issue_url(issue_id) + with_path("/api/0/issues/#{escape(issue_id)}/") + end + + def projects_url + with_path('/api/0/projects/') + end + + def issue_latest_event_url(issue_id) + with_path("/api/0/issues/#{escape(issue_id)}/events/latest/") + end + + private + + def with_path(new_path) + new_uri = @uri.dup + # Sentry API returns 404 if there are extra slashes in the URL + new_uri.path = new_path.squeeze('/') + + new_uri + end + + def escape(param) + CGI.escape(param.to_s) + end + end +end diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index 29b00a6f8b2..20c919a97ff 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -19,6 +19,10 @@ module Sentry private + def api_urls + @api_urls ||= Sentry::ApiUrls.new(@url) + end + def handle_mapping_exceptions(&block) yield rescue KeyError => e diff --git a/lib/sentry/client/event.rb b/lib/sentry/client/event.rb index 8bcada5a9ce..01dfaa25969 100644 --- a/lib/sentry/client/event.rb +++ b/lib/sentry/client/event.rb @@ -4,20 +4,13 @@ module Sentry class Client module Event def issue_latest_event(issue_id:) - latest_event = http_get(issue_latest_event_api_url(issue_id))[:body] + latest_event = http_get(api_urls.issue_latest_event_url(issue_id))[:body] map_to_event(latest_event) end private - def issue_latest_event_api_url(issue_id) - latest_event_url = URI(url) - latest_event_url.path = "/api/0/issues/#{issue_id}/events/latest/" - - latest_event_url - end - def map_to_event(event) stack_trace = parse_stack_trace(event) diff --git a/lib/sentry/client/issue.rb b/lib/sentry/client/issue.rb index b3b3776624b..1c5d88e8862 100644 --- a/lib/sentry/client/issue.rb +++ b/lib/sentry/client/issue.rb @@ -35,14 +35,14 @@ module Sentry end def update_issue(issue_id:, params:) - http_put(issue_api_url(issue_id), params)[:body] + http_put(api_urls.issue_url(issue_id), params)[:body] end private def get_issues(**keyword_args) response = http_get( - issues_api_url, + api_urls.issues_url, query: list_issue_sentry_query(keyword_args) ) @@ -72,21 +72,7 @@ module Sentry end def get_issue(issue_id:) - http_get(issue_api_url(issue_id))[:body] - end - - def issues_api_url - issues_url = URI("#{url}/issues/") - issues_url.path.squeeze!('/') - - issues_url - end - - def issue_api_url(issue_id) - issue_url = URI(url) - issue_url.path = "/api/0/issues/#{CGI.escape(issue_id.to_s)}/" - - issue_url + http_get(api_urls.issue_url(issue_id))[:body] end def parse_gitlab_issue(plugin_issues) diff --git a/lib/sentry/client/projects.rb b/lib/sentry/client/projects.rb index 68f8fe0f9c9..e686d4ff715 100644 --- a/lib/sentry/client/projects.rb +++ b/lib/sentry/client/projects.rb @@ -14,14 +14,7 @@ module Sentry private def get_projects - http_get(projects_api_url)[:body] - end - - def projects_api_url - projects_url = URI(url) - projects_url.path = '/api/0/projects/' - - projects_url + http_get(api_urls.projects_url)[:body] end def map_to_projects(projects) |