Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-15 03:10:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-15 03:10:51 +0300
commitd9749000e7835a56d960b4768abe783dca37f37e (patch)
tree1899ba4f5586ffb45e26162c45c6df2d3553dd42 /app
parent4b5042946065b750131e51790b84fe4a5aa7aa02 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/has_integrations.rb19
-rw-r--r--app/models/concerns/integrations/push_data_validations.rb44
-rw-r--r--app/models/concerns/service_push_data_validations.rb43
-rw-r--r--app/models/integrations/drone_ci.rb2
-rw-r--r--app/models/integrations/teamcity.rb2
-rw-r--r--app/models/project.rb13
6 files changed, 58 insertions, 65 deletions
diff --git a/app/models/concerns/has_integrations.rb b/app/models/concerns/has_integrations.rb
deleted file mode 100644
index 76e03d68600..00000000000
--- a/app/models/concerns/has_integrations.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-module HasIntegrations
- extend ActiveSupport::Concern
-
- class_methods do
- def without_integration(integration)
- integrations = Integration
- .select('1')
- .where("#{Integration.table_name}.project_id = projects.id")
- .where(type: integration.type)
-
- Project
- .where('NOT EXISTS (?)', integrations)
- .where(pending_delete: false)
- .where(archived: false)
- end
- end
-end
diff --git a/app/models/concerns/integrations/push_data_validations.rb b/app/models/concerns/integrations/push_data_validations.rb
new file mode 100644
index 00000000000..966fc94e289
--- /dev/null
+++ b/app/models/concerns/integrations/push_data_validations.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+# This concern is used by registered integrations such as Integrations::TeamCity and
+# Integrations::DroneCi and adds methods to perform validations on the received
+# data.
+module Integrations
+ module PushDataValidations
+ extend ActiveSupport::Concern
+
+ def merge_request_valid?(data)
+ data.dig(:object_attributes, :state) == 'opened' && merge_request_unchecked?(data)
+ end
+
+ def push_valid?(data)
+ data[:total_commits_count] > 0 &&
+ !branch_removed?(data) &&
+ # prefer merge request trigger over push to avoid double builds
+ !opened_merge_requests?(data)
+ end
+
+ def tag_push_valid?(data)
+ data[:total_commits_count] > 0 && !branch_removed?(data)
+ end
+
+ private
+
+ def branch_removed?(data)
+ Gitlab::Git.blank_ref?(data[:after])
+ end
+
+ def opened_merge_requests?(data)
+ project.merge_requests
+ .opened
+ .from_project(project)
+ .from_source_branches(Gitlab::Git.ref_name(data[:ref]))
+ .exists?
+ end
+
+ def merge_request_unchecked?(data)
+ MergeRequest.state_machines[:merge_status]
+ .check_state?(data.dig(:object_attributes, :merge_status))
+ end
+ end
+end
diff --git a/app/models/concerns/service_push_data_validations.rb b/app/models/concerns/service_push_data_validations.rb
deleted file mode 100644
index 451804a2c56..00000000000
--- a/app/models/concerns/service_push_data_validations.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# frozen_string_literal: true
-
-# This concern is used by registered integrations such as Integrations::TeamCity and
-# Integrations::DroneCi and adds methods to perform validations on the received
-# data.
-
-module ServicePushDataValidations
- extend ActiveSupport::Concern
-
- def merge_request_valid?(data)
- data.dig(:object_attributes, :state) == 'opened' && merge_request_unchecked?(data)
- end
-
- def push_valid?(data)
- data[:total_commits_count] > 0 &&
- !branch_removed?(data) &&
- # prefer merge request trigger over push to avoid double builds
- !opened_merge_requests?(data)
- end
-
- def tag_push_valid?(data)
- data[:total_commits_count] > 0 && !branch_removed?(data)
- end
-
- private
-
- def branch_removed?(data)
- Gitlab::Git.blank_ref?(data[:after])
- end
-
- def opened_merge_requests?(data)
- project.merge_requests
- .opened
- .from_project(project)
- .from_source_branches(Gitlab::Git.ref_name(data[:ref]))
- .exists?
- end
-
- def merge_request_unchecked?(data)
- MergeRequest.state_machines[:merge_status]
- .check_state?(data.dig(:object_attributes, :merge_status))
- end
-end
diff --git a/app/models/integrations/drone_ci.rb b/app/models/integrations/drone_ci.rb
index 6843aa21892..856d14c022d 100644
--- a/app/models/integrations/drone_ci.rb
+++ b/app/models/integrations/drone_ci.rb
@@ -3,8 +3,8 @@
module Integrations
class DroneCi < BaseCi
include HasWebHook
+ include PushDataValidations
include ReactivelyCached
- include ServicePushDataValidations
extend Gitlab::Utils::Override
prop_accessor :drone_url, :token
diff --git a/app/models/integrations/teamcity.rb b/app/models/integrations/teamcity.rb
index 9da9c0d2909..008b591c304 100644
--- a/app/models/integrations/teamcity.rb
+++ b/app/models/integrations/teamcity.rb
@@ -2,8 +2,8 @@
module Integrations
class Teamcity < BaseCi
+ include PushDataValidations
include ReactivelyCached
- include ServicePushDataValidations
prop_accessor :teamcity_url, :build_type, :username, :password
diff --git a/app/models/project.rb b/app/models/project.rb
index 2f98a116815..604158d1a6e 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -19,7 +19,6 @@ class Project < ApplicationRecord
include Presentable
include HasRepository
include HasWiki
- include HasIntegrations
include CanMoveRepositoryStorage
include Routable
include GroupDescendant
@@ -860,6 +859,18 @@ class Project < ApplicationRecord
rescue ActionController::RoutingError, URI::InvalidURIError
nil
end
+
+ def without_integration(integration)
+ integrations = Integration
+ .select('1')
+ .where("#{Integration.table_name}.project_id = projects.id")
+ .where(type: integration.type)
+
+ Project
+ .where('NOT EXISTS (?)', integrations)
+ .where(pending_delete: false)
+ .where(archived: false)
+ end
end
def initialize(attributes = nil)