2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-06 16:52:00 -04:00
|
|
|
module ServicesHelper
|
2018-04-03 07:00:33 -04:00
|
|
|
def service_event_description(event)
|
|
|
|
case event
|
|
|
|
when "push", "push_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered by a push to the repository")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "tag_push", "tag_push_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when a new tag is pushed to the repository")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "note", "note_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when someone adds a comment")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "confidential_note", "confidential_note_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when someone adds a comment on a confidential issue")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "issue", "issue_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when an issue is created/updated/closed")
|
|
|
|
when "confidential_issue", "confidential_issue_events"
|
|
|
|
s_("ProjectService|Event will be triggered when a confidential issue is created/updated/closed")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "merge_request", "merge_request_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when a merge request is created/updated/merged")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "pipeline", "pipeline_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when a pipeline status changes")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "wiki_page", "wiki_page_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when a wiki page is created/updated")
|
2018-04-03 07:00:33 -04:00
|
|
|
when "commit", "commit_events"
|
2020-06-21 17:08:34 -04:00
|
|
|
s_("ProjectService|Event will be triggered when a commit is created/updated")
|
|
|
|
when "deployment"
|
2020-10-05 02:08:45 -04:00
|
|
|
s_("ProjectService|Event will be triggered when a deployment starts or finishes")
|
2020-06-21 17:08:34 -04:00
|
|
|
when "alert"
|
|
|
|
s_("ProjectService|Event will be triggered when a new, unique alert is recorded")
|
2018-04-03 07:00:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-06 16:52:00 -04:00
|
|
|
def service_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
|
|
|
|
2020-03-26 02:08:40 -04:00
|
|
|
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?
|
2020-04-15 11:09:17 -04:00
|
|
|
project_service_path(@project, integration)
|
2020-03-26 02:08:40 -04:00
|
|
|
elsif @group.present?
|
|
|
|
group_settings_integration_path(@group, integration)
|
|
|
|
else
|
|
|
|
admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:09:16 -04:00
|
|
|
def scoped_edit_integration_path(integration)
|
|
|
|
if @project.present?
|
2020-05-06 20:11:11 -04:00
|
|
|
edit_project_service_path(@project, integration)
|
2020-04-08 14:09:16 -04:00
|
|
|
elsif @group.present?
|
|
|
|
edit_group_settings_integration_path(@group, integration)
|
|
|
|
else
|
|
|
|
edit_admin_application_settings_integration_path(integration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-26 02:08:40 -04:00
|
|
|
def scoped_test_integration_path(integration)
|
|
|
|
if @project.present?
|
2020-06-19 17:08:32 -04:00
|
|
|
test_project_service_path(@project, integration)
|
2020-03-26 02:08:40 -04:00
|
|
|
elsif @group.present?
|
|
|
|
test_group_settings_integration_path(@group, integration)
|
|
|
|
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
|
|
|
|
|
|
|
|
def integration_form_data(integration, group: nil)
|
2020-06-19 17:08:32 -04:00
|
|
|
{
|
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,
|
|
|
|
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-08-24 23:10:50 -04:00
|
|
|
learn_more_path: integrations_help_page_path,
|
2020-06-19 17:08:32 -04:00
|
|
|
trigger_events: trigger_events_for_service(integration),
|
2020-07-16 23:09:14 -04:00
|
|
|
fields: fields_for_service(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,
|
|
|
|
cancel_path: scoped_integrations_path,
|
|
|
|
can_test: integration.can_test?.to_s,
|
2020-11-16 10:09:23 -05:00
|
|
|
test_path: scoped_test_integration_path(integration),
|
2021-01-15 01:10:42 -05:00
|
|
|
reset_path: scoped_reset_integration_path(integration, group: group)
|
2020-06-19 17:08:32 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger_events_for_service(integration)
|
|
|
|
ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json
|
2020-06-03 05:08:47 -04:00
|
|
|
end
|
|
|
|
|
2020-06-19 17:08:32 -04:00
|
|
|
def fields_for_service(integration)
|
|
|
|
ServiceFieldSerializer.new(service: integration).represent(integration.global_fields).to_json
|
2020-06-03 05:08:47 -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
|
|
|
|
|
|
|
|
def integration_level(integration)
|
|
|
|
if integration.instance
|
|
|
|
'instance'
|
|
|
|
elsif integration.group_id
|
|
|
|
'group'
|
|
|
|
else
|
|
|
|
'project'
|
|
|
|
end
|
|
|
|
end
|
2016-07-06 16:52:00 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2020-05-12 11:10:33 -04:00
|
|
|
ServicesHelper.prepend_if_ee('EE::ServicesHelper')
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
# The methods in `EE::ServicesHelper` should be available as both instance and
|
|
|
|
# class methods.
|
|
|
|
ServicesHelper.extend_if_ee('EE::ServicesHelper')
|