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/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-24 18:06:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-24 18:06:34 +0300
commitf1a5755898e865428c923587402fd965b601c4ea (patch)
treea93aab01a1d3ba0e93c0fbf1450babfe4674f9dc /lib
parent1ae627c65192ae1a01fdac253065ef561a9d6b7e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/build/rules/rule/clause/exists.rb64
-rw-r--r--lib/gitlab/ci/config/entry/rules/rule.rb8
-rw-r--r--lib/gitlab/danger/helper.rb3
-rw-r--r--lib/tasks/services.rake98
4 files changed, 70 insertions, 103 deletions
diff --git a/lib/gitlab/ci/build/rules/rule/clause/exists.rb b/lib/gitlab/ci/build/rules/rule/clause/exists.rb
new file mode 100644
index 00000000000..62f8371283f
--- /dev/null
+++ b/lib/gitlab/ci/build/rules/rule/clause/exists.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ class Rules::Rule::Clause::Exists < Rules::Rule::Clause
+ # The maximum number of patterned glob comparisons that will be
+ # performed before the rule assumes that it has a match
+ MAX_PATTERN_COMPARISONS = 10_000
+
+ def initialize(globs)
+ globs = Array(globs)
+
+ @top_level_only = globs.all?(&method(:top_level_glob?))
+ @exact_globs, @pattern_globs = globs.partition(&method(:exact_glob?))
+ end
+
+ def satisfied_by?(pipeline, seed)
+ paths = worktree_paths(pipeline)
+
+ exact_matches?(paths) || pattern_matches?(paths)
+ end
+
+ private
+
+ def worktree_paths(pipeline)
+ if @top_level_only
+ pipeline.top_level_worktree_paths
+ else
+ pipeline.all_worktree_paths
+ end
+ end
+
+ def exact_matches?(paths)
+ @exact_globs.any? { |glob| paths.bsearch { |path| glob <=> path } }
+ end
+
+ def pattern_matches?(paths)
+ comparisons = 0
+ @pattern_globs.any? do |glob|
+ paths.any? do |path|
+ comparisons += 1
+ comparisons > MAX_PATTERN_COMPARISONS || pattern_match?(glob, path)
+ end
+ end
+ end
+
+ def pattern_match?(glob, path)
+ File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
+ end
+
+ # matches glob patterns that only match files in the top level directory
+ def top_level_glob?(glob)
+ !glob.include?('/') && !glob.include?('**')
+ end
+
+ # matches glob patterns that have no metacharacters for File#fnmatch?
+ def exact_glob?(glob)
+ !glob.include?('*') && !glob.include?('?') && !glob.include?('[') && !glob.include?('{')
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/rules/rule.rb b/lib/gitlab/ci/config/entry/rules/rule.rb
index 1f2a34ec90e..5d6d1c026e3 100644
--- a/lib/gitlab/ci/config/entry/rules/rule.rb
+++ b/lib/gitlab/ci/config/entry/rules/rule.rb
@@ -8,11 +8,11 @@ module Gitlab
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
- CLAUSES = %i[if changes].freeze
- ALLOWED_KEYS = %i[if changes when start_in].freeze
+ CLAUSES = %i[if changes exists].freeze
+ ALLOWED_KEYS = %i[if changes exists when start_in].freeze
ALLOWED_WHEN = %w[on_success on_failure always never manual delayed].freeze
- attributes :if, :changes, :when, :start_in
+ attributes :if, :changes, :exists, :when, :start_in
validations do
validates :config, presence: true
@@ -24,7 +24,7 @@ module Gitlab
with_options allow_nil: true do
validates :if, expression: true
- validates :changes, array_of_strings: true
+ validates :changes, :exists, array_of_strings: true, length: { maximum: 50 }
validates :when, allowed_values: { in: ALLOWED_WHEN }
end
end
diff --git a/lib/gitlab/danger/helper.rb b/lib/gitlab/danger/helper.rb
index 36e0ec65720..f22fc41a6d8 100644
--- a/lib/gitlab/danger/helper.rb
+++ b/lib/gitlab/danger/helper.rb
@@ -35,7 +35,8 @@ module Gitlab
end
def ee?
- ENV['CI_PROJECT_NAME'] == 'gitlab' || File.exist?('../../CHANGELOG-EE.md')
+ # Support former project name for `dev` and support local Danger run
+ %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?('../../ee')
end
def gitlab_helper
diff --git a/lib/tasks/services.rake b/lib/tasks/services.rake
deleted file mode 100644
index 4ec4fdd281f..00000000000
--- a/lib/tasks/services.rake
+++ /dev/null
@@ -1,98 +0,0 @@
-services_template = <<-ERB
-# Services
-
-<% services.each do |service| %>
-## <%= service[:title] %>
-
-
-<% unless service[:description].blank? %>
-<%= service[:description] %>
-<% end %>
-
-
-### Create/Edit <%= service[:title] %> service
-
-Set <%= service[:title] %> service for a project.
-<% unless service[:help].blank? %>
-
-> <%= service[:help].gsub("\n", ' ') %>
-
-<% end %>
-
-```
-PUT /projects/:id/services/<%= service[:dashed_name] %>
-
-```
-
-Parameters:
-
-<% service[:params].each do |param| %>
-- `<%= param[:name] %>` <%= param[:required] ? "(**required**)" : "(optional)" %><%= [" -", param[:description]].join(" ").gsub("\n", '') unless param[:description].blank? %>
-
-<% end %>
-
-### Delete <%= service[:title] %> service
-
-Delete <%= service[:title] %> service for a project.
-
-```
-DELETE /projects/:id/services/<%= service[:dashed_name] %>
-
-```
-
-### Get <%= service[:title] %> service settings
-
-Get <%= service[:title] %> service settings for a project.
-
-```
-GET /projects/:id/services/<%= service[:dashed_name] %>
-
-```
-
-<% end %>
-ERB
-
-namespace :services do
- task doc: :environment do
- services = Service.available_services_names.map do |s|
- service_start = Time.now
- klass = "#{s}_service".classify.constantize
-
- service = klass.new
-
- service_hash = {}
-
- service_hash[:title] = service.title
- service_hash[:dashed_name] = s.dasherize
- service_hash[:description] = service.description
- service_hash[:help] = service.help
- service_hash[:params] = service.fields.map do |p|
- param_hash = {}
-
- param_hash[:name] = p[:name]
- param_hash[:description] = p[:placeholder] || p[:title]
- param_hash[:required] = klass.validators_on(p[:name].to_sym).any? do |v|
- v.class == ActiveRecord::Validations::PresenceValidator
- end
-
- param_hash
- end
- service_hash[:params].sort_by! { |p| p[:required] ? 0 : 1 }
-
- puts "Collected data for: #{service.title}, #{Time.now - service_start}"
- service_hash
- end
-
- doc_start = Time.now
- doc_path = File.join(Rails.root, 'doc', 'api', 'services.md')
-
- result = ERB.new(services_template, trim_mode: '>')
- .result(OpenStruct.new(services: services).instance_eval { binding })
-
- File.open(doc_path, 'w') do |f|
- f.write result
- end
-
- puts "write a new service.md to: #{doc_path}, #{Time.now - doc_start}"
- end
-end