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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-01-06 15:10:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-01-06 15:10:58 +0300
commitf2c27c6f97cf138acaed79b90be7a5be520746fc (patch)
tree369b09c536983f7b8682a8e66ebdac8fd6c54446 /lib/atlassian/jira_connect
parentb3c8b65ec2ab3af29d4d14eac27837e0c4793939 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/atlassian/jira_connect')
-rw-r--r--lib/atlassian/jira_connect/client.rb13
-rw-r--r--lib/atlassian/jira_connect/serializers/build_entity.rb6
-rw-r--r--lib/atlassian/jira_connect/serializers/deployment_entity.rb90
-rw-r--r--lib/atlassian/jira_connect/serializers/environment_entity.rb39
-rw-r--r--lib/atlassian/jira_connect/serializers/pipeline_entity.rb31
5 files changed, 177 insertions, 2 deletions
diff --git a/lib/atlassian/jira_connect/client.rb b/lib/atlassian/jira_connect/client.rb
index da24d0e20ee..76211eba0bb 100644
--- a/lib/atlassian/jira_connect/client.rb
+++ b/lib/atlassian/jira_connect/client.rb
@@ -16,11 +16,13 @@ module Atlassian
common = { project: project, update_sequence_id: update_sequence_id }
dev_info = args.slice(:commits, :branches, :merge_requests)
build_info = args.slice(:pipelines)
+ deploy_info = args.slice(:deployments)
responses = []
responses << store_dev_info(**common, **dev_info) if dev_info.present?
responses << store_build_info(**common, **build_info) if build_info.present?
+ responses << store_deploy_info(**common, **deploy_info) if deploy_info.present?
raise ArgumentError, 'Invalid arguments' if responses.empty?
responses.compact
@@ -28,6 +30,17 @@ module Atlassian
private
+ def store_deploy_info(project:, deployments:, **opts)
+ return unless Feature.enabled?(:jira_sync_deployments, project)
+
+ items = deployments.map { |d| Serializers::DeploymentEntity.represent(d, opts) }
+ items.reject! { |d| d.issue_keys.empty? }
+
+ return if items.empty?
+
+ post('/rest/deployments/0.1/bulk', { deployments: items })
+ end
+
def store_build_info(project:, pipelines:, update_sequence_id: nil)
return unless Feature.enabled?(:jira_sync_builds, project)
diff --git a/lib/atlassian/jira_connect/serializers/build_entity.rb b/lib/atlassian/jira_connect/serializers/build_entity.rb
index 3eb8b1f1978..8372d2a62da 100644
--- a/lib/atlassian/jira_connect/serializers/build_entity.rb
+++ b/lib/atlassian/jira_connect/serializers/build_entity.rb
@@ -25,8 +25,10 @@ module Atlassian
# extract Jira issue keys from either the source branch/ref or the
# merge request title.
@issue_keys ||= begin
- src = "#{pipeline.source_ref} #{pipeline.merge_request&.title}"
- JiraIssueKeyExtractor.new(src).issue_keys
+ pipeline.all_merge_requests.flat_map do |mr|
+ src = "#{mr.source_branch} #{mr.title}"
+ JiraIssueKeyExtractor.new(src).issue_keys
+ end.uniq
end
end
diff --git a/lib/atlassian/jira_connect/serializers/deployment_entity.rb b/lib/atlassian/jira_connect/serializers/deployment_entity.rb
new file mode 100644
index 00000000000..9ef1666b61c
--- /dev/null
+++ b/lib/atlassian/jira_connect/serializers/deployment_entity.rb
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+
+module Atlassian
+ module JiraConnect
+ module Serializers
+ class DeploymentEntity < Grape::Entity
+ include Gitlab::Routing
+
+ format_with(:iso8601, &:iso8601)
+
+ expose :schema_version, as: :schemaVersion
+ expose :iid, as: :deploymentSequenceNumber
+ expose :update_sequence_id, as: :updateSequenceNumber
+ expose :display_name, as: :displayName
+ expose :description
+ expose :associations
+ expose :url
+ expose :label
+ expose :state
+ expose :updated_at, as: :lastUpdated, format_with: :iso8601
+ expose :pipeline_entity, as: :pipeline
+ expose :environment_entity, as: :environment
+
+ def issue_keys
+ return [] unless build&.pipeline.present?
+
+ @issue_keys ||= BuildEntity.new(build.pipeline).issue_keys
+ end
+
+ private
+
+ delegate :project, :deployable, :environment, :iid, :ref, :short_sha, to: :object
+ alias_method :deployment, :object
+ alias_method :build, :deployable
+
+ def associations
+ keys = issue_keys
+
+ [{ associationType: :issueKeys, values: keys }] if keys.present?
+ end
+
+ def display_name
+ "Deployment #{iid} (#{ref}@#{short_sha}) to #{environment.name}"
+ end
+
+ def label
+ "#{project.full_path}-#{environment.name}-#{iid}-#{short_sha}"
+ end
+
+ def description
+ "Deployment #{deployment.iid} of #{project.name} at #{short_sha} (#{build&.name}) to #{environment.name}"
+ end
+
+ def url
+ # There is no controller action to show a single deployment, so we
+ # link to the build instead
+ project_job_url(project, build) if build
+ end
+
+ def state
+ case deployment.status
+ when 'created' then 'pending'
+ when 'running' then 'in_progress'
+ when 'success' then 'successful'
+ when 'failed' then 'failed'
+ when 'canceled', 'skipped' then 'cancelled'
+ else
+ 'unknown'
+ end
+ end
+
+ def schema_version
+ '1.0'
+ end
+
+ def pipeline_entity
+ PipelineEntity.new(build.pipeline) if build&.pipeline.present?
+ end
+
+ def environment_entity
+ EnvironmentEntity.new(environment)
+ end
+
+ def update_sequence_id
+ options[:update_sequence_id] || Client.generate_update_sequence_id
+ end
+ end
+ end
+ end
+end
diff --git a/lib/atlassian/jira_connect/serializers/environment_entity.rb b/lib/atlassian/jira_connect/serializers/environment_entity.rb
new file mode 100644
index 00000000000..f3699e4d0ee
--- /dev/null
+++ b/lib/atlassian/jira_connect/serializers/environment_entity.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module Atlassian
+ module JiraConnect
+ module Serializers
+ class EnvironmentEntity < Grape::Entity
+ format_with(:string, &:to_s)
+
+ expose :id, format_with: :string
+ expose :display_name, as: :displayName
+ expose :type
+
+ private
+
+ alias_method :environment, :object
+ delegate :project, to: :object
+
+ def display_name
+ "#{project.name}/#{environment.name}"
+ end
+
+ def type
+ case environment.name
+ when /prod/i
+ 'production'
+ when /test/i
+ 'testing'
+ when /staging/i
+ 'staging'
+ when /(dev|review)/i
+ 'development'
+ else
+ 'unmapped'
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/atlassian/jira_connect/serializers/pipeline_entity.rb b/lib/atlassian/jira_connect/serializers/pipeline_entity.rb
new file mode 100644
index 00000000000..e67cf1a7229
--- /dev/null
+++ b/lib/atlassian/jira_connect/serializers/pipeline_entity.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Atlassian
+ module JiraConnect
+ module Serializers
+ # Both this an BuildEntity represent a Ci::Pipeline
+ class PipelineEntity < Grape::Entity
+ include Gitlab::Routing
+
+ format_with(:string, &:to_s)
+
+ expose :id, format_with: :string
+ expose :display_name, as: :displayName
+ expose :url
+
+ private
+
+ alias_method :pipeline, :object
+ delegate :project, to: :object
+
+ def display_name
+ "#{project.name} pipeline #{pipeline.iid}"
+ end
+
+ def url
+ project_pipeline_url(project, pipeline)
+ end
+ end
+ end
+ end
+end