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
Hide 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
# 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
...
...
app/models/integration.rb
View file @
ef88c430
...
@@ -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
...
...
app/models/integrations/jira.rb
View file @
ef88c430
...
@@ -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
...
...
app/models/integrations/teamcity.rb
View file @
ef88c430
...
@@ -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
...
...
app/serializers/service_event_entity.rb
View file @
ef88c430
...
@@ -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
...
...
lib/api/services.rb
View file @
ef88c430
...
@@ -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
...
...
locale/gitlab.pot
View file @
ef88c430
...
@@ -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 ""
...
...
spec/helpers/integrations_helper_spec.rb
View file @
ef88c430
...
@@ -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
[
[
...
...
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