summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb2
-rw-r--r--app/models/ci/daily_report_result.rb22
-rw-r--r--app/models/ci/pipeline.rb15
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/user.rb15
-rw-r--r--app/models/user_bot_type_enums.rb11
-rw-r--r--app/models/user_type_enums.rb6
7 files changed, 52 insertions, 21 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 74a1985ca50..517f2312a76 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -174,6 +174,8 @@ module Ci
pipeline: Ci::Pipeline::PROJECT_ROUTE_AND_NAMESPACE_ROUTE)
end
+ scope :with_coverage, -> { where.not(coverage: nil) }
+
acts_as_taggable
add_authentication_token_field :token, encrypted: :optional
diff --git a/app/models/ci/daily_report_result.rb b/app/models/ci/daily_report_result.rb
new file mode 100644
index 00000000000..3c1c5f11ed4
--- /dev/null
+++ b/app/models/ci/daily_report_result.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Ci
+ class DailyReportResult < ApplicationRecord
+ extend Gitlab::Ci::Model
+
+ belongs_to :last_pipeline, class_name: 'Ci::Pipeline', foreign_key: :last_pipeline_id
+ belongs_to :project
+
+ # TODO: Refactor this out when BuildReportResult is implemented.
+ # They both need to share the same enum values for param.
+ REPORT_PARAMS = {
+ coverage: 0
+ }.freeze
+
+ enum param_type: REPORT_PARAMS
+
+ def self.upsert_reports(data)
+ upsert_all(data, unique_by: :index_daily_report_results_unique_columns) if data.any?
+ end
+ end
+end
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 61b28a3e712..ef22b429df9 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -82,6 +82,8 @@ module Ci
has_one :pipeline_config, class_name: 'Ci::PipelineConfig', inverse_of: :pipeline
+ has_many :daily_report_results, class_name: 'Ci::DailyReportResult', foreign_key: :last_pipeline_id
+
accepts_nested_attributes_for :variables, reject_if: :persisted?
delegate :id, to: :project, prefix: true
@@ -189,7 +191,10 @@ module Ci
end
after_transition [:created, :waiting_for_resource, :preparing, :pending, :running] => :success do |pipeline|
- pipeline.run_after_commit { PipelineSuccessWorker.perform_async(pipeline.id) }
+ # We wait a little bit to ensure that all BuildFinishedWorkers finish first
+ # because this is where some metrics like code coverage is parsed and stored
+ # in CI build records which the daily build metrics worker relies on.
+ pipeline.run_after_commit { Ci::DailyReportResultsWorker.perform_in(10.minutes, pipeline.id) }
end
after_transition do |pipeline, transition|
@@ -941,6 +946,14 @@ module Ci
Ci::PipelineEnums.ci_config_sources.key?(config_source.to_sym)
end
+ def source_ref_path
+ if branch? || merge_request?
+ Gitlab::Git::BRANCH_REF_PREFIX + source_ref.to_s
+ elsif tag?
+ Gitlab::Git::TAG_REF_PREFIX + source_ref.to_s
+ end
+ end
+
private
def pipeline_data
diff --git a/app/models/project.rb b/app/models/project.rb
index 8578cd0e44a..4892c5310ec 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -314,6 +314,8 @@ class Project < ApplicationRecord
has_many :import_failures, inverse_of: :project
+ has_many :daily_report_results, class_name: 'Ci::DailyReportResult'
+
accepts_nested_attributes_for :variables, allow_destroy: true
accepts_nested_attributes_for :project_feature, update_only: true
accepts_nested_attributes_for :import_data
diff --git a/app/models/user.rb b/app/models/user.rb
index 0c7dfac5776..6972a465c30 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -21,6 +21,7 @@ class User < ApplicationRecord
include OptionallySearch
include FromUnion
include BatchDestroyDependentAssociations
+ include IgnorableColumns
DEFAULT_NOTIFICATION_LEVEL = :participating
@@ -59,9 +60,10 @@ class User < ApplicationRecord
MINIMUM_INACTIVE_DAYS = 180
- enum bot_type: ::UserBotTypeEnums.bots
enum user_type: ::UserTypeEnums.types
+ ignore_column :bot_type, remove_with: '12.11', remove_after: '2020-04-22'
+
# Override Devise::Models::Trackable#update_tracked_fields!
# to limit database writes to at most once every hour
# rubocop: disable CodeReuse/ServiceClass
@@ -337,8 +339,9 @@ class User < ApplicationRecord
scope :with_emails, -> { preload(:emails) }
scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) }
scope :with_public_profile, -> { where(private_profile: false) }
- scope :bots, -> { where.not(bot_type: nil) }
- scope :humans, -> { where(user_type: nil, bot_type: nil) }
+ scope :bots, -> { where(user_type: UserTypeEnums.bots.values) }
+ scope :not_bots, -> { humans.or(where.not(user_type: UserTypeEnums.bots.values)) }
+ scope :humans, -> { where(user_type: nil) }
scope :with_expiring_and_not_notified_personal_access_tokens, ->(at) do
where('EXISTS (?)',
@@ -618,7 +621,7 @@ class User < ApplicationRecord
def alert_bot
email_pattern = "alert%s@#{Settings.gitlab.host}"
- unique_internal(where(bot_type: :alert_bot), 'alert-bot', email_pattern) do |u|
+ unique_internal(where(user_type: :alert_bot), 'alert-bot', email_pattern) do |u|
u.bio = 'The GitLab alert bot'
u.name = 'GitLab Alert Bot'
end
@@ -640,7 +643,7 @@ class User < ApplicationRecord
end
def bot?
- bot_type.present?
+ UserTypeEnums.bots.has_key?(user_type)
end
def internal?
@@ -652,7 +655,7 @@ class User < ApplicationRecord
end
def self.non_internal
- without_ghosts.humans
+ without_ghosts.not_bots
end
#
diff --git a/app/models/user_bot_type_enums.rb b/app/models/user_bot_type_enums.rb
deleted file mode 100644
index 1a9c02a3998..00000000000
--- a/app/models/user_bot_type_enums.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-module UserBotTypeEnums
- def self.bots
- {
- alert_bot: 2
- }
- end
-end
-
-UserBotTypeEnums.prepend_if_ee('EE::UserBotTypeEnums')
diff --git a/app/models/user_type_enums.rb b/app/models/user_type_enums.rb
index 4e9dd70aee8..2d0d2f3a4ce 100644
--- a/app/models/user_type_enums.rb
+++ b/app/models/user_type_enums.rb
@@ -2,13 +2,13 @@
module UserTypeEnums
def self.types
- bots
+ bots.merge(human: nil)
end
def self.bots
{
- AlertBot: 2
- }
+ alert_bot: 2
+ }.with_indifferent_access
end
end