debian-mirror-gitlab/app/helpers/services_helper.rb

148 lines
5 KiB
Ruby
Raw Normal View History

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"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered by a push to the repository")
2017-08-17 22:00:37 +05:30
when "tag_push", "tag_push_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when a new tag is pushed to the repository")
2017-08-17 22:00:37 +05:30
when "note", "note_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when someone adds a comment")
2018-04-05 14:03:07 +05:30
when "confidential_note", "confidential_note_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when someone adds a comment on a confidential issue")
2017-08-17 22:00:37 +05:30
when "issue", "issue_events"
2020-07-28 23:09:34 +05:30
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")
2017-08-17 22:00:37 +05:30
when "merge_request", "merge_request_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when a merge request is created/updated/merged")
2017-08-17 22:00:37 +05:30
when "pipeline", "pipeline_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when a pipeline status changes")
2017-08-17 22:00:37 +05:30
when "wiki_page", "wiki_page_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when a wiki page is created/updated")
2017-08-17 22:00:37 +05:30
when "commit", "commit_events"
2020-07-28 23:09:34 +05:30
s_("ProjectService|Event will be triggered when a commit is created/updated")
when "deployment"
s_("ProjectService|Event will be triggered when a deployment finishes")
when "alert"
s_("ProjectService|Event will be triggered 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-01-01 13:55:28 +05:30
def service_event_action_field_name(action)
"#{action}_on_event_enabled"
end
def event_action_title(action)
case action
when "comment"
s_("ProjectService|Comment")
else
action.humanize
end
end
2020-07-28 23:09:34 +05:30
def service_save_button(disabled: false)
button_tag(class: 'btn btn-success', type: 'submit', disabled: disabled, data: { qa_selector: 'save_changes_button' }) do
2018-03-17 18:26:18 +05:30
icon('spinner spin', class: 'hidden js-btn-spinner') +
content_tag(:span, 'Save changes', class: 'js-btn-label')
end
end
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
2020-06-23 00:09:42 +05:30
def integration_form_refactor?
2020-07-28 23:09:34 +05:30
Feature.enabled?(:integration_form_refactor, @project, default_enabled: true)
2020-06-23 00:09:42 +05:30
end
2020-07-28 23:09:34 +05:30
def integration_form_data(integration)
{
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,
trigger_events: trigger_events_for_service(integration),
fields: fields_for_service(integration),
inherit_from_id: integration.inherit_from_id
}
end
def trigger_events_for_service(integration)
2020-06-23 00:09:42 +05:30
return [] unless integration_form_refactor?
2020-07-28 23:09:34 +05:30
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)
2020-06-23 00:09:42 +05:30
return [] unless integration_form_refactor?
2020-07-28 23:09:34 +05:30
ServiceFieldSerializer.new(service: integration).represent(integration.global_fields).to_json
2020-06-23 00:09:42 +05:30
end
2020-07-28 23:09:34 +05:30
def show_service_trigger_events?(integration)
return false if integration.is_a?(JiraService) || integration_form_refactor?
integration.configurable_events.present?
end
2020-06-23 00:09:42 +05:30
2020-07-28 23:09:34 +05:30
def project_jira_issues_integration?
false
2020-06-23 00:09:42 +05:30
end
2017-08-17 22:00:37 +05:30
extend self
2016-08-24 12:49:21 +05:30
end
2019-12-04 20:38:33 +05:30
2020-05-24 23:13:21 +05:30
ServicesHelper.prepend_if_ee('EE::ServicesHelper')
2019-12-04 20:38:33 +05:30
# The methods in `EE::ServicesHelper` should be available as both instance and
# class methods.
ServicesHelper.extend_if_ee('EE::ServicesHelper')