diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:06:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:06:17 +0300 |
commit | 238d22c07218adf2b8f3db630ee8b74ca6f29df5 (patch) | |
tree | 23fd5f85efef0fb95eb73bf6395d5b7e8c0f1b9f /app/models | |
parent | 6b75320f525f841454f1ab162d141d3610f2e77b (diff) |
Add latest changes from gitlab-org/gitlab@masterlist
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build_trace.rb | 41 | ||||
-rw-r--r-- | app/models/evidence.rb | 27 | ||||
-rw-r--r-- | app/models/group.rb | 6 | ||||
-rw-r--r-- | app/models/hooks/web_hook.rb | 2 | ||||
-rw-r--r-- | app/models/release.rb | 7 | ||||
-rw-r--r-- | app/models/todo.rb | 8 |
6 files changed, 86 insertions, 5 deletions
diff --git a/app/models/ci/build_trace.rb b/app/models/ci/build_trace.rb new file mode 100644 index 00000000000..b9db1559836 --- /dev/null +++ b/app/models/ci/build_trace.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Ci + class BuildTrace + CONVERTERS = { + html: Gitlab::Ci::Ansi2html, + json: Gitlab::Ci::Ansi2json + }.freeze + + attr_reader :trace, :build + + delegate :state, :append, :truncated, :offset, :size, :total, to: :trace, allow_nil: true + delegate :id, :status, :complete?, to: :build, prefix: true + + def initialize(build:, stream:, state:, content_format:) + @build = build + @content_format = content_format + + if stream.valid? + stream.limit + @trace = CONVERTERS.fetch(content_format).convert(stream.stream, state) + end + end + + def json? + @content_format == :json + end + + def html? + @content_format == :html + end + + def json_lines + @trace&.lines if json? + end + + def html_lines + @trace&.html if html? + end + end +end diff --git a/app/models/evidence.rb b/app/models/evidence.rb new file mode 100644 index 00000000000..69a00f1cb3f --- /dev/null +++ b/app/models/evidence.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Evidence < ApplicationRecord + include ShaAttribute + + belongs_to :release + + before_validation :generate_summary_and_sha + + default_scope { order(created_at: :asc) } + + sha_attribute :summary_sha + + def milestones + @milestones ||= release.milestones.includes(:issues) + end + + private + + def generate_summary_and_sha + summary = Evidences::EvidenceSerializer.new.represent(self) # rubocop: disable CodeReuse/Serializer + return unless summary + + self.summary = summary + self.summary_sha = Gitlab::CryptoHelper.sha256(summary) + end +end diff --git a/app/models/group.rb b/app/models/group.rb index 8b21206fccf..042201ffa14 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -473,6 +473,12 @@ class Group < Namespace errors.add(:visibility_level, "#{visibility} is not allowed since there are sub-groups with higher visibility.") end + + def self.groups_including_descendants_by(group_ids) + Gitlab::ObjectHierarchy + .new(Group.where(id: group_ids)) + .base_and_descendants + end end Group.prepend_if_ee('EE::Group') diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index 16fc7fdbd48..e51b1c41059 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -13,7 +13,7 @@ class WebHook < ApplicationRecord algorithm: 'aes-256-gcm', key: Settings.attr_encrypted_db_key_base_32 - has_many :web_hook_logs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + has_many :web_hook_logs validates :url, presence: true validates :url, public_url: true, unless: ->(hook) { hook.is_a?(SystemHook) } diff --git a/app/models/release.rb b/app/models/release.rb index 8759e38060c..add57367f61 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -14,6 +14,7 @@ class Release < ApplicationRecord has_many :milestone_releases has_many :milestones, through: :milestone_releases + has_one :evidence default_value_for :released_at, allows_nil: false do Time.zone.now @@ -28,6 +29,8 @@ class Release < ApplicationRecord delegate :repository, to: :project + after_commit :create_evidence!, on: :create + def commit strong_memoize(:commit) do repository.commit(actual_sha) @@ -66,6 +69,10 @@ class Release < ApplicationRecord repository.find_tag(tag) end end + + def create_evidence! + CreateEvidenceWorker.perform_async(self.id) + end end Release.prepend_if_ee('EE::Release') diff --git a/app/models/todo.rb b/app/models/todo.rb index 456115872d1..1927b54510e 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -75,13 +75,13 @@ class Todo < ApplicationRecord after_save :keep_around_commit, if: :commit_id class << self - # Returns all todos for the given group and its descendants. + # Returns all todos for the given group ids and their descendants. # - # group - A `Group` to retrieve todos for. + # group_ids - Group Ids to retrieve todos for. # # Returns an `ActiveRecord::Relation`. - def for_group_and_descendants(group) - groups = group.self_and_descendants + def for_group_ids_and_descendants(group_ids) + groups = Group.groups_including_descendants_by(group_ids) from_union([ for_project(Project.for_group(groups)), |