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 # frozen_string_literal: true
module IntegrationsHelper module IntegrationsHelper
def integration_event_description(event) def integration_event_description(integration, event)
case event case integration
when "push", "push_events" when Integrations::Jira
s_("ProjectService|Trigger event for pushes to the repository.") jira_integration_event_description(event)
when "tag_push", "tag_push_events" when Integrations::Teamcity
s_("ProjectService|Trigger event for new tags pushed to the repository.") teamcity_integration_event_description(event)
when "note", "note_events" else
s_("ProjectService|Trigger event for new comments.") default_integration_event_description(event)
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
end end
...@@ -144,6 +126,53 @@ module IntegrationsHelper ...@@ -144,6 +126,53 @@ module IntegrationsHelper
private 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) def trigger_events_for_integration(integration)
ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json ServiceEventSerializer.new(service: integration).represent(integration.configurable_events).to_json
end end
......
...@@ -172,10 +172,6 @@ class Integration < ApplicationRecord ...@@ -172,10 +172,6 @@ class Integration < ApplicationRecord
'push' 'push'
end end
def self.event_description(event)
IntegrationsHelper.integration_event_description(event)
end
def self.find_or_create_templates def self.find_or_create_templates
create_nonexistent_templates create_nonexistent_templates
for_template for_template
......
...@@ -577,15 +577,6 @@ module Integrations ...@@ -577,15 +577,6 @@ module Integrations
data_fields.deployment_server! data_fields.deployment_server!
end end
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
end end
......
...@@ -29,15 +29,6 @@ module Integrations ...@@ -29,15 +29,6 @@ module Integrations
def supported_events def supported_events
%w(push merge_request) %w(push merge_request)
end 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 end
def compose_service_hook def compose_service_hook
......
...@@ -14,7 +14,7 @@ class ServiceEventEntity < Grape::Entity ...@@ -14,7 +14,7 @@ class ServiceEventEntity < Grape::Entity
end end
expose :description do |event| expose :description do |event|
IntegrationsHelper.integration_event_description(event) IntegrationsHelper.integration_event_description(integration, event)
end end
expose :field, if: -> (_, _) { event_field } do expose :field, if: -> (_, _) { event_field } do
......
...@@ -23,14 +23,14 @@ module API ...@@ -23,14 +23,14 @@ module API
INTEGRATIONS = integrations.freeze INTEGRATIONS = integrations.freeze
integration_classes.each do |service| integration_classes.each do |integration|
event_names = service.try(:event_names) || next event_names = integration.try(:event_names) || next
event_names.each do |event_name| event_names.each do |event_name|
INTEGRATIONS[service.to_param.tr("_", "-")] << { INTEGRATIONS[integration.to_param.tr("_", "-")] << {
required: false, required: false,
name: event_name.to_sym, name: event_name.to_sym,
type: String, type: String,
desc: service.event_description(event_name) desc: IntegrationsHelper.integration_event_description(integration, event_name)
} }
end end
end end
......
...@@ -31878,6 +31878,12 @@ msgstr "" ...@@ -31878,6 +31878,12 @@ msgstr ""
msgid "Team domain" msgid "Team domain"
msgstr "" 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" msgid "Telephone number"
msgstr "" msgstr ""
......
...@@ -3,6 +3,22 @@ ...@@ -3,6 +3,22 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe IntegrationsHelper do 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 describe '#integration_form_data' do
let(:fields) 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