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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
cd51af1a
Commit
cd51af1a
authored
Dec 27, 2016
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds events to services api deserialization
parent
4b7ec44b
Changes
37
Show whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
259 additions
and
66 deletions
+259
-66
app/helpers/services_helper.rb
app/helpers/services_helper.rb
+9
-9
app/models/project_services/asana_service.rb
app/models/project_services/asana_service.rb
+6
-2
app/models/project_services/assembla_service.rb
app/models/project_services/assembla_service.rb
+6
-2
app/models/project_services/bamboo_service.rb
app/models/project_services/bamboo_service.rb
+2
-2
app/models/project_services/bugzilla_service.rb
app/models/project_services/bugzilla_service.rb
+9
-1
app/models/project_services/buildkite_service.rb
app/models/project_services/buildkite_service.rb
+6
-2
app/models/project_services/builds_email_service.rb
app/models/project_services/builds_email_service.rb
+6
-2
app/models/project_services/campfire_service.rb
app/models/project_services/campfire_service.rb
+6
-2
app/models/project_services/chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+1
-1
app/models/project_services/chat_slash_commands_service.rb
app/models/project_services/chat_slash_commands_service.rb
+2
-2
app/models/project_services/ci_service.rb
app/models/project_services/ci_service.rb
+4
-1
app/models/project_services/custom_issue_tracker_service.rb
app/models/project_services/custom_issue_tracker_service.rb
+9
-1
app/models/project_services/deployment_service.rb
app/models/project_services/deployment_service.rb
+2
-2
app/models/project_services/drone_ci_service.rb
app/models/project_services/drone_ci_service.rb
+2
-2
app/models/project_services/emails_on_push_service.rb
app/models/project_services/emails_on_push_service.rb
+6
-2
app/models/project_services/external_wiki_service.rb
app/models/project_services/external_wiki_service.rb
+9
-1
app/models/project_services/flowdock_service.rb
app/models/project_services/flowdock_service.rb
+6
-2
app/models/project_services/gemnasium_service.rb
app/models/project_services/gemnasium_service.rb
+6
-2
app/models/project_services/gitlab_issue_tracker_service.rb
app/models/project_services/gitlab_issue_tracker_service.rb
+1
-1
app/models/project_services/hipchat_service.rb
app/models/project_services/hipchat_service.rb
+6
-2
app/models/project_services/irker_service.rb
app/models/project_services/irker_service.rb
+6
-2
app/models/project_services/issue_tracker_service.rb
app/models/project_services/issue_tracker_service.rb
+1
-1
app/models/project_services/jira_service.rb
app/models/project_services/jira_service.rb
+6
-2
app/models/project_services/kubernetes_service.rb
app/models/project_services/kubernetes_service.rb
+9
-1
app/models/project_services/mattermost_service.rb
app/models/project_services/mattermost_service.rb
+9
-1
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+9
-1
app/models/project_services/pipelines_email_service.rb
app/models/project_services/pipelines_email_service.rb
+6
-2
app/models/project_services/pivotaltracker_service.rb
app/models/project_services/pivotaltracker_service.rb
+6
-2
app/models/project_services/pushover_service.rb
app/models/project_services/pushover_service.rb
+6
-2
app/models/project_services/redmine_service.rb
app/models/project_services/redmine_service.rb
+9
-1
app/models/project_services/slack_service.rb
app/models/project_services/slack_service.rb
+9
-1
app/models/project_services/slack_slash_commands_service.rb
app/models/project_services/slack_slash_commands_service.rb
+9
-1
app/models/project_services/teamcity_service.rb
app/models/project_services/teamcity_service.rb
+6
-2
app/models/service.rb
app/models/service.rb
+4
-2
changelogs/unreleased/22974-trigger-service-events-through-api.yml
...s/unreleased/22974-trigger-service-events-through-api.yml
+4
-0
lib/api/services.rb
lib/api/services.rb
+46
-3
spec/requests/api/services_spec.rb
spec/requests/api/services_spec.rb
+10
-1
No files found.
app/helpers/services_helper.rb
View file @
cd51af1a
module
ServicesHelper
module
ServicesHelper
def
service_event_description
(
event
)
def
service_event_description
(
event
)
case
event
case
event
when
"push"
when
"push"
,
"push_events"
"Event will be triggered by a push to the repository"
"Event will be triggered by a push to the repository"
when
"tag_push"
when
"tag_push"
,
"tag_push_events"
"Event will be triggered when a new tag is pushed to the repository"
"Event will be triggered when a new tag is pushed to the repository"
when
"note"
when
"note"
,
"note_events"
"Event will be triggered when someone adds a comment"
"Event will be triggered when someone adds a comment"
when
"issue"
when
"issue"
,
"issue_events"
"Event will be triggered when an issue is created/updated/closed"
"Event will be triggered when an issue is created/updated/closed"
when
"confidential_issue"
when
"confidential_issue"
,
"confidential_issue_events"
"Event will be triggered when a confidential issue is created/updated/closed"
"Event will be triggered when a confidential issue is created/updated/closed"
when
"merge_request"
when
"merge_request"
,
"merge_request_events"
"Event will be triggered when a merge request is created/updated/merged"
"Event will be triggered when a merge request is created/updated/merged"
when
"build"
when
"build"
,
"build_events"
"Event will be triggered when a build status changes"
"Event will be triggered when a build status changes"
when
"wiki_page"
when
"wiki_page"
,
"wiki_page_events"
"Event will be triggered when a wiki page is created/updated"
"Event will be triggered when a wiki page is created/updated"
when
"commit"
when
"commit"
,
"commit_events"
"Event will be triggered when a commit is created/updated"
"Event will be triggered when a commit is created/updated"
end
end
end
end
...
...
app/models/project_services/asana_service.rb
View file @
cd51af1a
...
@@ -25,7 +25,7 @@ You can create a Personal Access Token here:
...
@@ -25,7 +25,7 @@ You can create a Personal Access Token here:
http://app.asana.com/-/account_api'
http://app.asana.com/-/account_api'
end
end
def
to_param
def
self
.
to_param
'asana'
'asana'
end
end
...
@@ -44,10 +44,14 @@ http://app.asana.com/-/account_api'
...
@@ -44,10 +44,14 @@ http://app.asana.com/-/account_api'
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
client
def
client
@_client
||=
begin
@_client
||=
begin
Asana
::
Client
.
new
do
|
c
|
Asana
::
Client
.
new
do
|
c
|
...
...
app/models/project_services/assembla_service.rb
View file @
cd51af1a
...
@@ -12,7 +12,7 @@ class AssemblaService < Service
...
@@ -12,7 +12,7 @@ class AssemblaService < Service
'Project Management Software (Source Commits Endpoint)'
'Project Management Software (Source Commits Endpoint)'
end
end
def
to_param
def
self
.
to_param
'assembla'
'assembla'
end
end
...
@@ -23,10 +23,14 @@ class AssemblaService < Service
...
@@ -23,10 +23,14 @@ class AssemblaService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
app/models/project_services/bamboo_service.rb
View file @
cd51af1a
...
@@ -40,7 +40,7 @@ class BambooService < CiService
...
@@ -40,7 +40,7 @@ class BambooService < CiService
'You must set up automatic revision labeling and a repository trigger in Bamboo.'
'You must set up automatic revision labeling and a repository trigger in Bamboo.'
end
end
def
to_param
def
self
.
to_param
'bamboo'
'bamboo'
end
end
...
@@ -56,7 +56,7 @@ class BambooService < CiService
...
@@ -56,7 +56,7 @@ class BambooService < CiService
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
...
...
app/models/project_services/bugzilla_service.rb
View file @
cd51af1a
...
@@ -19,7 +19,15 @@ class BugzillaService < IssueTrackerService
...
@@ -19,7 +19,15 @@ class BugzillaService < IssueTrackerService
end
end
end
end
def
to_param
def
self
.
to_param
'bugzilla'
'bugzilla'
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/buildkite_service.rb
View file @
cd51af1a
...
@@ -24,10 +24,14 @@ class BuildkiteService < CiService
...
@@ -24,10 +24,14 @@ class BuildkiteService < CiService
hook
.
save
hook
.
save
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
@@ -54,7 +58,7 @@ class BuildkiteService < CiService
...
@@ -54,7 +58,7 @@ class BuildkiteService < CiService
'Continuous integration and deployments'
'Continuous integration and deployments'
end
end
def
to_param
def
self
.
to_param
'buildkite'
'buildkite'
end
end
...
...
app/models/project_services/builds_email_service.rb
View file @
cd51af1a
...
@@ -19,14 +19,18 @@ class BuildsEmailService < Service
...
@@ -19,14 +19,18 @@ class BuildsEmailService < Service
'Email the builds status to a list of recipients.'
'Email the builds status to a list of recipients.'
end
end
def
to_param
def
self
.
to_param
'builds_email'
'builds_email'
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(build)
%w(build)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
push_data
)
def
execute
(
push_data
)
return
unless
supported_events
.
include?
(
push_data
[
:object_kind
])
return
unless
supported_events
.
include?
(
push_data
[
:object_kind
])
return
unless
should_build_be_notified?
(
push_data
)
return
unless
should_build_be_notified?
(
push_data
)
...
...
app/models/project_services/campfire_service.rb
View file @
cd51af1a
...
@@ -12,7 +12,7 @@ class CampfireService < Service
...
@@ -12,7 +12,7 @@ class CampfireService < Service
'Simple web-based real-time group chat'
'Simple web-based real-time group chat'
end
end
def
to_param
def
self
.
to_param
'campfire'
'campfire'
end
end
...
@@ -24,10 +24,14 @@ class CampfireService < Service
...
@@ -24,10 +24,14 @@ class CampfireService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
app/models/project_services/chat_notification_service.rb
View file @
cd51af1a
...
@@ -25,7 +25,7 @@ class ChatNotificationService < Service
...
@@ -25,7 +25,7 @@ class ChatNotificationService < Service
valid?
valid?
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w[push issue confidential_issue merge_request note tag_push
%w[push issue confidential_issue merge_request note tag_push
build pipeline wiki_page]
build pipeline wiki_page]
end
end
...
...
app/models/project_services/chat_slash_commands_service.rb
View file @
cd51af1a
...
@@ -13,8 +13,8 @@ class ChatSlashCommandsService < Service
...
@@ -13,8 +13,8 @@ class ChatSlashCommandsService < Service
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
end
end
def
supported_events
def
s
elf
.
s
upported_events
[]
%w()
end
end
def
can_test?
def
can_test?
...
...
app/models/project_services/ci_service.rb
View file @
cd51af1a
...
@@ -8,10 +8,13 @@ class CiService < Service
...
@@ -8,10 +8,13 @@ class CiService < Service
self
.
respond_to?
(
:token
)
&&
self
.
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
self
.
respond_to?
(
:token
)
&&
self
.
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
# Return complete url to build page
# Return complete url to build page
#
#
# Ex.
# Ex.
...
...
app/models/project_services/custom_issue_tracker_service.rb
View file @
cd51af1a
...
@@ -23,7 +23,7 @@ class CustomIssueTrackerService < IssueTrackerService
...
@@ -23,7 +23,7 @@ class CustomIssueTrackerService < IssueTrackerService
end
end
end
end
def
to_param
def
self
.
to_param
'custom_issue_tracker'
'custom_issue_tracker'
end
end
...
@@ -36,4 +36,12 @@ class CustomIssueTrackerService < IssueTrackerService
...
@@ -36,4 +36,12 @@ class CustomIssueTrackerService < IssueTrackerService
{
type:
'text'
,
name:
'new_issue_url'
,
placeholder:
'New Issue url'
}
{
type:
'text'
,
name:
'new_issue_url'
,
placeholder:
'New Issue url'
}
]
]
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/deployment_service.rb
View file @
cd51af1a
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
class
DeploymentService
<
Service
class
DeploymentService
<
Service
default_value_for
:category
,
'deployment'
default_value_for
:category
,
'deployment'
def
supported_events
def
s
elf
.
s
upported_events
[]
%w()
end
end
def
predefined_variables
def
predefined_variables
...
...
app/models/project_services/drone_ci_service.rb
View file @
cd51af1a
...
@@ -32,7 +32,7 @@ class DroneCiService < CiService
...
@@ -32,7 +32,7 @@ class DroneCiService < CiService
true
true
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push merge_request tag_push)
%w(push merge_request tag_push)
end
end
...
@@ -87,7 +87,7 @@ class DroneCiService < CiService
...
@@ -87,7 +87,7 @@ class DroneCiService < CiService
'Drone is a Continuous Integration platform built on Docker, written in Go'
'Drone is a Continuous Integration platform built on Docker, written in Go'
end
end
def
to_param
def
self
.
to_param
'drone_ci'
'drone_ci'
end
end
...
...
app/models/project_services/emails_on_push_service.rb
View file @
cd51af1a
...
@@ -12,14 +12,18 @@ class EmailsOnPushService < Service
...
@@ -12,14 +12,18 @@ class EmailsOnPushService < Service
'Email the commits and diff of each push to a list of recipients.'
'Email the commits and diff of each push to a list of recipients.'
end
end
def
to_param
def
self
.
to_param
'emails_on_push'
'emails_on_push'
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push tag_push)
%w(push tag_push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
push_data
)
def
execute
(
push_data
)
return
unless
supported_events
.
include?
(
push_data
[
:object_kind
])
return
unless
supported_events
.
include?
(
push_data
[
:object_kind
])
...
...
app/models/project_services/external_wiki_service.rb
View file @
cd51af1a
...
@@ -13,7 +13,7 @@ class ExternalWikiService < Service
...
@@ -13,7 +13,7 @@ class ExternalWikiService < Service
'Replaces the link to the internal wiki with a link to an external wiki.'
'Replaces the link to the internal wiki with a link to an external wiki.'
end
end
def
to_param
def
self
.
to_param
'external_wiki'
'external_wiki'
end
end
...
@@ -29,4 +29,12 @@ class ExternalWikiService < Service
...
@@ -29,4 +29,12 @@ class ExternalWikiService < Service
nil
nil
end
end
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/flowdock_service.rb
View file @
cd51af1a
...
@@ -12,7 +12,7 @@ class FlowdockService < Service
...
@@ -12,7 +12,7 @@ class FlowdockService < Service
'Flowdock is a collaboration web app for technical teams.'
'Flowdock is a collaboration web app for technical teams.'
end
end
def
to_param
def
self
.
to_param
'flowdock'
'flowdock'
end
end
...
@@ -22,10 +22,14 @@ class FlowdockService < Service
...
@@ -22,10 +22,14 @@ class FlowdockService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
app/models/project_services/gemnasium_service.rb
View file @
cd51af1a
...
@@ -12,7 +12,7 @@ class GemnasiumService < Service
...
@@ -12,7 +12,7 @@ class GemnasiumService < Service
'Gemnasium monitors your project dependencies and alerts you about updates and security vulnerabilities.'
'Gemnasium monitors your project dependencies and alerts you about updates and security vulnerabilities.'
end
end
def
to_param
def
self
.
to_param
'gemnasium'
'gemnasium'
end
end
...
@@ -23,10 +23,14 @@ class GemnasiumService < Service
...
@@ -23,10 +23,14 @@ class GemnasiumService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
app/models/project_services/gitlab_issue_tracker_service.rb
View file @
cd51af1a
...
@@ -7,7 +7,7 @@ class GitlabIssueTrackerService < IssueTrackerService
...
@@ -7,7 +7,7 @@ class GitlabIssueTrackerService < IssueTrackerService
default_value_for
:default
,
true
default_value_for
:default
,
true
def
to_param
def
self
.
to_param
'gitlab'
'gitlab'
end
end
...
...
app/models/project_services/hipchat_service.rb
View file @
cd51af1a
...
@@ -27,7 +27,7 @@ class HipchatService < Service
...
@@ -27,7 +27,7 @@ class HipchatService < Service
'Private group chat and IM'
'Private group chat and IM'
end
end
def
to_param
def
self
.
to_param
'hipchat'
'hipchat'
end
end
...
@@ -45,10 +45,14 @@ class HipchatService < Service
...
@@ -45,10 +45,14 @@ class HipchatService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push issue confidential_issue merge_request note tag_push build)
%w(push issue confidential_issue merge_request note tag_push build)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
message
=
create_message
(
data
)
message
=
create_message
(
data
)
...
...
app/models/project_services/irker_service.rb
View file @
cd51af1a
...
@@ -17,14 +17,18 @@ class IrkerService < Service
...
@@ -17,14 +17,18 @@ class IrkerService < Service
'gateway.'
'gateway.'
end
end
def
to_param
def
self
.
to_param
'irker'
'irker'
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
app/models/project_services/issue_tracker_service.rb
View file @
cd51af1a
...
@@ -57,7 +57,7 @@ class IssueTrackerService < Service
...
@@ -57,7 +57,7 @@ class IssueTrackerService < Service
end
end
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
...
...
app/models/project_services/jira_service.rb
View file @
cd51af1a
...
@@ -12,10 +12,14 @@ class JiraService < IssueTrackerService
...
@@ -12,10 +12,14 @@ class JiraService < IssueTrackerService
# This is confusing, but JiraService does not really support these events.
# This is confusing, but JiraService does not really support these events.
# The values here are required to display correct options in the service
# The values here are required to display correct options in the service
# configuration screen.
# configuration screen.
def
supported_events
def
s
elf
.
s
upported_events
%w(commit merge_request)
%w(commit merge_request)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
# {PROJECT-KEY}-{NUMBER} Examples: JIRA-1, PROJECT-1
# {PROJECT-KEY}-{NUMBER} Examples: JIRA-1, PROJECT-1
def
reference_pattern
def
reference_pattern
@reference_pattern
||=
%r{(?<issue>
\b
([A-Z][A-Z0-9_]+-)
\d
+)}
@reference_pattern
||=
%r{(?<issue>
\b
([A-Z][A-Z0-9_]+-)
\d
+)}
...
@@ -81,7 +85,7 @@ class JiraService < IssueTrackerService
...
@@ -81,7 +85,7 @@ class JiraService < IssueTrackerService
end
end
end
end
def
to_param
def
self
.
to_param
'jira'
'jira'
end
end
...
...
app/models/project_services/kubernetes_service.rb
View file @
cd51af1a
...
@@ -52,7 +52,7 @@ class KubernetesService < DeploymentService
...
@@ -52,7 +52,7 @@ class KubernetesService < DeploymentService
'deployments with `app=$CI_ENVIRONMENT_SLUG`'
'deployments with `app=$CI_ENVIRONMENT_SLUG`'
end
end
def
to_param
def
self
.
to_param
'kubernetes'
'kubernetes'
end
end
...
@@ -158,6 +158,14 @@ class KubernetesService < DeploymentService
...
@@ -158,6 +158,14 @@ class KubernetesService < DeploymentService
opts
opts
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
kubeclient_auth_options
def
kubeclient_auth_options
{
bearer_token:
token
}
{
bearer_token:
token
}
end
end
...
...
app/models/project_services/mattermost_service.rb
View file @
cd51af1a
...
@@ -7,7 +7,7 @@ class MattermostService < ChatNotificationService
...
@@ -7,7 +7,7 @@ class MattermostService < ChatNotificationService
'Receive event notifications in Mattermost'
'Receive event notifications in Mattermost'
end
end
def
to_param
def
self
.
to_param
'mattermost'
'mattermost'
end
end
...
@@ -38,4 +38,12 @@ class MattermostService < ChatNotificationService
...
@@ -38,4 +38,12 @@ class MattermostService < ChatNotificationService
def
default_channel_placeholder
def
default_channel_placeholder
"#town-square"
"#town-square"
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/mattermost_slash_commands_service.rb
View file @
cd51af1a
...
@@ -15,7 +15,7 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
...
@@ -15,7 +15,7 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
"Perform common operations on GitLab in Mattermost"
"Perform common operations on GitLab in Mattermost"
end
end
def
to_param
def
self
.
to_param
'mattermost_slash_commands'
'mattermost_slash_commands'
end
end
...
@@ -48,4 +48,12 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
...
@@ -48,4 +48,12 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
method:
'P'
,
method:
'P'
,
username:
'GitLab'
)
username:
'GitLab'
)
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/pipelines_email_service.rb
View file @
cd51af1a
...
@@ -15,14 +15,18 @@ class PipelinesEmailService < Service
...
@@ -15,14 +15,18 @@ class PipelinesEmailService < Service
'Email the pipelines status to a list of recipients.'
'Email the pipelines status to a list of recipients.'
end
end
def
to_param
def
self
.
to_param
'pipelines_email'
'pipelines_email'
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w[pipeline]
%w[pipeline]
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
,
force:
false
)
def
execute
(
data
,
force:
false
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
force
||
should_pipeline_be_notified?
(
data
)
return
unless
force
||
should_pipeline_be_notified?
(
data
)
...
...
app/models/project_services/pivotaltracker_service.rb
View file @
cd51af1a
...
@@ -14,7 +14,7 @@ class PivotaltrackerService < Service
...
@@ -14,7 +14,7 @@ class PivotaltrackerService < Service
'Project Management Software (Source Commits Endpoint)'
'Project Management Software (Source Commits Endpoint)'
end
end
def
to_param
def
self
.
to_param
'pivotaltracker'
'pivotaltracker'
end
end
...
@@ -34,10 +34,14 @@ class PivotaltrackerService < Service
...
@@ -34,10 +34,14 @@ class PivotaltrackerService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
allowed_branch?
(
data
[
:ref
])
return
unless
allowed_branch?
(
data
[
:ref
])
...
...
app/models/project_services/pushover_service.rb
View file @
cd51af1a
...
@@ -13,7 +13,7 @@ class PushoverService < Service
...
@@ -13,7 +13,7 @@ class PushoverService < Service
'Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop.'
'Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop.'
end
end
def
to_param
def
self
.
to_param
'pushover'
'pushover'
end
end
...
@@ -61,10 +61,14 @@ class PushoverService < Service
...
@@ -61,10 +61,14 @@ class PushoverService < Service
]
]
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
execute
(
data
)
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
app/models/project_services/redmine_service.rb
View file @
cd51af1a
...
@@ -19,7 +19,15 @@ class RedmineService < IssueTrackerService
...
@@ -19,7 +19,15 @@ class RedmineService < IssueTrackerService
end
end
end
end
def
to_param
def
self
.
to_param
'redmine'
'redmine'
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/slack_service.rb
View file @
cd51af1a
...
@@ -7,7 +7,7 @@ class SlackService < ChatNotificationService
...
@@ -7,7 +7,7 @@ class SlackService < ChatNotificationService
'Receive event notifications in Slack'
'Receive event notifications in Slack'
end
end
def
to_param
def
self
.
to_param
'slack'
'slack'
end
end
...
@@ -37,4 +37,12 @@ class SlackService < ChatNotificationService
...
@@ -37,4 +37,12 @@ class SlackService < ChatNotificationService
def
default_channel_placeholder
def
default_channel_placeholder
"#general"
"#general"
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/slack_slash_commands_service.rb
View file @
cd51af1a
...
@@ -9,7 +9,7 @@ class SlackSlashCommandsService < ChatSlashCommandsService
...
@@ -9,7 +9,7 @@ class SlackSlashCommandsService < ChatSlashCommandsService
"Perform common operations on GitLab in Slack"
"Perform common operations on GitLab in Slack"
end
end
def
to_param
def
self
.
to_param
'slack_slash_commands'
'slack_slash_commands'
end
end
...
@@ -25,4 +25,12 @@ class SlackSlashCommandsService < ChatSlashCommandsService
...
@@ -25,4 +25,12 @@ class SlackSlashCommandsService < ChatSlashCommandsService
def
format
(
text
)
def
format
(
text
)
Slack
::
Notifier
::
LinkFormatter
.
format
(
text
)
if
text
Slack
::
Notifier
::
LinkFormatter
.
format
(
text
)
if
text
end
end
def
self
.
supported_events
%w()
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
end
end
app/models/project_services/teamcity_service.rb
View file @
cd51af1a
...
@@ -43,14 +43,18 @@ class TeamcityService < CiService
...
@@ -43,14 +43,18 @@ class TeamcityService < CiService
'requests build, that setting is in the vsc root advanced settings.'
'requests build, that setting is in the vsc root advanced settings.'
end
end
def
to_param
def
self
.
to_param
'teamcity'
'teamcity'
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
%w(push)
end
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
fields
def
fields
[
[
{
type:
'text'
,
name:
'teamcity_url'
,
{
type:
'text'
,
name:
'teamcity_url'
,
...
...
app/models/service.rb
View file @
cd51af1a
...
@@ -76,6 +76,7 @@ class Service < ActiveRecord::Base
...
@@ -76,6 +76,7 @@ class Service < ActiveRecord::Base
def
to_param
def
to_param
# implement inside child
# implement inside child
self
.
class
.
to_param
end
end
def
fields
def
fields
...
@@ -92,7 +93,8 @@ class Service < ActiveRecord::Base
...
@@ -92,7 +93,8 @@ class Service < ActiveRecord::Base
end
end
def
event_names
def
event_names
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
# implement inside child
self
.
class
.
event_names
end
end
def
event_field
(
event
)
def
event_field
(
event
)
...
@@ -104,7 +106,7 @@ class Service < ActiveRecord::Base
...
@@ -104,7 +106,7 @@ class Service < ActiveRecord::Base
end
end
def
supported_events
def
supported_events
%w(push tag_push issue confidential_issue merge_request wiki_page)
self
.
class
.
supported_events
end
end
def
execute
(
data
)
def
execute
(
data
)
...
...
changelogs/unreleased/22974-trigger-service-events-through-api.yml
0 → 100644
View file @
cd51af1a
---
title
:
Adds service trigger events to api
merge_request
:
8324
author
:
lib/api/services.rb
View file @
cd51af1a
...
@@ -145,7 +145,7 @@ module API
...
@@ -145,7 +145,7 @@ module API
name: :room
,
name: :room
,
type:
String
,
type:
String
,
desc:
'Campfire room'
desc:
'Campfire room'
}
,
}
],
],
'custom-issue-tracker'
=>
[
'custom-issue-tracker'
=>
[
{
{
...
@@ -534,7 +534,36 @@ module API
...
@@ -534,7 +534,36 @@ module API
desc:
'The password of the user'
desc:
'The password of the user'
}
}
]
]
}.
freeze
}
service_classes
=
[
AsanaService
,
AssemblaService
,
BambooService
,
BugzillaService
,
BuildkiteService
,
BuildsEmailService
,
CampfireService
,
CustomIssueTrackerService
,
DroneCiService
,
EmailsOnPushService
,
ExternalWikiService
,
FlowdockService
,
GemnasiumService
,
HipchatService
,
IrkerService
,
JiraService
,
KubernetesService
,
MattermostSlashCommandsService
,
SlackSlashCommandsService
,
PipelinesEmailService
,
PivotaltrackerService
,
PushoverService
,
RedmineService
,
SlackService
,
MattermostService
,
TeamcityService
,
].
freeze
trigger_services
=
{
trigger_services
=
{
'mattermost-slash-commands'
=>
[
'mattermost-slash-commands'
=>
[
...
@@ -568,6 +597,20 @@ module API
...
@@ -568,6 +597,20 @@ module API
services
.
each
do
|
service_slug
,
settings
|
services
.
each
do
|
service_slug
,
settings
|
desc
"Set
#{
service_slug
}
service for project"
desc
"Set
#{
service_slug
}
service for project"
params
do
params
do
service_classes
.
each
do
|
service
|
event_names
=
service
.
try
(
:event_names
)
||
[]
event_names
.
each
do
|
event_name
|
services
[
service
.
to_param
.
gsub
(
"_"
,
"-"
)]
<<
{
required:
false
,
name:
event_name
.
to_sym
,
type:
String
,
desc:
ServicesHelper
.
instance_method
(
:service_event_description
)
.
bind
(
self
).
call
(
event_name
)
}
end
end
services
.
freeze
settings
.
each
do
|
setting
|
settings
.
each
do
|
setting
|
if
setting
[
:required
]
if
setting
[
:required
]
requires
setting
[
:name
],
type:
setting
[
:type
],
desc:
setting
[
:desc
]
requires
setting
[
:name
],
type:
setting
[
:type
],
desc:
setting
[
:desc
]
...
@@ -581,7 +624,7 @@ module API
...
@@ -581,7 +624,7 @@ module API
service_params
=
declared_params
(
include_missing:
false
).
merge
(
active:
true
)
service_params
=
declared_params
(
include_missing:
false
).
merge
(
active:
true
)
if
service
.
update_attributes
(
service_params
)
if
service
.
update_attributes
(
service_params
)
true
present
service
,
with:
Entities
::
ProjectService
,
include_passwords:
current_user
.
is_admin?
else
else
render_api_error!
(
'400 Bad Request'
,
400
)
render_api_error!
(
'400 Bad Request'
,
400
)
end
end
...
...
spec/requests/api/services_spec.rb
View file @
cd51af1a
...
@@ -6,7 +6,7 @@ describe API::Services, api: true do
...
@@ -6,7 +6,7 @@ describe API::Services, api: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
Service
.
available_services_names
.
each
do
|
service
|
Service
.
available_services_names
.
each
do
|
service
|
describe
"PUT /projects/:id/services/
#{
service
.
dasherize
}
"
do
describe
"PUT /projects/:id/services/
#{
service
.
dasherize
}
"
do
...
@@ -16,6 +16,15 @@ describe API::Services, api: true do
...
@@ -16,6 +16,15 @@ describe API::Services, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user
),
service_attrs
put
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user
),
service_attrs
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
current_service
=
project
.
services
.
first
event
=
current_service
.
event_names
.
empty?
?
"foo"
:
current_service
.
event_names
.
first
state
=
current_service
[
event
]
||
false
put
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
?
#{
event
}
=
#{
!
state
}
"
,
user
),
service_attrs
expect
(
response
).
to
have_http_status
(
200
)
expect
(
project
.
services
.
first
[
event
]).
not_to
eq
(
state
)
unless
event
==
"foo"
end
end
it
"returns if required fields missing"
do
it
"returns if required fields missing"
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