Commit ef88c430 authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Robert Speicher

Refactor a SSOT for integration event descriptions

parent bf1e288a
# frozen_string_literal: true
module IntegrationsHelper
def 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.")
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)
end
end
......@@ -144,6 +126,53 @@ module IntegrationsHelper
private
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
def trigger_events_for_integration(integration)
ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json
end
......
......@@ -172,10 +172,6 @@ class Integration < ApplicationRecord
'push'
end
def self.event_description(event)
IntegrationsHelper.integration_event_description(event)
end
def self.find_or_create_templates
create_nonexistent_templates
for_template
......
......@@ -577,15 +577,6 @@ module Integrations
data_fields.deployment_server!
end
end
def self.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
end
end
......
......@@ -29,15 +29,6 @@ module Integrations
def supported_events
%w(push merge_request)
end
def event_description(event)
case event
when 'push', 'push_events'
'TeamCity CI will be triggered after every push to the repository except branch delete'
when 'merge_request', 'merge_request_events'
'TeamCity CI will be triggered after a merge request has been created or updated'
end
end
end
def compose_service_hook
......
......@@ -14,7 +14,7 @@ class ServiceEventEntity < Grape::Entity
end
expose :description do |event|
IntegrationsHelper.integration_event_description(event)
IntegrationsHelper.integration_event_description(integration, event)
end
expose :field, if: -> (_, _) { event_field } do
......
......@@ -23,14 +23,14 @@ module API
INTEGRATIONS = integrations.freeze
integration_classes.each do |service|
event_names = service.try(:event_names) || next
integration_classes.each do |integration|
event_names = integration.try(:event_names) || next
event_names.each do |event_name|
INTEGRATIONS[service.to_param.tr("_", "-")] << {
INTEGRATIONS[integration.to_param.tr("_", "-")] << {
required: false,
name: event_name.to_sym,
type: String,
desc: service.event_description(event_name)
desc: IntegrationsHelper.integration_event_description(integration, event_name)
}
end
end
......
......@@ -31878,6 +31878,12 @@ msgstr ""
msgid "Team domain"
msgstr ""
msgid "TeamcityIntegration|Trigger TeamCity CI after a merge request has been created or updated"
msgstr ""
msgid "TeamcityIntegration|Trigger TeamCity CI after every push to the repository, except branch delete"
msgstr ""
msgid "Telephone number"
msgstr ""
......
......@@ -3,6 +3,22 @@
require 'spec_helper'
RSpec.describe IntegrationsHelper do
describe '#integration_event_description' do
subject(:description) { helper.integration_event_description(integration, 'merge_request_events') }
context 'when integration is Jira' do
let(:integration) { Integrations::Jira.new }
it { is_expected.to include('Jira') }
end
context 'when integration is Team City' do
let(:integration) { Integrations::Teamcity.new }
it { is_expected.to include('TeamCity') }
end
end
describe '#integration_form_data' do
let(:fields) do
[
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment