2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-06-24 11:07:28 -04:00
|
|
|
module IntegrationsHelper
|
2022-02-27 19:18:02 -05:00
|
|
|
def integration_event_title(event)
|
|
|
|
case event
|
|
|
|
when "push", "push_events"
|
|
|
|
_("Push")
|
|
|
|
when "tag_push", "tag_push_events"
|
|
|
|
_("Tag push")
|
|
|
|
when "note", "note_events"
|
|
|
|
_("Note")
|
|
|
|
when "confidential_note", "confidential_note_events"
|
|
|
|
_("Confidential note")
|
|
|
|
when "issue", "issue_events"
|
|
|
|
_("Issue")
|
|
|
|
when "confidential_issue", "confidential_issue_events"
|
|
|
|
_("Confidential issue")
|
|
|
|
when "merge_request", "merge_request_events"
|
|
|
|
_("Merge request")
|
|
|
|
when "pipeline", "pipeline_events"
|
|
|
|
_("Pipeline")
|
|
|
|
when "wiki_page", "wiki_page_events"
|
|
|
|
_("Wiki page")
|
|
|
|
when "commit", "commit_events"
|
|
|
|
_("Commit")
|
|
|
|
when "deployment"
|
|
|
|
_("Deployment")
|
|
|
|
when "alert"
|
|
|
|
_("Alert")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 17:07:50 -04:00
|
|
|
def integration_event_description(integration, event)
|
|
|
|
case integration
|
|
|
|
when Integrations::Jira
|
|
|
|
jira_integration_event_description(event)
|
|
|
|
when Integrations::Teamcity
|
|
|
|
teamcity_integration_event_description(event)
|
|
|
|
else
|
|
|
|
default_integration_event_description(event)
|
2018-04-03 07:00:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-24 11:07:28 -04:00
|
|
|
def integration_event_field_name(event)
|
2016-08-30 17:39:25 -04:00
|
|
|
event = event.pluralize if %w[merge_request issue confidential_issue].include?(event)
|
2016-07-06 16:52:00 -04:00
|
|
|
"#{event}_events"
|
|
|
|
end
|
2017-01-12 17:33:04 -05:00
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def scoped_integrations_path(project: nil, group: nil)
|
|
|
|
if project.present?
|
|
|
|
project_settings_integrations_path(project)
|
|
|
|
elsif group.present?
|
|
|
|
group_settings_integrations_path(group)
|
2020-03-26 02:08:40 -04:00
|
|
|
else
|
|
|
|
integrations_admin_application_settings_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def scoped_integration_path(integration, project: nil, group: nil)
|
|
|
|
if project.present?
|
2022-05-25 14:08:15 -04:00
|
|
|
project_settings_integration_path(project, integration)
|
2021-12-06 16:10:14 -05:00
|
|
|
elsif group.present?
|
|
|
|
group_settings_integration_path(group, integration)
|
2020-03-26 02:08:40 -04:00
|
|
|
else
|
|
|
|
admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def scoped_edit_integration_path(integration, project: nil, group: nil)
|
|
|
|
if project.present?
|
2022-05-25 14:08:15 -04:00
|
|
|
edit_project_settings_integration_path(project, integration)
|
2021-12-06 16:10:14 -05:00
|
|
|
elsif group.present?
|
|
|
|
edit_group_settings_integration_path(group, integration)
|
2020-04-08 14:09:16 -04:00
|
|
|
else
|
|
|
|
edit_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-28 08:10:41 -04:00
|
|
|
def scoped_overrides_integration_path(integration, options = {})
|
|
|
|
overrides_admin_application_settings_integration_path(integration, options)
|
|
|
|
end
|
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def scoped_test_integration_path(integration, project: nil, group: nil)
|
|
|
|
if project.present?
|
2022-05-25 14:08:15 -04:00
|
|
|
test_project_settings_integration_path(project, integration)
|
2021-12-06 16:10:14 -05:00
|
|
|
elsif group.present?
|
|
|
|
test_group_settings_integration_path(group, integration)
|
2020-03-26 02:08:40 -04:00
|
|
|
else
|
|
|
|
test_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-02 19:09:53 -05:00
|
|
|
def scoped_reset_integration_path(integration, group: nil)
|
2021-01-15 01:10:42 -05:00
|
|
|
return '' unless integration.persisted?
|
|
|
|
|
2020-12-02 19:09:53 -05:00
|
|
|
if group.present?
|
|
|
|
reset_group_settings_integration_path(group, integration)
|
|
|
|
else
|
|
|
|
reset_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def integration_form_data(integration, project: nil, group: nil)
|
2021-03-29 17:09:08 -04:00
|
|
|
form_data = {
|
2020-07-16 23:09:14 -04:00
|
|
|
id: integration.id,
|
2020-06-19 17:08:32 -04:00
|
|
|
show_active: integration.show_active_box?.to_s,
|
2022-03-07 04:13:09 -05:00
|
|
|
activated: (integration.active || (integration.new_record? && integration.activate_disabled_reason.nil?)).to_s,
|
|
|
|
activate_disabled: integration.activate_disabled_reason.present?.to_s,
|
2020-06-19 17:08:32 -04:00
|
|
|
type: integration.to_param,
|
|
|
|
merge_request_events: integration.merge_requests_events.to_s,
|
|
|
|
commit_events: integration.commit_events.to_s,
|
|
|
|
enable_comments: integration.comment_on_event_enabled.to_s,
|
|
|
|
comment_detail: integration.comment_detail,
|
2020-08-24 23:10:50 -04:00
|
|
|
learn_more_path: integrations_help_page_path,
|
2022-05-12 02:07:53 -04:00
|
|
|
about_pricing_url: Gitlab::Saas.about_pricing_url,
|
2021-06-24 11:07:28 -04:00
|
|
|
trigger_events: trigger_events_for_integration(integration),
|
2022-02-18 10:15:51 -05:00
|
|
|
sections: integration.sections.to_json,
|
2021-06-24 11:07:28 -04:00
|
|
|
fields: fields_for_integration(integration),
|
2020-09-01 08:11:01 -04:00
|
|
|
inherit_from_id: integration.inherit_from_id,
|
2020-09-15 14:09:43 -04:00
|
|
|
integration_level: integration_level(integration),
|
|
|
|
editable: integration.editable?.to_s,
|
2021-12-06 16:10:14 -05:00
|
|
|
cancel_path: scoped_integrations_path(project: project, group: group),
|
2021-07-08 14:09:32 -04:00
|
|
|
can_test: integration.testable?.to_s,
|
2021-12-06 16:10:14 -05:00
|
|
|
test_path: scoped_test_integration_path(integration, project: project, group: group),
|
2022-01-19 13:14:01 -05:00
|
|
|
reset_path: scoped_reset_integration_path(integration, group: group),
|
|
|
|
form_path: scoped_integration_path(integration, project: project, group: group),
|
|
|
|
redirect_to: request.referer
|
2020-06-19 17:08:32 -04:00
|
|
|
}
|
2021-03-29 17:09:08 -04:00
|
|
|
|
2021-05-21 20:10:27 -04:00
|
|
|
if integration.is_a?(Integrations::Jira)
|
2021-03-29 17:09:08 -04:00
|
|
|
form_data[:jira_issue_transition_automatic] = integration.jira_issue_transition_automatic
|
|
|
|
form_data[:jira_issue_transition_id] = integration.jira_issue_transition_id
|
|
|
|
end
|
|
|
|
|
|
|
|
form_data
|
2020-06-19 17:08:32 -04:00
|
|
|
end
|
|
|
|
|
2021-12-21 01:13:16 -05:00
|
|
|
def integration_overrides_data(integration, project: nil, group: nil)
|
2021-07-28 08:10:41 -04:00
|
|
|
{
|
2021-12-21 01:13:16 -05:00
|
|
|
edit_path: scoped_edit_integration_path(integration, project: project, group: group),
|
2021-07-28 08:10:41 -04:00
|
|
|
overrides_path: scoped_overrides_integration_path(integration, format: :json)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def integration_list_data(integrations, group: nil, project: nil)
|
2021-04-14 14:09:18 -04:00
|
|
|
{
|
2021-12-06 16:10:14 -05:00
|
|
|
integrations: integrations.map { |i| serialize_integration(i, group: group, project: project) }.to_json
|
2021-04-14 14:09:18 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-08-24 23:10:50 -04:00
|
|
|
def integrations_help_page_path
|
|
|
|
help_page_path('user/admin_area/settings/project_integration_management')
|
|
|
|
end
|
|
|
|
|
2020-07-07 08:09:16 -04:00
|
|
|
def project_jira_issues_integration?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2020-09-25 17:09:51 -04:00
|
|
|
def instance_level_integrations?
|
|
|
|
!Gitlab.com?
|
|
|
|
end
|
|
|
|
|
2017-01-12 17:33:04 -05:00
|
|
|
extend self
|
2020-09-01 08:11:01 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-07-06 17:07:50 -04:00
|
|
|
def jira_integration_event_description(event)
|
|
|
|
case event
|
|
|
|
when "merge_request", "merge_request_events"
|
|
|
|
s_("JiraService|Jira comments are created when an issue is referenced in a merge request.")
|
|
|
|
when "commit", "commit_events"
|
|
|
|
s_("JiraService|Jira comments are created when an issue is referenced in a commit.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def teamcity_integration_event_description(event)
|
|
|
|
case event
|
|
|
|
when 'push', 'push_events'
|
|
|
|
s_('TeamcityIntegration|Trigger TeamCity CI after every push to the repository, except branch delete')
|
|
|
|
when 'merge_request', 'merge_request_events'
|
|
|
|
s_('TeamcityIntegration|Trigger TeamCity CI after a merge request has been created or updated')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_integration_event_description(event)
|
|
|
|
case event
|
|
|
|
when "push", "push_events"
|
|
|
|
s_("ProjectService|Trigger event for pushes to the repository.")
|
|
|
|
when "tag_push", "tag_push_events"
|
|
|
|
s_("ProjectService|Trigger event for new tags pushed to the repository.")
|
|
|
|
when "note", "note_events"
|
|
|
|
s_("ProjectService|Trigger event for new comments.")
|
|
|
|
when "confidential_note", "confidential_note_events"
|
|
|
|
s_("ProjectService|Trigger event for new comments on confidential issues.")
|
|
|
|
when "issue", "issue_events"
|
|
|
|
s_("ProjectService|Trigger event when an issue is created, updated, or closed.")
|
|
|
|
when "confidential_issue", "confidential_issue_events"
|
|
|
|
s_("ProjectService|Trigger event when a confidential issue is created, updated, or closed.")
|
|
|
|
when "merge_request", "merge_request_events"
|
|
|
|
s_("ProjectService|Trigger event when a merge request is created, updated, or merged.")
|
|
|
|
when "pipeline", "pipeline_events"
|
|
|
|
s_("ProjectService|Trigger event when a pipeline status changes.")
|
|
|
|
when "wiki_page", "wiki_page_events"
|
|
|
|
s_("ProjectService|Trigger event when a wiki page is created or updated.")
|
|
|
|
when "commit", "commit_events"
|
|
|
|
s_("ProjectService|Trigger event when a commit is created or updated.")
|
|
|
|
when "deployment"
|
|
|
|
s_("ProjectService|Trigger event when a deployment starts or finishes.")
|
|
|
|
when "alert"
|
|
|
|
s_("ProjectService|Trigger event when a new, unique alert is recorded.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-24 11:07:28 -04:00
|
|
|
def trigger_events_for_integration(integration)
|
2022-06-10 08:09:36 -04:00
|
|
|
Integrations::EventSerializer.new(integration: integration).represent(integration.configurable_events).to_json
|
2021-06-24 11:07:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def fields_for_integration(integration)
|
2022-07-01 14:08:33 -04:00
|
|
|
Integrations::FieldSerializer.new(integration: integration).represent(integration.form_fields).to_json
|
2021-06-24 11:07:28 -04:00
|
|
|
end
|
|
|
|
|
2020-09-01 08:11:01 -04:00
|
|
|
def integration_level(integration)
|
2021-04-26 05:09:53 -04:00
|
|
|
if integration.instance_level?
|
2020-09-01 08:11:01 -04:00
|
|
|
'instance'
|
2021-04-26 05:09:53 -04:00
|
|
|
elsif integration.group_level?
|
2020-09-01 08:11:01 -04:00
|
|
|
'group'
|
|
|
|
else
|
|
|
|
'project'
|
|
|
|
end
|
|
|
|
end
|
2021-04-14 14:09:18 -04:00
|
|
|
|
2021-12-06 16:10:14 -05:00
|
|
|
def serialize_integration(integration, group: nil, project: nil)
|
2021-04-14 14:09:18 -04:00
|
|
|
{
|
|
|
|
active: integration.operating?,
|
|
|
|
title: integration.title,
|
|
|
|
description: integration.description,
|
|
|
|
updated_at: integration.updated_at,
|
2021-12-06 16:10:14 -05:00
|
|
|
edit_path: scoped_edit_integration_path(integration, group: group, project: project),
|
2021-04-14 14:09:18 -04:00
|
|
|
name: integration.to_param
|
|
|
|
}
|
|
|
|
end
|
2016-07-06 16:52:00 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-06-24 11:07:28 -04:00
|
|
|
IntegrationsHelper.prepend_mod_with('IntegrationsHelper')
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-06-24 11:07:28 -04:00
|
|
|
# The methods in `EE::IntegrationsHelper` should be available as both instance and
|
2019-09-13 09:26:31 -04:00
|
|
|
# class methods.
|
2021-06-24 11:07:28 -04:00
|
|
|
IntegrationsHelper.extend_mod_with('IntegrationsHelper')
|