diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:07:55 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:07:55 +0000 |
commit | 603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc (patch) | |
tree | 907f5b8ee1b6f5aad396e95e3327a08400b9e8ea /app/models | |
parent | 120f4aaedc8fe830a3f572491d240d8ee6addefb (diff) | |
download | gitlab-ce-603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 2 | ||||
-rw-r--r-- | app/models/ci/job_artifact.rb | 10 | ||||
-rw-r--r-- | app/models/concerns/milestoneish.rb | 12 | ||||
-rw-r--r-- | app/models/issue.rb | 2 | ||||
-rw-r--r-- | app/models/service.rb | 33 |
5 files changed, 49 insertions, 10 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index b555b78cda6..d0ea7439556 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -33,6 +33,8 @@ module Ci scheduler_failure: 2 }.freeze + CODE_NAVIGATION_JOB_NAME = 'code_navigation' + has_one :deployment, as: :deployable, class_name: 'Deployment' has_one :resource, class_name: 'Ci::Resource', inverse_of: :build has_many :trace_sections, class_name: 'Ci::BuildTraceSection' diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index ae57da9c546..ef0701b3874 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -31,7 +31,8 @@ module Ci metrics: 'metrics.txt', lsif: 'lsif.json', dotenv: '.env', - cobertura: 'cobertura-coverage.xml' + cobertura: 'cobertura-coverage.xml', + terraform: 'tfplan.json' }.freeze INTERNAL_TYPES = { @@ -59,7 +60,8 @@ module Ci dast: :raw, license_management: :raw, license_scanning: :raw, - performance: :raw + performance: :raw, + terraform: :raw }.freeze TYPE_AND_FORMAT_PAIRS = INTERNAL_TYPES.merge(REPORT_TYPES).freeze @@ -80,6 +82,7 @@ module Ci scope :with_files_stored_locally, -> { where(file_store: [nil, ::JobArtifactUploader::Store::LOCAL]) } scope :with_files_stored_remotely, -> { where(file_store: ::JobArtifactUploader::Store::REMOTE) } scope :for_sha, ->(sha, project_id) { joins(job: :pipeline).where(ci_pipelines: { sha: sha, project_id: project_id }) } + scope :for_job_name, ->(name) { joins(:job).where(ci_builds: { name: name }) } scope :with_file_types, -> (file_types) do types = self.file_types.select { |file_type| file_types.include?(file_type) }.values @@ -129,7 +132,8 @@ module Ci network_referee: 14, ## runner referees lsif: 15, # LSIF data for code navigation dotenv: 16, - cobertura: 17 + cobertura: 17, + terraform: 18 # Transformed json } enum file_format: { diff --git a/app/models/concerns/milestoneish.rb b/app/models/concerns/milestoneish.rb index 6dbb9649b9f..fac058e5a46 100644 --- a/app/models/concerns/milestoneish.rb +++ b/app/models/concerns/milestoneish.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true module Milestoneish + DISPLAY_ISSUES_LIMIT = 3000 + def total_issues_count @total_issues_count ||= Milestones::IssuesCountService.new(self).count end @@ -55,7 +57,15 @@ module Milestoneish end def sorted_issues(user) - issues_visible_to_user(user).preload_associated_models.sort_by_attribute('label_priority') + # This method is used on milestone view to filter opened assigned, opened unassigned and closed issues columns. + # We want a limit of DISPLAY_ISSUES_LIMIT for total issues present on all columns. + limited_ids = + issues_visible_to_user(user).sort_by_attribute('label_priority').limit(DISPLAY_ISSUES_LIMIT) + + Issue + .where(id: Issue.select(:id).from(limited_ids)) + .preload_associated_models + .sort_by_attribute('label_priority') end def sorted_merge_requests(user) diff --git a/app/models/issue.rb b/app/models/issue.rb index bdcebb4b942..0f00a78c728 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -70,7 +70,7 @@ class Issue < ApplicationRecord scope :order_closed_date_desc, -> { reorder(closed_at: :desc) } scope :order_created_at_desc, -> { reorder(created_at: :desc) } - scope :preload_associated_models, -> { preload(:labels, project: :namespace) } + scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) } scope :with_api_entity_associations, -> { preload(:timelogs, :assignees, :author, :notes, :labels, project: [:route, { namespace: :route }] ) } scope :public_only, -> { where(confidential: false) } diff --git a/app/models/service.rb b/app/models/service.rb index 5782fab3266..138da0c546e 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -46,6 +46,7 @@ class Service < ApplicationRecord scope :active, -> { where(active: true) } scope :without_defaults, -> { where(default: false) } scope :by_type, -> (type) { where(type: type) } + scope :templates, -> { where(template: true, type: available_services_types) } scope :push_hooks, -> { where(push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } @@ -259,14 +260,32 @@ class Service < ApplicationRecord self.category == :issue_tracker end + # Find all service templates; if some of them do not exist, create them + # within a transaction to perform the lowest possible SQL queries. + def self.find_or_create_templates + create_nonexistent_templates + templates + end + + private_class_method def self.create_nonexistent_templates + nonexistent_services = available_services_types - templates.map(&:type) + return if nonexistent_services.empty? + + transaction do + nonexistent_services.each do |service_type| + service_type.constantize.create(template: true) + end + end + end + def self.available_services_names service_names = %w[ alerts asana assembla bamboo - buildkite bugzilla + buildkite campfire custom_issue_tracker discord @@ -278,20 +297,20 @@ class Service < ApplicationRecord hipchat irker jira - mattermost_slash_commands mattermost + mattermost_slash_commands + microsoft_teams packagist pipelines_email pivotaltracker prometheus pushover redmine - youtrack - slack_slash_commands slack + slack_slash_commands teamcity - microsoft_teams unify_circuit + youtrack ] if Rails.env.development? @@ -301,6 +320,10 @@ class Service < ApplicationRecord service_names.sort_by(&:downcase) end + def self.available_services_types + available_services_names.map { |service_name| "#{service_name}_service".camelize } + end + def self.build_from_template(project_id, template) service = template.dup |