diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 03:09:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 03:09:34 +0300 |
commit | 3cd08f4bf96cda3e9d3abf233095107832b17c20 (patch) | |
tree | dc09a618783a79d70f2a404374d4b850ccf9cc84 /lib/gitlab | |
parent | dd4bee69b7d55620f7dc9db8c36b478bd4959755 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/background_migration/user_mentions/models/commit.rb | 35 | ||||
-rw-r--r-- | lib/gitlab/background_migration/user_mentions/models/commit_user_mention.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/background_migration/user_mentions/models/note.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/ci/templates/Verify/Accessibility.gitlab-ci.yml | 16 | ||||
-rw-r--r-- | lib/gitlab/elasticsearch/logs.rb | 47 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/remote_service.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/jira/http_client.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/path_regex.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/setup_helper.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/x509/commit.rb | 6 |
12 files changed, 137 insertions, 46 deletions
diff --git a/lib/gitlab/background_migration/user_mentions/models/commit.rb b/lib/gitlab/background_migration/user_mentions/models/commit.rb new file mode 100644 index 00000000000..279e93dbf0d --- /dev/null +++ b/lib/gitlab/background_migration/user_mentions/models/commit.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + module UserMentions + module Models + class Commit + include Concerns::IsolatedMentionable + include Concerns::MentionableMigrationMethods + + def self.user_mention_model + Gitlab::BackgroundMigration::UserMentions::Models::CommitUserMention + end + + def user_mention_model + self.class.user_mention_model + end + + def user_mention_resource_id + id + end + + def user_mention_note_id + 'NULL' + end + + def self.no_quote_columns + [:note_id] + end + end + end + end + end +end diff --git a/lib/gitlab/background_migration/user_mentions/models/commit_user_mention.rb b/lib/gitlab/background_migration/user_mentions/models/commit_user_mention.rb new file mode 100644 index 00000000000..bdb4d6c7d48 --- /dev/null +++ b/lib/gitlab/background_migration/user_mentions/models/commit_user_mention.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + module UserMentions + module Models + class CommitUserMention < ActiveRecord::Base + self.table_name = 'commit_user_mentions' + + def self.resource_foreign_key + :commit_id + end + end + end + end + end +end diff --git a/lib/gitlab/background_migration/user_mentions/models/note.rb b/lib/gitlab/background_migration/user_mentions/models/note.rb index fb61de638a8..7a1a0223bc7 100644 --- a/lib/gitlab/background_migration/user_mentions/models/note.rb +++ b/lib/gitlab/background_migration/user_mentions/models/note.rb @@ -20,7 +20,7 @@ module Gitlab belongs_to :project def for_personal_snippet? - noteable.class.name == 'PersonalSnippet' + noteable && noteable.class.name == 'PersonalSnippet' end def for_project_noteable? @@ -32,7 +32,7 @@ module Gitlab end def for_epic? - noteable.class.name == 'Epic' + noteable && noteable_type == 'Epic' end def user_mention_resource_id @@ -43,6 +43,14 @@ module Gitlab id end + def noteable + super unless for_commit? + end + + def for_commit? + noteable_type == "Commit" + end + private def mentionable_params @@ -52,6 +60,8 @@ module Gitlab end def banzai_context_params + return {} unless noteable + { group: noteable.group, label_url_method: :group_epics_url } end end diff --git a/lib/gitlab/ci/templates/Verify/Accessibility.gitlab-ci.yml b/lib/gitlab/ci/templates/Verify/Accessibility.gitlab-ci.yml index a295fdcef7c..5d9d3c74def 100644 --- a/lib/gitlab/ci/templates/Verify/Accessibility.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Verify/Accessibility.gitlab-ci.yml @@ -8,20 +8,12 @@ stages: a11y: stage: accessibility - image: node - script: - - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ - - echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \ - - apt-get update && \ - - apt-get install -y google-chrome-stable && \ - - rm -rf /var/lib/apt/lists/* - - npm install pa11y@5.3.0 pa11y-reporter-html@1.0.0 - - 'echo { \"chromeLaunchConfig\": { \"args\": [\"--no-sandbox\"] }, \"includeWarnings\": true, \"reporter\": \"html\" } > pa11y.json' - - './node_modules/.bin/pa11y $a11y_urls > accessibility.html' + image: registry.gitlab.com/gitlab-org/ci-cd/accessibility:5.3.0-gitlab.2 + script: /gitlab-accessibility.sh $a11y_urls allow_failure: true artifacts: when: always - expose_as: 'accessibility' - paths: ['accessibility.html'] + expose_as: 'Accessibility Reports' + paths: ['reports/'] rules: - if: $a11y_urls diff --git a/lib/gitlab/elasticsearch/logs.rb b/lib/gitlab/elasticsearch/logs.rb index eca8b71dd7d..f976f6ce305 100644 --- a/lib/gitlab/elasticsearch/logs.rb +++ b/lib/gitlab/elasticsearch/logs.rb @@ -3,6 +3,8 @@ module Gitlab module Elasticsearch class Logs + InvalidCursor = Class.new(RuntimeError) + # How many log lines to fetch in a query LOGS_LIMIT = 500 @@ -10,7 +12,7 @@ module Gitlab @client = client end - def pod_logs(namespace, pod_name, container_name = nil, search = nil, start_time = nil, end_time = nil) + def pod_logs(namespace, pod_name, container_name: nil, search: nil, start_time: nil, end_time: nil, cursor: nil) query = { bool: { must: [] } }.tap do |q| filter_pod_name(q, pod_name) filter_namespace(q, namespace) @@ -19,7 +21,7 @@ module Gitlab filter_times(q, start_time, end_time) end - body = build_body(query) + body = build_body(query, cursor) response = @client.search body: body format_response(response) @@ -27,8 +29,8 @@ module Gitlab private - def build_body(query) - { + def build_body(query, cursor = nil) + body = { query: query, # reverse order so we can query N-most recent records sort: [ @@ -40,6 +42,12 @@ module Gitlab # fixed limit for now, we should support paginated queries size: ::Gitlab::Elasticsearch::Logs::LOGS_LIMIT } + + unless cursor.nil? + body[:search_after] = decode_cursor(cursor) + end + + body end def filter_pod_name(query, pod_name) @@ -100,7 +108,9 @@ module Gitlab end def format_response(response) - result = response.fetch("hits", {}).fetch("hits", []).map do |hit| + results = response.fetch("hits", {}).fetch("hits", []) + last_result = results.last + results = results.map do |hit| { timestamp: hit["_source"]["@timestamp"], message: hit["_source"]["message"] @@ -108,7 +118,32 @@ module Gitlab end # we queried for the N-most recent records but we want them ordered oldest to newest - result.reverse + { + logs: results.reverse, + cursor: last_result.nil? ? nil : encode_cursor(last_result["sort"]) + } + end + + # we want to hide the implementation details of the search_after parameter from the frontend + # behind a single easily transmitted value + def encode_cursor(obj) + obj.join(',') + end + + def decode_cursor(obj) + cursor = obj.split(',').map(&:to_i) + + unless valid_cursor(cursor) + raise InvalidCursor, "invalid cursor format" + end + + cursor + end + + def valid_cursor(cursor) + cursor.instance_of?(Array) && + cursor.length == 2 && + cursor.map {|i| i.instance_of?(Integer)}.reduce(:&) end end end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 29324381cb5..fd31039491a 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -152,6 +152,12 @@ module Gitlab end end + def replicate(source_repository) + wrapped_gitaly_errors do + gitaly_repository_client.replicate(source_repository) + end + end + def expire_has_local_branches_cache clear_memoization(:has_local_branches) end @@ -767,12 +773,6 @@ module Gitlab !has_visible_content? end - def fetch_repository_as_mirror(repository) - wrapped_gitaly_errors do - gitaly_remote_client.fetch_internal_remote(repository) - end - end - # Fetch remote for repository # # remote - remote name diff --git a/lib/gitlab/gitaly_client/remote_service.rb b/lib/gitlab/gitaly_client/remote_service.rb index 0e95b0ef469..2405f3be197 100644 --- a/lib/gitlab/gitaly_client/remote_service.rb +++ b/lib/gitlab/gitaly_client/remote_service.rb @@ -41,20 +41,6 @@ module Gitlab GitalyClient.call(@storage, :remote_service, :remove_remote, request, timeout: GitalyClient.long_timeout).result end - def fetch_internal_remote(repository) - request = Gitaly::FetchInternalRemoteRequest.new( - repository: @gitaly_repo, - remote_repository: repository.gitaly_repository - ) - - response = GitalyClient.call(@storage, :remote_service, - :fetch_internal_remote, request, - timeout: GitalyClient.long_timeout, - remote_storage: repository.storage) - - response.result - end - def find_remote_root_ref(remote_name) request = Gitaly::FindRemoteRootRefRequest.new( repository: @gitaly_repo, diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 597ae4651ea..f74c9ea4192 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -359,6 +359,22 @@ module Gitlab GitalyClient.call(@storage, :repository_service, :remove_repository, request, timeout: GitalyClient.long_timeout) end + def replicate(source_repository) + request = Gitaly::ReplicateRepositoryRequest.new( + repository: @gitaly_repo, + source: source_repository.gitaly_repository + ) + + GitalyClient.call( + @storage, + :repository_service, + :replicate_repository, + request, + remote_storage: source_repository.storage, + timeout: GitalyClient.long_timeout + ) + end + private def search_results_from_response(gitaly_response, options = {}) diff --git a/lib/gitlab/jira/http_client.rb b/lib/gitlab/jira/http_client.rb index 2479b9089c2..b973244a531 100644 --- a/lib/gitlab/jira/http_client.rb +++ b/lib/gitlab/jira/http_client.rb @@ -15,7 +15,7 @@ module Gitlab unless result.response.is_a?(Net::HTTPSuccess) Gitlab::ErrorTracking.track_and_raise_exception( JIRA::HTTPError.new(result.response), - response_body: result.body + response: result.body ) end diff --git a/lib/gitlab/path_regex.rb b/lib/gitlab/path_regex.rb index db094bfe973..5fa0fbf874c 100644 --- a/lib/gitlab/path_regex.rb +++ b/lib/gitlab/path_regex.rb @@ -42,7 +42,6 @@ module Gitlab invites jwt login - notification_settings oauth profile projects diff --git a/lib/gitlab/setup_helper.rb b/lib/gitlab/setup_helper.rb index c449c6879bc..99a7e617884 100644 --- a/lib/gitlab/setup_helper.rb +++ b/lib/gitlab/setup_helper.rb @@ -33,8 +33,6 @@ module Gitlab if Rails.env.test? storage_path = Rails.root.join('tmp', 'tests', 'second_storage').to_s - - FileUtils.mkdir(storage_path) unless File.exist?(storage_path) storages << { name: 'test_second_storage', path: storage_path } end diff --git a/lib/gitlab/x509/commit.rb b/lib/gitlab/x509/commit.rb index b1d15047981..4b35c0ef7d2 100644 --- a/lib/gitlab/x509/commit.rb +++ b/lib/gitlab/x509/commit.rb @@ -184,11 +184,13 @@ module Gitlab commit_sha: @commit.sha, project: @commit.project, x509_certificate_id: certificate.id, - verification_status: verification_status + verification_status: verification_status(certificate) } end - def verification_status + def verification_status(certificate) + return :unverified if certificate.revoked? + if verified_signature && certificate_email == @commit.committer_email :verified else |