1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
# frozen_string_literal: true
module Integrations
class JiraCloudApp < Integration
include HasAvatar
SERVICE_IDS_REGEX = /\A^[A-Za-z0-9=,:]*$\z/
SERVICE_IDS_LIMIT = 100
ENVIRONMENT_REGEX = /\A^[A-Za-z0-9,]*$\z/
AVAILABLE_ENVRIONMENT_NAMES = %w[production staging testing development].freeze
validate :validate_service_ids_limit, if: :activated?
validate :validate_deployment_gating_environments, if: :activated?
validate :validate_valid_deployment_gating_input, if: :activated?
validates :jira_cloud_app_service_ids, allow_blank: true, format: { with: SERVICE_IDS_REGEX }, if: :activated?
validates :jira_cloud_app_deployment_gating_environments, allow_blank: true, format: { with: ENVIRONMENT_REGEX },
if: :activated?
before_validation :format_deployment_gating_environments,
if: :jira_cloud_app_deployment_gating_environments_changed?
field :jira_cloud_app_service_ids,
section: SECTION_TYPE_CONFIGURATION,
required: false,
title: -> { s_("JiraCloudApp|Service ID") },
help: -> {
s_("JiraCloudApp|Copy and paste your JSM Service ID here. Use comma (,) to separate multiple IDs.")
}
field :jira_cloud_app_enable_deployment_gating,
section: SECTION_TYPE_CONFIGURATION,
type: :checkbox,
required: false,
title: -> { s_('JiraCloudApp|Deployment Gating') },
checkbox_label: -> { s_('JiraCloudApp|Enable Deployment Gating') },
help: -> {
s_('JiraCloudApp|Enable to approve or reject blocked GitLab deployments from Jira Service Management.')
}
field :jira_cloud_app_deployment_gating_environments,
section: SECTION_TYPE_CONFIGURATION,
required: false,
title: -> { s_('JiraCloudApp|Environment Tiers') },
help: -> {
format(
s_('JiraCloudApp|Enter the environment (%{names}) where you want to enable deployment gating. ' \
'Use comma (,) to separate multiple environments.'),
names: AVAILABLE_ENVRIONMENT_NAMES.join(',')
)
}
def self.title
s_('JiraCloudApp|GitLab for Jira Cloud app')
end
def self.description
s_('JiraCloudApp|Sync development information to Jira in real time.')
end
def self.help
jira_doc_link_start = format('<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe,
url: Gitlab::Routing.url_helpers.help_page_path('integration/jira/connect-app.md',
anchor: 'configure-the-gitlab-for-jira-cloud-app')
)
format(
s_('JiraCloudApp|This integration is enabled automatically when a group is linked in the ' \
'GitLab for Jira Cloud app and cannot be enabled or disabled through this form. ' \
"%{jira_doc_link_start}Learn more.%{link_end}"),
jira_doc_link_start: jira_doc_link_start,
link_end: '</a>'.html_safe)
end
def self.to_param
'jira_cloud_app'
end
def self.supported_events
[]
end
def sections
[
{
type: SECTION_TYPE_CONFIGURATION,
title: s_('JiraCloudApp|Jira Service Management'),
description: format(
'%{description}<br><br>%{help}'.html_safe,
description: s_('Seamlessly create change requests when your team initiates deployments.'),
help: help
)
}
]
end
override :manual_activation?
def manual_activation?
false
end
# The form fields of this integration are editable only after the GitLab for Jira Cloud app configuration
# flow has been completed for a group, which causes the integration to become activated/enabled.
override :editable?
def editable?
activated?
end
private
def validate_service_ids_limit
return unless jira_cloud_app_service_ids.present?
return unless jira_cloud_app_service_ids.split(',').size > SERVICE_IDS_LIMIT
errors.add(
:jira_cloud_app_service_ids,
format(
s_('JiraCloudApp|cannot have more than %{limit} service IDs'),
limit: SERVICE_IDS_LIMIT
)
)
end
def format_deployment_gating_environments
unformatted = jira_cloud_app_deployment_gating_environments
return if unformatted.nil?
self.jira_cloud_app_deployment_gating_environments = unformatted.split(',').map(&:strip).uniq.join(',')
end
def validate_deployment_gating_environments
return unless jira_cloud_app_deployment_gating_environments.present?
return if jira_cloud_app_deployment_gating_environments.split(',').all? do |env|
AVAILABLE_ENVRIONMENT_NAMES.include?(env)
end
errors.add(
:jira_cloud_app_deployment_gating_environments,
format(
s_('JiraCloudApp|only available environment names: %{names}'),
names: AVAILABLE_ENVRIONMENT_NAMES.join(',')
)
)
end
def validate_valid_deployment_gating_input
return unless jira_cloud_app_enable_deployment_gating
return if jira_cloud_app_deployment_gating_environments.present?
errors.add(
:jira_cloud_app_deployment_gating_environments,
format(
s_('JiraCloudApp|environment names should be provided if deployment gating has been enabled'))
)
end
end
end
|