diff options
Diffstat (limited to 'lib')
26 files changed, 216 insertions, 113 deletions
diff --git a/lib/api/container_registry.rb b/lib/api/container_registry.rb index e4493910196..7d9b5e1a598 100644 --- a/lib/api/container_registry.rb +++ b/lib/api/container_registry.rb @@ -115,12 +115,8 @@ module API authorize! :read_container_image, repository end - def authorize_update_container_image! - authorize! :update_container_image, repository - end - def authorize_destroy_container_image! - authorize! :admin_container_image, repository + authorize! :destroy_container_image, repository end def authorize_admin_container_image! diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb b/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb index d7f47c0e7e6..942e4e55323 100644 --- a/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb +++ b/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb @@ -13,16 +13,6 @@ module Gitlab regexp = @right.evaluate(variables) regexp.scan(text.to_s).any? - - if ci_variables_complex_expressions? - # return offset of first match, or nil if no matches - if match = regexp.scan(text.to_s).first - text.to_s.index(match) - end - else - # return true or false - regexp.scan(text.to_s).any? - end end def self.build(_value, behind, ahead) @@ -32,12 +22,6 @@ module Gitlab def self.precedence 10 # See: https://ruby-doc.org/core-2.5.0/doc/syntax/precedence_rdoc.html end - - private - - def ci_variables_complex_expressions? - Feature.enabled?(:ci_variables_complex_expressions) - end end end end diff --git a/lib/gitlab/cycle_analytics/builds_event_helper.rb b/lib/gitlab/cycle_analytics/builds_event_helper.rb new file mode 100644 index 00000000000..0d6f32fdc6f --- /dev/null +++ b/lib/gitlab/cycle_analytics/builds_event_helper.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module BuildsEventHelper + def initialize(*args) + @projections = [build_table[:id]] + @order = build_table[:created_at] + + super(*args) + end + + def fetch + Updater.update!(event_result, from: 'id', to: 'build', klass: ::Ci::Build) + + super + end + + def events_query + base_query.join(build_table).on(mr_metrics_table[:pipeline_id].eq(build_table[:commit_id])) + + super + end + + private + + def allowed_ids + nil + end + + def serialize(event) + AnalyticsBuildSerializer.new.represent(event['build']) + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/code_event_fetcher.rb b/lib/gitlab/cycle_analytics/code_event_fetcher.rb index 591db3c35e6..6c348f1862d 100644 --- a/lib/gitlab/cycle_analytics/code_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/code_event_fetcher.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class CodeEventFetcher < BaseEventFetcher + include CodeHelper + def initialize(*args) @projections = [mr_table[:title], mr_table[:iid], diff --git a/lib/gitlab/cycle_analytics/code_helper.rb b/lib/gitlab/cycle_analytics/code_helper.rb new file mode 100644 index 00000000000..8f28bdd2502 --- /dev/null +++ b/lib/gitlab/cycle_analytics/code_helper.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module CodeHelper + def stage_query(project_ids) + super(project_ids).where(mr_table[:created_at].gteq(issue_metrics_table[:first_mentioned_in_commit_at])) + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/code_stage.rb b/lib/gitlab/cycle_analytics/code_stage.rb index 2e5f9ef5a40..89a6430221c 100644 --- a/lib/gitlab/cycle_analytics/code_stage.rb +++ b/lib/gitlab/cycle_analytics/code_stage.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class CodeStage < BaseStage + include CodeHelper + def start_time_attrs @start_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at] end diff --git a/lib/gitlab/cycle_analytics/issue_event_fetcher.rb b/lib/gitlab/cycle_analytics/issue_event_fetcher.rb index 30c6ead8968..8a870f2e2a3 100644 --- a/lib/gitlab/cycle_analytics/issue_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/issue_event_fetcher.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class IssueEventFetcher < BaseEventFetcher + include IssueHelper + def initialize(*args) @projections = [issue_table[:title], issue_table[:iid], diff --git a/lib/gitlab/cycle_analytics/issue_helper.rb b/lib/gitlab/cycle_analytics/issue_helper.rb new file mode 100644 index 00000000000..c9266341378 --- /dev/null +++ b/lib/gitlab/cycle_analytics/issue_helper.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module IssueHelper + def stage_query(project_ids) + query = issue_table.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id])) + .project(issue_table[:project_id].as("project_id")) + .where(issue_table[:project_id].in(project_ids)) + .where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables + .where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) + + query + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/issue_stage.rb b/lib/gitlab/cycle_analytics/issue_stage.rb index 4eae2da512c..738cb3eba03 100644 --- a/lib/gitlab/cycle_analytics/issue_stage.rb +++ b/lib/gitlab/cycle_analytics/issue_stage.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class IssueStage < BaseStage + include IssueHelper + def start_time_attrs @start_time_attrs ||= issue_table[:created_at] end diff --git a/lib/gitlab/cycle_analytics/plan_event_fetcher.rb b/lib/gitlab/cycle_analytics/plan_event_fetcher.rb index aeca9d00156..d924f956dcd 100644 --- a/lib/gitlab/cycle_analytics/plan_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/plan_event_fetcher.rb @@ -3,60 +3,26 @@ module Gitlab module CycleAnalytics class PlanEventFetcher < BaseEventFetcher + include PlanHelper + def initialize(*args) - @projections = [mr_diff_table[:id], - issue_metrics_table[:first_mentioned_in_commit_at]] + @projections = [issue_table[:title], + issue_table[:iid], + issue_table[:id], + issue_table[:created_at], + issue_table[:author_id]] super(*args) end - def events_query - base_query - .join(mr_diff_table) - .on(mr_diff_table[:merge_request_id].eq(mr_table[:id])) - - super - end - private - def allowed_ids - nil - end - - def merge_request_diff_commits - @merge_request_diff_commits ||= - MergeRequestDiffCommit - .where(merge_request_diff_id: event_result.map { |event| event['id'] }) - .group_by(&:merge_request_diff_id) - end - def serialize(event) - commit = first_time_reference_commit(event) - - return unless commit - - serialize_commit(event, commit, query) - end - - def first_time_reference_commit(event) - return unless event && merge_request_diff_commits - - commits = merge_request_diff_commits[event['id'].to_i] - - return if commits.blank? - - commits.find do |commit| - next unless commit[:committed_date] && event['first_mentioned_in_commit_at'] - - commit[:committed_date].to_i == DateTime.parse(event['first_mentioned_in_commit_at'].to_s).to_i - end + AnalyticsIssueSerializer.new(project: @project).represent(event) end - def serialize_commit(event, commit, query) - commit = Commit.from_hash(commit.to_hash, @project) - - AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit) + def allowed_ids_finder_class + IssuesFinder end end end diff --git a/lib/gitlab/cycle_analytics/plan_helper.rb b/lib/gitlab/cycle_analytics/plan_helper.rb new file mode 100644 index 00000000000..30fc2ce6d40 --- /dev/null +++ b/lib/gitlab/cycle_analytics/plan_helper.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module PlanHelper + def stage_query(project_ids) + query = issue_table.join(issue_metrics_table).on(issue_table[:id].eq(issue_metrics_table[:issue_id])) + .project(issue_table[:project_id].as("project_id")) + .where(issue_table[:project_id].in(project_ids)) + .where(issue_table[:created_at].gteq(@options[:from])) # rubocop:disable Gitlab/ModuleWithInstanceVariables + .where(issue_metrics_table[:first_added_to_board_at].not_eq(nil).or(issue_metrics_table[:first_associated_with_milestone_at].not_eq(nil))) + .where(issue_metrics_table[:first_mentioned_in_commit_at].not_eq(nil)) + + query + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/plan_stage.rb b/lib/gitlab/cycle_analytics/plan_stage.rb index 513e4575be0..0b27d114f52 100644 --- a/lib/gitlab/cycle_analytics/plan_stage.rb +++ b/lib/gitlab/cycle_analytics/plan_stage.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class PlanStage < BaseStage + include PlanHelper + def start_time_attrs @start_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at], issue_metrics_table[:first_added_to_board_at]] @@ -21,7 +23,7 @@ module Gitlab end def legend - _("Related Commits") + _("Related Issues") end def description diff --git a/lib/gitlab/cycle_analytics/production_event_fetcher.rb b/lib/gitlab/cycle_analytics/production_event_fetcher.rb index 6681cb42c90..6bcbe0412a9 100644 --- a/lib/gitlab/cycle_analytics/production_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/production_event_fetcher.rb @@ -2,7 +2,28 @@ module Gitlab module CycleAnalytics - class ProductionEventFetcher < IssueEventFetcher + class ProductionEventFetcher < BaseEventFetcher + include ProductionHelper + + def initialize(*args) + @projections = [issue_table[:title], + issue_table[:iid], + issue_table[:id], + issue_table[:created_at], + issue_table[:author_id]] + + super(*args) + end + + private + + def serialize(event) + AnalyticsIssueSerializer.new(project: @project).represent(event) + end + + def allowed_ids_finder_class + IssuesFinder + end end end end diff --git a/lib/gitlab/cycle_analytics/review_event_fetcher.rb b/lib/gitlab/cycle_analytics/review_event_fetcher.rb index de100295281..b6354b5ffad 100644 --- a/lib/gitlab/cycle_analytics/review_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/review_event_fetcher.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class ReviewEventFetcher < BaseEventFetcher + include ReviewHelper + def initialize(*args) @projections = [mr_table[:title], mr_table[:iid], diff --git a/lib/gitlab/cycle_analytics/review_helper.rb b/lib/gitlab/cycle_analytics/review_helper.rb new file mode 100644 index 00000000000..c53249652b5 --- /dev/null +++ b/lib/gitlab/cycle_analytics/review_helper.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module ReviewHelper + def stage_query(project_ids) + super(project_ids).where(mr_metrics_table[:merged_at].not_eq(nil)) + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/review_stage.rb b/lib/gitlab/cycle_analytics/review_stage.rb index 294b656bc55..e9df8cd5a05 100644 --- a/lib/gitlab/cycle_analytics/review_stage.rb +++ b/lib/gitlab/cycle_analytics/review_stage.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class ReviewStage < BaseStage + include ReviewHelper + def start_time_attrs @start_time_attrs ||= mr_table[:created_at] end diff --git a/lib/gitlab/cycle_analytics/staging_event_fetcher.rb b/lib/gitlab/cycle_analytics/staging_event_fetcher.rb index 70ce82383b3..1454a1a33eb 100644 --- a/lib/gitlab/cycle_analytics/staging_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/staging_event_fetcher.rb @@ -3,34 +3,8 @@ module Gitlab module CycleAnalytics class StagingEventFetcher < BaseEventFetcher - def initialize(*args) - @projections = [build_table[:id]] - @order = build_table[:created_at] - - super(*args) - end - - def fetch - Updater.update!(event_result, from: 'id', to: 'build', klass: ::Ci::Build) - - super - end - - def events_query - base_query.join(build_table).on(mr_metrics_table[:pipeline_id].eq(build_table[:commit_id])) - - super - end - - private - - def allowed_ids - nil - end - - def serialize(event) - AnalyticsBuildSerializer.new.represent(event['build']) - end + include ProductionHelper + include BuildsEventHelper end end end diff --git a/lib/gitlab/cycle_analytics/staging_stage.rb b/lib/gitlab/cycle_analytics/staging_stage.rb index dbc2414ff66..e03627c6cd1 100644 --- a/lib/gitlab/cycle_analytics/staging_stage.rb +++ b/lib/gitlab/cycle_analytics/staging_stage.rb @@ -4,6 +4,7 @@ module Gitlab module CycleAnalytics class StagingStage < BaseStage include ProductionHelper + def start_time_attrs @start_time_attrs ||= mr_metrics_table[:merged_at] end diff --git a/lib/gitlab/cycle_analytics/test_event_fetcher.rb b/lib/gitlab/cycle_analytics/test_event_fetcher.rb index 4d5ea5b7c34..2fa44b1b364 100644 --- a/lib/gitlab/cycle_analytics/test_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/test_event_fetcher.rb @@ -2,7 +2,9 @@ module Gitlab module CycleAnalytics - class TestEventFetcher < StagingEventFetcher + class TestEventFetcher < BaseEventFetcher + include TestHelper + include BuildsEventHelper end end end diff --git a/lib/gitlab/cycle_analytics/test_helper.rb b/lib/gitlab/cycle_analytics/test_helper.rb new file mode 100644 index 00000000000..32fca7fa898 --- /dev/null +++ b/lib/gitlab/cycle_analytics/test_helper.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module TestHelper + def stage_query(project_ids) + if branch + super(project_ids).where(build_table[:ref].eq(branch)) + else + super(project_ids) + end + end + + private + + def branch + @branch ||= @options[:branch] # rubocop:disable Gitlab/ModuleWithInstanceVariables + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/test_stage.rb b/lib/gitlab/cycle_analytics/test_stage.rb index c31b664148b..4787a906c07 100644 --- a/lib/gitlab/cycle_analytics/test_stage.rb +++ b/lib/gitlab/cycle_analytics/test_stage.rb @@ -3,6 +3,8 @@ module Gitlab module CycleAnalytics class TestStage < BaseStage + include TestHelper + def start_time_attrs @start_time_attrs ||= mr_metrics_table[:latest_build_started_at] end @@ -26,14 +28,6 @@ module Gitlab def description _("Total test time for all commits/merges") end - - def stage_query(project_ids) - if @options[:branch] - super(project_ids).where(build_table[:ref].eq(@options[:branch])) - else - super(project_ids) - end - end end end end diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb index e8f98f52111..d349c378e53 100644 --- a/lib/gitlab/diff/position.rb +++ b/lib/gitlab/diff/position.rb @@ -134,6 +134,14 @@ module Gitlab @line_code ||= diff_file(repository)&.line_code_for_position(self) end + def on_image? + position_type == 'image' + end + + def on_text? + position_type == 'text' + end + private def find_diff_file(repository) diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb index 5ff415b6126..1d317c389d2 100644 --- a/lib/gitlab/gpg/commit.rb +++ b/lib/gitlab/gpg/commit.rb @@ -52,12 +52,13 @@ module Gitlab def using_keychain Gitlab::Gpg.using_tmp_keychain do - # first we need to get the keyid from the signature to query the gpg - # key belonging to the keyid. + # first we need to get the fingerprint from the signature to query the gpg + # key belonging to the fingerprint. # This way we can add the key to the temporary keychain and extract # the proper signature. - # NOTE: the invoked method is #fingerprint but it's only returning - # 16 characters (the format used by keyid) instead of 40. + # NOTE: the invoked method is #fingerprint but versions of GnuPG + # prior to 2.2.13 return 16 characters (the format used by keyid) + # instead of 40. fingerprint = verified_signature&.fingerprint break unless fingerprint @@ -128,11 +129,13 @@ module Gitlab gpg_key&.verified_user_infos&.first || gpg_key&.user_infos&.first || {} end - # rubocop: disable CodeReuse/ActiveRecord - def find_gpg_key(keyid) - GpgKey.find_by(primary_keyid: keyid) || GpgKeySubkey.find_by(keyid: keyid) + def find_gpg_key(fingerprint) + if fingerprint.length > 16 + GpgKey.find_by_fingerprint(fingerprint) || GpgKeySubkey.find_by_fingerprint(fingerprint) + else + GpgKey.find_by_primary_keyid(fingerprint) || GpgKeySubkey.find_by_keyid(fingerprint) + end end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/lib/gitlab/metrics/dashboard/project_dashboard_service.rb b/lib/gitlab/metrics/dashboard/project_dashboard_service.rb index e88658e4f9f..5a1c4ecf886 100644 --- a/lib/gitlab/metrics/dashboard/project_dashboard_service.rb +++ b/lib/gitlab/metrics/dashboard/project_dashboard_service.rb @@ -13,12 +13,23 @@ module Gitlab def all_dashboard_paths(project) file_finder(project) .list_files_for(DASHBOARD_ROOT) - .map { |filepath| { path: filepath, default: false } } + .map do |filepath| + { + path: filepath, + display_name: name_for_path(filepath), + default: false + } + end end def file_finder(project) Gitlab::Template::Finders::RepoTemplateFinder.new(project, DASHBOARD_ROOT, '.yml') end + + # Grabs the filepath after the base directory. + def name_for_path(filepath) + filepath.delete_prefix("#{DASHBOARD_ROOT}/") + end end private diff --git a/lib/gitlab/metrics/dashboard/system_dashboard_service.rb b/lib/gitlab/metrics/dashboard/system_dashboard_service.rb index 67509ed4230..82421572f4a 100644 --- a/lib/gitlab/metrics/dashboard/system_dashboard_service.rb +++ b/lib/gitlab/metrics/dashboard/system_dashboard_service.rb @@ -7,11 +7,13 @@ module Gitlab module Dashboard class SystemDashboardService < Gitlab::Metrics::Dashboard::BaseService SYSTEM_DASHBOARD_PATH = 'config/prometheus/common_metrics.yml' + SYSTEM_DASHBOARD_NAME = 'Default' class << self def all_dashboard_paths(_project) [{ path: SYSTEM_DASHBOARD_PATH, + display_name: SYSTEM_DASHBOARD_NAME, default: true }] end diff --git a/lib/gitlab/visibility_level.rb b/lib/gitlab/visibility_level.rb index 8f9d5cf1e63..e2787744f09 100644 --- a/lib/gitlab/visibility_level.rb +++ b/lib/gitlab/visibility_level.rb @@ -138,5 +138,18 @@ module Gitlab def visibility=(level) self[visibility_level_field] = Gitlab::VisibilityLevel.level_value(level) end + + def visibility_attribute_present?(attributes) + visibility_level_attributes.each do |attr| + return true if attributes[attr].present? + end + + false + end + + def visibility_level_attributes + [visibility_level_field, visibility_level_field.to_s, + :visibility, 'visibility'] + end end end |