summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-03 15:09:56 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-03 15:09:56 +0000
commitc08d9c22569d1c9e7c7737e183969593394133d9 (patch)
tree8ce1722f852f8921656080e04f6c9e16fa71ddb5 /lib
parent546ddc3f6ac96fdf09934390a938bb391d07dc94 (diff)
downloadgitlab-ce-c08d9c22569d1c9e7c7737e183969593394133d9.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/entry/include.rb5
-rw-r--r--lib/gitlab/ci/yaml_processor.rb50
-rw-r--r--lib/gitlab/database/batch_count.rb4
-rw-r--r--lib/gitlab/jira_import/issue_serializer.rb47
4 files changed, 87 insertions, 19 deletions
diff --git a/lib/gitlab/ci/config/entry/include.rb b/lib/gitlab/ci/config/entry/include.rb
index cd09d83b728..b2586714636 100644
--- a/lib/gitlab/ci/config/entry/include.rb
+++ b/lib/gitlab/ci/config/entry/include.rb
@@ -15,6 +15,11 @@ module Gitlab
validations do
validates :config, hash_or_string: true
validates :config, allowed_keys: ALLOWED_KEYS
+ validate do
+ if config[:artifact] && config[:job].blank?
+ errors.add(:config, "must specify the job where to fetch the artifact from")
+ end
+ end
end
end
end
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb
index 764047dae6d..4b0062549f0 100644
--- a/lib/gitlab/ci/yaml_processor.rb
+++ b/lib/gitlab/ci/yaml_processor.rb
@@ -142,6 +142,7 @@ module Gitlab
validate_job_stage!(name, job)
validate_job_dependencies!(name, job)
validate_job_needs!(name, job)
+ validate_dynamic_child_pipeline_dependencies!(name, job)
validate_job_environment!(name, job)
end
end
@@ -163,37 +164,52 @@ module Gitlab
def validate_job_dependencies!(name, job)
return unless job[:dependencies]
- stage_index = @stages.index(job[:stage])
-
job[:dependencies].each do |dependency|
- raise ValidationError, "#{name} job: undefined dependency: #{dependency}" unless @jobs[dependency.to_sym]
+ validate_job_dependency!(name, dependency)
+ end
+ end
- dependency_stage_index = @stages.index(@jobs[dependency.to_sym][:stage])
+ def validate_dynamic_child_pipeline_dependencies!(name, job)
+ return unless includes = job.dig(:trigger, :include)
- unless dependency_stage_index.present? && dependency_stage_index < stage_index
- raise ValidationError, "#{name} job: dependency #{dependency} is not defined in prior stages"
- end
+ includes.each do |included|
+ next unless dependency = included[:job]
+
+ validate_job_dependency!(name, dependency)
end
end
def validate_job_needs!(name, job)
- return unless job.dig(:needs, :job)
-
- stage_index = @stages.index(job[:stage])
+ return unless needs = job.dig(:needs, :job)
- job.dig(:needs, :job).each do |need|
- need_job_name = need[:name]
+ needs.each do |need|
+ dependency = need[:name]
+ validate_job_dependency!(name, dependency, 'need')
+ end
+ end
- raise ValidationError, "#{name} job: undefined need: #{need_job_name}" unless @jobs[need_job_name.to_sym]
+ def validate_job_dependency!(name, dependency, dependency_type = 'dependency')
+ unless @jobs[dependency.to_sym]
+ raise ValidationError, "#{name} job: undefined #{dependency_type}: #{dependency}"
+ end
- needs_stage_index = @stages.index(@jobs[need_job_name.to_sym][:stage])
+ job_stage_index = stage_index(name)
+ dependency_stage_index = stage_index(dependency)
- unless needs_stage_index.present? && needs_stage_index < stage_index
- raise ValidationError, "#{name} job: need #{need_job_name} is not defined in prior stages"
- end
+ # A dependency might be defined later in the configuration
+ # with a stage that does not exist
+ unless dependency_stage_index.present? && dependency_stage_index < job_stage_index
+ raise ValidationError, "#{name} job: #{dependency_type} #{dependency} is not defined in prior stages"
end
end
+ def stage_index(name)
+ job = @jobs[name.to_sym]
+ return unless job
+
+ @stages.index(job[:stage])
+ end
+
def validate_job_environment!(name, job)
return unless job[:environment]
return unless job[:environment].is_a?(Hash)
diff --git a/lib/gitlab/database/batch_count.rb b/lib/gitlab/database/batch_count.rb
index e0f6b0f9eee..5987dc34801 100644
--- a/lib/gitlab/database/batch_count.rb
+++ b/lib/gitlab/database/batch_count.rb
@@ -39,8 +39,8 @@ module Gitlab
SLEEP_TIME_IN_SECONDS = 0.01 # 10 msec sleep
# Each query should take < 500ms https://gitlab.com/gitlab-org/gitlab/-/merge_requests/22705
- DEFAULT_DISTINCT_BATCH_SIZE = 100_000
- DEFAULT_BATCH_SIZE = 10_000
+ DEFAULT_DISTINCT_BATCH_SIZE = 10_000
+ DEFAULT_BATCH_SIZE = 100_000
def initialize(relation, column: nil)
@relation = relation
diff --git a/lib/gitlab/jira_import/issue_serializer.rb b/lib/gitlab/jira_import/issue_serializer.rb
index 0be5d22065a..cdcb62ac6e9 100644
--- a/lib/gitlab/jira_import/issue_serializer.rb
+++ b/lib/gitlab/jira_import/issue_serializer.rb
@@ -4,12 +4,14 @@ module Gitlab
module JiraImport
class IssueSerializer
attr_reader :jira_issue, :project, :params, :formatter
+ attr_accessor :metadata
def initialize(project, jira_issue, params = {})
@jira_issue = jira_issue
@project = project
@params = params
@formatter = Gitlab::ImportFormatter.new
+ @metadata = []
end
def execute
@@ -36,6 +38,7 @@ module Gitlab
body << formatter.author_line(jira_issue.reporter.displayName)
body << formatter.assignee_line(jira_issue.assignee.displayName) if jira_issue.assignee
body << jira_issue.description
+ body << add_metadata
body.join
end
@@ -48,6 +51,50 @@ module Gitlab
Issuable::STATE_ID_MAP[:opened]
end
end
+
+ def add_metadata
+ add_field(%w(issuetype name), 'Issue type')
+ add_field(%w(priority name), 'Priority')
+ add_labels
+ add_field('environment', 'Environment')
+ add_field('duedate', 'Due date')
+ add_parent
+ add_versions
+
+ return if metadata.empty?
+
+ metadata.join("\n").prepend("\n\n---\n\n**Issue metadata**\n\n")
+ end
+
+ def add_field(keys, field_label)
+ value = fields.dig(*keys)
+ return if value.blank?
+
+ metadata << "- #{field_label}: #{value}"
+ end
+
+ def add_labels
+ return if fields['labels'].blank?
+
+ metadata << "- Labels: #{fields['labels'].join(', ')}"
+ end
+
+ def add_parent
+ parent_issue_key = fields.dig('parent', 'key')
+ return if parent_issue_key.blank?
+
+ metadata << "- Parent issue: [#{parent_issue_key}] #{fields['parent']['fields']['summary']}"
+ end
+
+ def add_versions
+ return if fields['fixVersions'].blank?
+
+ metadata << "- Fix versions: #{fields['fixVersions'].map { |version| version['name'] }.join(', ')}"
+ end
+
+ def fields
+ jira_issue.fields
+ end
end
end
end