Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ef88c430
Commit
ef88c430
authored
Jul 06, 2021
by
Luke Duncalfe
Committed by
Robert Speicher
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor a SSOT for integration event descriptions
parent
bf1e288a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
82 additions
and
53 deletions
+82
-53
app/helpers/integrations_helper.rb
app/helpers/integrations_helper.rb
+55
-26
app/models/integration.rb
app/models/integration.rb
+0
-4
app/models/integrations/jira.rb
app/models/integrations/jira.rb
+0
-9
app/models/integrations/teamcity.rb
app/models/integrations/teamcity.rb
+0
-9
app/serializers/service_event_entity.rb
app/serializers/service_event_entity.rb
+1
-1
lib/api/services.rb
lib/api/services.rb
+4
-4
locale/gitlab.pot
locale/gitlab.pot
+6
-0
spec/helpers/integrations_helper_spec.rb
spec/helpers/integrations_helper_spec.rb
+16
-0
No files found.
app/helpers/integrations_helper.rb
View file @
ef88c430
# 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
...
...
app/models/integration.rb
View file @
ef88c430
...
...
@@ -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
...
...
app/models/integrations/jira.rb
View file @
ef88c430
...
...
@@ -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
...
...
app/models/integrations/teamcity.rb
View file @
ef88c430
...
...
@@ -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
...
...
app/serializers/service_event_entity.rb
View file @
ef88c430
...
...
@@ -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
...
...
lib/api/services.rb
View file @
ef88c430
...
...
@@ -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
...
...
locale/gitlab.pot
View file @
ef88c430
...
...
@@ -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 ""
...
...
spec/helpers/integrations_helper_spec.rb
View file @
ef88c430
...
...
@@ -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
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment