2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
module ServicesHelper
|
|
|
|
def service_event_description(event)
|
|
|
|
case event
|
2017-08-17 22:00:37 +05:30
|
|
|
when "push", "push_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event for pushes to the repository.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "tag_push", "tag_push_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event for new tags pushed to the repository.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "note", "note_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event for new comments.")
|
2018-04-05 14:03:07 +05:30
|
|
|
when "confidential_note", "confidential_note_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event for new comments on confidential issues.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "issue", "issue_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when an issue is created, updated, or closed.")
|
2020-07-28 23:09:34 +05:30
|
|
|
when "confidential_issue", "confidential_issue_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a confidential issue is created, updated, or closed.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "merge_request", "merge_request_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a merge request is created, updated, or merged.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "pipeline", "pipeline_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a pipeline status changes.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "wiki_page", "wiki_page_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a wiki page is created or updated.")
|
2017-08-17 22:00:37 +05:30
|
|
|
when "commit", "commit_events"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a commit is created or updated.")
|
2020-07-28 23:09:34 +05:30
|
|
|
when "deployment"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a deployment starts or finishes.")
|
2020-07-28 23:09:34 +05:30
|
|
|
when "alert"
|
2021-04-29 21:17:54 +05:30
|
|
|
s_("ProjectService|Trigger event when a new, unique alert is recorded.")
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def service_event_field_name(event)
|
2016-09-29 09:46:39 +05:30
|
|
|
event = event.pluralize if %w[merge_request issue confidential_issue].include?(event)
|
2016-08-24 12:49:21 +05:30
|
|
|
"#{event}_events"
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def scoped_integrations_path
|
|
|
|
if @project.present?
|
|
|
|
project_settings_integrations_path(@project)
|
|
|
|
elsif @group.present?
|
|
|
|
group_settings_integrations_path(@group)
|
|
|
|
else
|
|
|
|
integrations_admin_application_settings_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def scoped_integration_path(integration)
|
|
|
|
if @project.present?
|
|
|
|
project_service_path(@project, integration)
|
|
|
|
elsif @group.present?
|
|
|
|
group_settings_integration_path(@group, integration)
|
|
|
|
else
|
|
|
|
admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def scoped_edit_integration_path(integration)
|
|
|
|
if @project.present?
|
2020-05-24 23:13:21 +05:30
|
|
|
edit_project_service_path(@project, integration)
|
2020-04-22 19:07:51 +05:30
|
|
|
elsif @group.present?
|
|
|
|
edit_group_settings_integration_path(@group, integration)
|
|
|
|
else
|
|
|
|
edit_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def scoped_test_integration_path(integration)
|
|
|
|
if @project.present?
|
2020-07-28 23:09:34 +05:30
|
|
|
test_project_service_path(@project, integration)
|
2020-04-22 19:07:51 +05:30
|
|
|
elsif @group.present?
|
|
|
|
test_group_settings_integration_path(@group, integration)
|
|
|
|
else
|
|
|
|
test_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def scoped_reset_integration_path(integration, group: nil)
|
2021-03-08 18:12:59 +05:30
|
|
|
return '' unless integration.persisted?
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
if group.present?
|
|
|
|
reset_group_settings_integration_path(group, integration)
|
|
|
|
else
|
|
|
|
reset_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def integration_form_data(integration, group: nil)
|
2021-04-29 21:17:54 +05:30
|
|
|
form_data = {
|
2020-07-28 23:09:34 +05:30
|
|
|
id: integration.id,
|
|
|
|
show_active: integration.show_active_box?.to_s,
|
|
|
|
activated: (integration.active || integration.new_record?).to_s,
|
|
|
|
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-11-24 15:15:51 +05:30
|
|
|
learn_more_path: integrations_help_page_path,
|
2020-07-28 23:09:34 +05:30
|
|
|
trigger_events: trigger_events_for_service(integration),
|
|
|
|
fields: fields_for_service(integration),
|
2020-11-24 15:15:51 +05:30
|
|
|
inherit_from_id: integration.inherit_from_id,
|
|
|
|
integration_level: integration_level(integration),
|
|
|
|
editable: integration.editable?.to_s,
|
|
|
|
cancel_path: scoped_integrations_path,
|
|
|
|
can_test: integration.can_test?.to_s,
|
2021-01-29 00:20:46 +05:30
|
|
|
test_path: scoped_test_integration_path(integration),
|
2021-03-08 18:12:59 +05:30
|
|
|
reset_path: scoped_reset_integration_path(integration, group: group)
|
2020-07-28 23:09:34 +05:30
|
|
|
}
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
if integration.is_a?(JiraService)
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
def integration_list_data(integrations)
|
|
|
|
{
|
|
|
|
integrations: integrations.map { |i| serialize_integration(i) }.to_json
|
|
|
|
}
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def trigger_events_for_service(integration)
|
|
|
|
ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def fields_for_service(integration)
|
|
|
|
ServiceFieldSerializer.new(service: integration).represent(integration.global_fields).to_json
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def integrations_help_page_path
|
|
|
|
help_page_path('user/admin_area/settings/project_integration_management')
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def project_jira_issues_integration?
|
|
|
|
false
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def instance_level_integrations?
|
|
|
|
!Gitlab.com?
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
def jira_issue_breadcrumb_link(issue_reference)
|
|
|
|
link_to '', { class: 'gl-display-flex gl-align-items-center gl-white-space-nowrap' } do
|
|
|
|
icon = image_tag image_path('illustrations/logos/jira.svg'), width: 15, height: 15, class: 'gl-mr-2'
|
|
|
|
[icon, issue_reference].join.html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
extend self
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def integration_level(integration)
|
2021-06-08 01:23:25 +05:30
|
|
|
if integration.instance_level?
|
2020-11-24 15:15:51 +05:30
|
|
|
'instance'
|
2021-06-08 01:23:25 +05:30
|
|
|
elsif integration.group_level?
|
2020-11-24 15:15:51 +05:30
|
|
|
'group'
|
|
|
|
else
|
|
|
|
'project'
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
def serialize_integration(integration)
|
|
|
|
{
|
|
|
|
active: integration.operating?,
|
|
|
|
title: integration.title,
|
|
|
|
description: integration.description,
|
|
|
|
updated_at: integration.updated_at,
|
|
|
|
edit_path: scoped_edit_integration_path(integration),
|
|
|
|
name: integration.to_param
|
|
|
|
}
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
def show_service_templates_nav_link?
|
|
|
|
Feature.disabled?(:disable_service_templates, type: :development, default_enabled: :yaml)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
ServicesHelper.prepend_mod_with('ServicesHelper')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
# The methods in `EE::ServicesHelper` should be available as both instance and
|
|
|
|
# class methods.
|
2021-06-08 01:23:25 +05:30
|
|
|
ServicesHelper.extend_mod_with('ServicesHelper')
|