diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-09 18:10:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-09 18:10:12 +0300 |
commit | e91cb68359c900aa51ffdb1863502168742e94f0 (patch) | |
tree | b7dd1749da6e2a11899905b4eae258236cd4f6a6 /lib | |
parent | 1361891b0a87187364d1586395df176a8984e914 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/boards.rb | 2 | ||||
-rw-r--r-- | lib/api/boards_responses.rb | 16 | ||||
-rw-r--r-- | lib/api/entities/merge_request_basic.rb | 1 | ||||
-rw-r--r-- | lib/api/group_boards.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/background_migration/populate_dismissed_state_for_vulnerabilities.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/background_migration/populate_missing_vulnerability_dismissal_information.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/i18n/html_todo.yml | 57 | ||||
-rw-r--r-- | lib/gitlab/i18n/po_linter.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/i18n/translation_entry.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/import_export/project/import_export.yml | 1 | ||||
-rw-r--r-- | lib/gitlab/performance_bar/logger.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/performance_bar/stats.rb | 60 | ||||
-rw-r--r-- | lib/tasks/gettext.rake | 4 |
14 files changed, 135 insertions, 102 deletions
diff --git a/lib/api/boards.rb b/lib/api/boards.rb index f4b23c507f4..e2d30dd7c2b 100644 --- a/lib/api/boards.rb +++ b/lib/api/boards.rb @@ -117,8 +117,6 @@ module API use :list_creation_params end post '/lists' do - authorize_list_type_resource! - authorize!(:admin_list, user_project) create_list diff --git a/lib/api/boards_responses.rb b/lib/api/boards_responses.rb index 2ae82f78e01..b83fa32ff22 100644 --- a/lib/api/boards_responses.rb +++ b/lib/api/boards_responses.rb @@ -47,12 +47,12 @@ module API create_list_service = ::Boards::Lists::CreateService.new(board_parent, current_user, create_list_params) - list = create_list_service.execute(board) + response = create_list_service.execute(board) - if list.valid? - present list, with: Entities::List + if response.success? + present response.payload[:list], with: Entities::List else - render_validation_error!(list) + render_api_error!({ error: response.errors.first }, 400) end end @@ -80,14 +80,6 @@ module API end end - # rubocop: disable CodeReuse/ActiveRecord - def authorize_list_type_resource! - unless available_labels_for(board_parent).exists?(params[:label_id]) - render_api_error!({ error: 'Label not found!' }, 400) - end - end - # rubocop: enable CodeReuse/ActiveRecord - params :list_creation_params do requires :label_id, type: Integer, desc: 'The ID of an existing label' end diff --git a/lib/api/entities/merge_request_basic.rb b/lib/api/entities/merge_request_basic.rb index 69523e3637b..7f1b5b87725 100644 --- a/lib/api/entities/merge_request_basic.rb +++ b/lib/api/entities/merge_request_basic.rb @@ -27,6 +27,7 @@ module API expose(:downvotes) { |merge_request, options| issuable_metadata.downvotes } expose :author, :assignees, :assignee, using: Entities::UserBasic + expose :reviewers, if: -> (merge_request, _) { merge_request.allows_reviewers? }, using: Entities::UserBasic expose :source_project_id, :target_project_id expose :labels do |merge_request, options| if options[:with_labels_details] diff --git a/lib/api/group_boards.rb b/lib/api/group_boards.rb index ac5a1a2ce94..2bfd98a5b69 100644 --- a/lib/api/group_boards.rb +++ b/lib/api/group_boards.rb @@ -83,8 +83,6 @@ module API use :list_creation_params end post '/lists' do - authorize_list_type_resource! - authorize!(:admin_list, user_group) create_list diff --git a/lib/gitlab/background_migration/populate_dismissed_state_for_vulnerabilities.rb b/lib/gitlab/background_migration/populate_dismissed_state_for_vulnerabilities.rb new file mode 100644 index 00000000000..68c91650d93 --- /dev/null +++ b/lib/gitlab/background_migration/populate_dismissed_state_for_vulnerabilities.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # This class updates vulnerabilities entities with state dismissed + class PopulateDismissedStateForVulnerabilities + class Vulnerability < ActiveRecord::Base # rubocop:disable Style/Documentation + self.table_name = 'vulnerabilities' + end + + def perform(*vulnerability_ids) + Vulnerability.where(id: vulnerability_ids).update_all(state: 2) + PopulateMissingVulnerabilityDismissalInformation.new.perform(*vulnerability_ids) + end + end + end +end diff --git a/lib/gitlab/background_migration/populate_missing_vulnerability_dismissal_information.rb b/lib/gitlab/background_migration/populate_missing_vulnerability_dismissal_information.rb index bc0a181a06c..04342fdabd4 100644 --- a/lib/gitlab/background_migration/populate_missing_vulnerability_dismissal_information.rb +++ b/lib/gitlab/background_migration/populate_missing_vulnerability_dismissal_information.rb @@ -26,13 +26,16 @@ module Gitlab class Finding < ActiveRecord::Base # rubocop:disable Style/Documentation include ShaAttribute + include ::Gitlab::Utils::StrongMemoize self.table_name = 'vulnerability_occurrences' sha_attribute :project_fingerprint def dismissal_feedback - Feedback.dismissal.where(category: report_type, project_fingerprint: project_fingerprint, project_id: project_id).first + strong_memoize(:dismissal_feedback) do + Feedback.dismissal.where(category: report_type, project_fingerprint: project_fingerprint, project_id: project_id).first + end end end diff --git a/lib/gitlab/i18n/html_todo.yml b/lib/gitlab/i18n/html_todo.yml deleted file mode 100644 index 610381b9b48..00000000000 --- a/lib/gitlab/i18n/html_todo.yml +++ /dev/null @@ -1,57 +0,0 @@ -# -# PLEASE DO NOT ADD NEW STRINGS TO THIS FILE. -# -# See https://docs.gitlab.com/ee/development/i18n/externalization.html#html -# for information on how to handle HTML in translations. - -# -# This file contains strings that need to be fixed to use the -# updated HTML guidelines. Any strings in this file will no -# longer be able to be translated until they have been updated. -# -# This file (and the functionality around it) will be removed -# once https://gitlab.com/gitlab-org/gitlab/-/issues/217933 is complete. -# -# See https://gitlab.com/gitlab-org/gitlab/-/issues/19485 for more details -# why this change has been made. -# - -# -# Strings below are fixed in the source code but the translations are still present in CrowdIn so the -# locale files will fail the linter. They can be deleted after next CrowdIn sync, likely in: -# https://gitlab.com/gitlab-org/gitlab/-/issues/226008 -# - -"This commit was signed with an <strong>unverified</strong> signature.": - plural_id: - translations: - - "このコミットは<strong>検証されていない</strong> 署名でサインされています。" - - "Этот коммит был подписан <strong>непроверенной</strong> подписью." - - "此提交使用 <strong>未经验证的</strong> 签名进行签名。" - - "Цей коміт підписано <strong>неперевіреним</strong> підписом." - - "Esta commit fue firmado con una firma <strong>no verificada</strong>." -"This commit was signed with a <strong>verified</strong> signature and the committer email is verified to belong to the same user.": - plural_id: - translations: - - "このコミットは <strong>検証済み</strong> の署名でサインされており、このコミッターのメールは同じユーザーのものであることが検証されています。" - - "Это коммит был подписан <strong>верифицированной</strong> подписью и коммитер подтвердил, что адрес почты принадлежит ему." - - "此提交使用 <strong>已验证</strong> 的签名进行签名,并且已验证提交者的电子邮件属于同一用户。" - - "Цей коміт підписано <strong>перевіреним</strong> підписом і адреса електронної пошти комітера гарантовано належить тому самому користувачу." - - "Este commit fue firmado con una firma verificada, y <strong>se ha verificado</strong> que la dirección de correo electrónico del committer y la firma pertenecen al mismo usuario." -"Branch <strong>%{branch_name}</strong> was created. To set up auto deploy, choose a GitLab CI Yaml template and commit your changes. %{link_to_autodeploy_doc}": - plural_id: - translations: - - "分支 <strong>%{branch_name}</strong> 已創建。如需設置自動部署, 請選擇合適的 GitLab CI Yaml 模板併提交更改。%{link_to_autodeploy_doc}" - - "O branch <strong>%{branch_name}</strong> foi criado. Para configurar o deploy automático, selecione um modelo de Yaml do GitLab CI e commit suas mudanças. %{link_to_autodeploy_doc}" - - "<strong>%{branch_name}</strong> ブランチが作成されました。自動デプロイを設定するには、GitLab CI Yaml テンプレートを選択して、変更をコミットしてください。 %{link_to_autodeploy_doc}" - - "La branch <strong>%{branch_name}</strong> è stata creata. Per impostare un rilascio automatico scegli un template CI di Gitlab e committa le tue modifiche %{link_to_autodeploy_doc}" - - "O ramo <strong>%{branch_name}</strong> foi criado. Para configurar a implantação automática, seleciona um modelo de Yaml do GitLab CI e envia as tuas alterações. %{link_to_autodeploy_doc}" - - "Ветка <strong>%{branch_name}</strong> создана. Для настройки автоматического развертывания выберите YAML-шаблон для GitLab CI и зафиксируйте свои изменения. %{link_to_autodeploy_doc}" - - "已创建分支 <strong>%{branch_name}</strong> 。如需设置自动部署, 请选择合适的 GitLab CI Yaml 模板并提交更改。%{link_to_autodeploy_doc}" - - "Гілка <strong>%{branch_name}</strong> створена. Для настройки автоматичного розгортання виберіть GitLab CI Yaml-шаблон і закомітьте зміни. %{link_to_autodeploy_doc}" - - "Клонът <strong>%{branch_name}</strong> беше създаден. За да настроите автоматичното внедряване, изберете Yaml шаблон за GitLab CI и подайте промените си. %{link_to_autodeploy_doc}" - - "Branch <strong>%{branch_name}</strong> wurde erstellt. Um die automatische Bereitstellung einzurichten, wähle eine GitLab CI Yaml Vorlage und committe deine Änderungen. %{link_to_autodeploy_doc}" - - "<strong>%{branch_name}</strong> 브랜치가 생성되었습니다. 자동 배포를 설정하려면 GitLab CI Yaml 템플릿을 선택하고 변경 사항을 적용하십시오. %{link_to_autodeploy_doc}" - - "La branĉo <strong>%{branch_name}</strong> estis kreita. Por agordi aŭtomatan disponigadon, bonvolu elekti Yaml-ŝablonon por GitLab CI kaj enmeti viajn ŝanĝojn. %{link_to_autodeploy_doc}" - - "La branche <strong>%{branch_name}</strong> a été créée. Pour mettre en place le déploiement automatisé, sélectionnez un modèle de fichier YAML pour l’intégration continue (CI) de GitLab, et validez les modifications. %{link_to_autodeploy_doc}" - - "La rama <strong>%{branch_name}</strong> fue creada. Para configurar el auto despliegue, escoge una plantilla Yaml para GitLab CI y envía tus cambios. %{link_to_autodeploy_doc}" diff --git a/lib/gitlab/i18n/po_linter.rb b/lib/gitlab/i18n/po_linter.rb index 33054a5b9bf..3bb34ab2811 100644 --- a/lib/gitlab/i18n/po_linter.rb +++ b/lib/gitlab/i18n/po_linter.rb @@ -5,14 +5,13 @@ module Gitlab class PoLinter include Gitlab::Utils::StrongMemoize - attr_reader :po_path, :translation_entries, :metadata_entry, :locale, :html_todolist + attr_reader :po_path, :translation_entries, :metadata_entry, :locale VARIABLE_REGEX = /%{\w*}|%[a-z]/.freeze - def initialize(po_path:, html_todolist:, locale: I18n.locale.to_s) + def initialize(po_path:, locale: I18n.locale.to_s) @po_path = po_path @locale = locale - @html_todolist = html_todolist end def errors @@ -43,8 +42,7 @@ module Gitlab @translation_entries = entries.map do |entry_data| Gitlab::I18n::TranslationEntry.new( entry_data: entry_data, - nplurals: metadata_entry.expected_forms, - html_allowed: html_todolist.fetch(entry_data[:msgid], false) + nplurals: metadata_entry.expected_forms ) end @@ -97,15 +95,15 @@ module Gitlab common_message = 'contains < or >. Use variables to include HTML in the string, or the < and > codes ' \ 'for the symbols. For more info see: https://docs.gitlab.com/ee/development/i18n/externalization.html#html' - if entry.msgid_contains_potential_html? && !entry.msgid_html_allowed? + if entry.msgid_contains_potential_html? errors << common_message end - if entry.plural_id_contains_potential_html? && !entry.plural_id_html_allowed? + if entry.plural_id_contains_potential_html? errors << 'plural id ' + common_message end - if entry.translations_contain_potential_html? && !entry.translations_html_allowed? + if entry.translations_contain_potential_html? errors << 'translation ' + common_message end end diff --git a/lib/gitlab/i18n/translation_entry.rb b/lib/gitlab/i18n/translation_entry.rb index 25a45332d27..f3cca97950d 100644 --- a/lib/gitlab/i18n/translation_entry.rb +++ b/lib/gitlab/i18n/translation_entry.rb @@ -6,12 +6,11 @@ module Gitlab PERCENT_REGEX = /(?:^|[^%])%(?!{\w*}|[a-z%])/.freeze ANGLE_BRACKET_REGEX = /[<>]/.freeze - attr_reader :nplurals, :entry_data, :html_allowed + attr_reader :nplurals, :entry_data - def initialize(entry_data:, nplurals:, html_allowed:) + def initialize(entry_data:, nplurals:) @entry_data = entry_data @nplurals = nplurals - @html_allowed = html_allowed end def msgid @@ -97,20 +96,6 @@ module Gitlab all_translations.any? { |translation| contains_angle_brackets?(translation) } end - def msgid_html_allowed? - html_allowed.present? - end - - def plural_id_html_allowed? - html_allowed.present? && html_allowed['plural_id'] == plural_id - end - - def translations_html_allowed? - msgid_html_allowed? && html_allowed['translations'].present? && all_translations.all? do |translation| - html_allowed['translations'].include?(translation) - end - end - private def contains_angle_brackets?(string) diff --git a/lib/gitlab/import_export/project/import_export.yml b/lib/gitlab/import_export/project/import_export.yml index 04ca3c4ddb5..778b42f4358 100644 --- a/lib/gitlab/import_export/project/import_export.yml +++ b/lib/gitlab/import_export/project/import_export.yml @@ -347,6 +347,7 @@ excluded_attributes: - :board_id - :label_id - :milestone_id + - :iteration_id epic: - :start_date_sourcing_milestone_id - :due_date_sourcing_milestone_id diff --git a/lib/gitlab/performance_bar/logger.rb b/lib/gitlab/performance_bar/logger.rb new file mode 100644 index 00000000000..a8e2f7d2d4e --- /dev/null +++ b/lib/gitlab/performance_bar/logger.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Gitlab + module PerformanceBar + class Logger < ::Gitlab::JsonLogger + def self.file_name_noext + 'performance_bar_json' + end + end + end +end diff --git a/lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb b/lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb index 805283b0f93..bf8d4b202b6 100644 --- a/lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb +++ b/lib/gitlab/performance_bar/redis_adapter_when_peek_enabled.rb @@ -5,7 +5,33 @@ module Gitlab module PerformanceBar module RedisAdapterWhenPeekEnabled def save(request_id) - super if ::Gitlab::PerformanceBar.enabled_for_request? + return unless ::Gitlab::PerformanceBar.enabled_for_request? + return if request_id.blank? + + super + + enqueue_stats_job(request_id) + end + + # schedules a job which parses peek profile data and adds them + # to a structured log + def enqueue_stats_job(request_id) + return unless gather_stats? + + @client.sadd(GitlabPerformanceBarStatsWorker::STATS_KEY, request_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables + + return unless uuid = Gitlab::ExclusiveLease.new( + GitlabPerformanceBarStatsWorker::LEASE_KEY, + timeout: GitlabPerformanceBarStatsWorker::LEASE_TIMEOUT + ).try_obtain + + GitlabPerformanceBarStatsWorker.perform_in(GitlabPerformanceBarStatsWorker::WORKER_DELAY, uuid) + end + + def gather_stats? + return unless Feature.enabled?(:performance_bar_stats) + + Gitlab.com? || !Rails.env.production? end end end diff --git a/lib/gitlab/performance_bar/stats.rb b/lib/gitlab/performance_bar/stats.rb new file mode 100644 index 00000000000..d1504d88315 --- /dev/null +++ b/lib/gitlab/performance_bar/stats.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module Gitlab + module PerformanceBar + # This class fetches Peek stats stored in redis and logs them in a + # structured log (so these can be then analyzed in Kibana) + class Stats + def initialize(redis) + @redis = redis + end + + def process(id) + data = request(id) + return unless data + + log_sql_queries(id, data) + rescue => err + logger.error(message: "failed to process request id #{id}: #{err.message}") + end + + private + + def request(id) + # Peek gem stores request data under peek:requests:request_id key + json_data = @redis.get("peek:requests:#{id}") + Gitlab::Json.parse(json_data) + end + + def log_sql_queries(id, data) + return [] unless queries = data.dig('data', 'active-record', 'details') + + queries.each do |query| + next unless location = parse_backtrace(query['backtrace']) + + log_info = location.merge( + type: :sql, + request_id: id, + duration_ms: query['duration'].to_f + ) + + logger.info(log_info) + end + end + + def parse_backtrace(backtrace) + return unless match = /(?<filename>.*):(?<filenum>\d+):in `(?<method>.*)'/.match(backtrace.first) + + { + filename: match[:filename], + filenum: match[:filenum].to_i, + method: match[:method] + } + end + + def logger + @logger ||= Gitlab::PerformanceBar::Logger.build + end + end + end +end diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index 0834d41521b..e03c78d5a40 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -65,10 +65,10 @@ namespace :gettext do linters = files.map do |file| locale = File.basename(File.dirname(file)) - Gitlab::I18n::PoLinter.new(po_path: file, html_todolist: html_todolist, locale: locale) + Gitlab::I18n::PoLinter.new(po_path: file, locale: locale) end - linters.unshift(Gitlab::I18n::PoLinter.new(po_path: pot_file_path, html_todolist: html_todolist)) + linters.unshift(Gitlab::I18n::PoLinter.new(po_path: pot_file_path)) failed_linters = linters.select { |linter| linter.errors.any? } |