BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
30d5e9fa
Commit
30d5e9fa
authored
Jan 23, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '22974-trigger-service-events-through-api' into 'master'
adds events to services api deserialization Closes #22974 See merge request !8324
parents
6c65f7a7
4b6e583c
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
137 additions
and
74 deletions
+137
-74
services_helper.rb
app/helpers/services_helper.rb
+11
-9
asana_service.rb
app/models/project_services/asana_service.rb
+2
-2
assembla_service.rb
app/models/project_services/assembla_service.rb
+2
-2
bamboo_service.rb
app/models/project_services/bamboo_service.rb
+1
-5
bugzilla_service.rb
app/models/project_services/bugzilla_service.rb
+1
-1
buildkite_service.rb
app/models/project_services/buildkite_service.rb
+1
-5
builds_email_service.rb
app/models/project_services/builds_email_service.rb
+2
-2
campfire_service.rb
app/models/project_services/campfire_service.rb
+2
-2
chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+1
-1
chat_slash_commands_service.rb
app/models/project_services/chat_slash_commands_service.rb
+2
-2
ci_service.rb
app/models/project_services/ci_service.rb
+1
-1
custom_issue_tracker_service.rb
app/models/project_services/custom_issue_tracker_service.rb
+1
-1
deployment_service.rb
app/models/project_services/deployment_service.rb
+2
-2
drone_ci_service.rb
app/models/project_services/drone_ci_service.rb
+2
-2
emails_on_push_service.rb
app/models/project_services/emails_on_push_service.rb
+2
-2
external_wiki_service.rb
app/models/project_services/external_wiki_service.rb
+5
-1
flowdock_service.rb
app/models/project_services/flowdock_service.rb
+2
-2
gemnasium_service.rb
app/models/project_services/gemnasium_service.rb
+2
-2
gitlab_issue_tracker_service.rb
app/models/project_services/gitlab_issue_tracker_service.rb
+1
-1
hipchat_service.rb
app/models/project_services/hipchat_service.rb
+2
-2
irker_service.rb
app/models/project_services/irker_service.rb
+2
-2
issue_tracker_service.rb
app/models/project_services/issue_tracker_service.rb
+1
-1
jira_service.rb
app/models/project_services/jira_service.rb
+2
-2
kubernetes_service.rb
app/models/project_services/kubernetes_service.rb
+1
-1
mattermost_service.rb
app/models/project_services/mattermost_service.rb
+1
-1
mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+1
-1
pipelines_email_service.rb
app/models/project_services/pipelines_email_service.rb
+2
-2
pivotaltracker_service.rb
app/models/project_services/pivotaltracker_service.rb
+2
-2
pushover_service.rb
app/models/project_services/pushover_service.rb
+2
-2
redmine_service.rb
app/models/project_services/redmine_service.rb
+1
-1
slack_service.rb
app/models/project_services/slack_service.rb
+1
-1
slack_slash_commands_service.rb
app/models/project_services/slack_slash_commands_service.rb
+1
-1
teamcity_service.rb
app/models/project_services/teamcity_service.rb
+1
-5
service.rb
app/models/service.rb
+14
-1
22974-trigger-service-events-through-api.yml
...s/unreleased/22974-trigger-service-events-through-api.yml
+4
-0
services.rb
lib/api/services.rb
+45
-3
services_controller_spec.rb
spec/controllers/projects/services_controller_spec.rb
+1
-0
services_spec.rb
spec/requests/api/services_spec.rb
+10
-1
No files found.
app/helpers/services_helper.rb
View file @
30d5e9fa
module
ServicesHelper
def
service_event_description
(
event
)
case
event
when
"push"
when
"push"
,
"push_events"
"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"
when
"note"
when
"note"
,
"note_events"
"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"
when
"confidential_issue"
when
"confidential_issue"
,
"confidential_issue_events"
"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"
when
"build"
when
"build"
,
"build_events"
"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"
when
"commit"
when
"commit"
,
"commit_events"
"Event will be triggered when a commit is created/updated"
end
end
...
...
@@ -26,4 +26,6 @@ module ServicesHelper
event
=
event
.
pluralize
if
%w[merge_request issue confidential_issue]
.
include?
(
event
)
"
#{
event
}
_events"
end
extend
self
end
app/models/project_services/asana_service.rb
View file @
30d5e9fa
...
...
@@ -25,7 +25,7 @@ You can create a Personal Access Token here:
http://app.asana.com/-/account_api'
end
def
to_param
def
self
.
to_param
'asana'
end
...
...
@@ -44,7 +44,7 @@ http://app.asana.com/-/account_api'
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/assembla_service.rb
View file @
30d5e9fa
...
...
@@ -12,7 +12,7 @@ class AssemblaService < Service
'Project Management Software (Source Commits Endpoint)'
end
def
to_param
def
self
.
to_param
'assembla'
end
...
...
@@ -23,7 +23,7 @@ class AssemblaService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/bamboo_service.rb
View file @
30d5e9fa
...
...
@@ -40,7 +40,7 @@ class BambooService < CiService
'You must set up automatic revision labeling and a repository trigger in Bamboo.'
end
def
to_param
def
self
.
to_param
'bamboo'
end
...
...
@@ -56,10 +56,6 @@ class BambooService < CiService
]
end
def
supported_events
%w(push)
end
def
build_page
(
sha
,
ref
)
with_reactive_cache
(
sha
,
ref
)
{
|
cached
|
cached
[
:build_page
]
}
end
...
...
app/models/project_services/bugzilla_service.rb
View file @
30d5e9fa
...
...
@@ -19,7 +19,7 @@ class BugzillaService < IssueTrackerService
end
end
def
to_param
def
self
.
to_param
'bugzilla'
end
end
app/models/project_services/buildkite_service.rb
View file @
30d5e9fa
...
...
@@ -24,10 +24,6 @@ class BuildkiteService < CiService
hook
.
save
end
def
supported_events
%w(push)
end
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
...
...
@@ -54,7 +50,7 @@ class BuildkiteService < CiService
'Continuous integration and deployments'
end
def
to_param
def
self
.
to_param
'buildkite'
end
...
...
app/models/project_services/builds_email_service.rb
View file @
30d5e9fa
...
...
@@ -19,11 +19,11 @@ class BuildsEmailService < Service
'Email the builds status to a list of recipients.'
end
def
to_param
def
self
.
to_param
'builds_email'
end
def
supported_events
def
s
elf
.
s
upported_events
%w(build)
end
...
...
app/models/project_services/campfire_service.rb
View file @
30d5e9fa
...
...
@@ -12,7 +12,7 @@ class CampfireService < Service
'Simple web-based real-time group chat'
end
def
to_param
def
self
.
to_param
'campfire'
end
...
...
@@ -24,7 +24,7 @@ class CampfireService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/chat_notification_service.rb
View file @
30d5e9fa
...
...
@@ -25,7 +25,7 @@ class ChatNotificationService < Service
valid?
end
def
supported_events
def
s
elf
.
s
upported_events
%w[push issue confidential_issue merge_request note tag_push
build pipeline wiki_page]
end
...
...
app/models/project_services/chat_slash_commands_service.rb
View file @
30d5e9fa
...
...
@@ -13,8 +13,8 @@ class ChatSlashCommandsService < Service
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
end
def
supported_events
[]
def
s
elf
.
s
upported_events
%w()
end
def
can_test?
...
...
app/models/project_services/ci_service.rb
View file @
30d5e9fa
...
...
@@ -8,7 +8,7 @@ class CiService < Service
self
.
respond_to?
(
:token
)
&&
self
.
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
self
.
token
)
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/custom_issue_tracker_service.rb
View file @
30d5e9fa
...
...
@@ -23,7 +23,7 @@ class CustomIssueTrackerService < IssueTrackerService
end
end
def
to_param
def
self
.
to_param
'custom_issue_tracker'
end
...
...
app/models/project_services/deployment_service.rb
View file @
30d5e9fa
...
...
@@ -5,8 +5,8 @@
class
DeploymentService
<
Service
default_value_for
:category
,
'deployment'
def
supported_events
[]
def
s
elf
.
s
upported_events
%w()
end
def
predefined_variables
...
...
app/models/project_services/drone_ci_service.rb
View file @
30d5e9fa
...
...
@@ -32,7 +32,7 @@ class DroneCiService < CiService
true
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push merge_request tag_push)
end
...
...
@@ -87,7 +87,7 @@ class DroneCiService < CiService
'Drone is a Continuous Integration platform built on Docker, written in Go'
end
def
to_param
def
self
.
to_param
'drone_ci'
end
...
...
app/models/project_services/emails_on_push_service.rb
View file @
30d5e9fa
...
...
@@ -12,11 +12,11 @@ class EmailsOnPushService < Service
'Email the commits and diff of each push to a list of recipients.'
end
def
to_param
def
self
.
to_param
'emails_on_push'
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push tag_push)
end
...
...
app/models/project_services/external_wiki_service.rb
View file @
30d5e9fa
...
...
@@ -13,7 +13,7 @@ class ExternalWikiService < Service
'Replaces the link to the internal wiki with a link to an external wiki.'
end
def
to_param
def
self
.
to_param
'external_wiki'
end
...
...
@@ -29,4 +29,8 @@ class ExternalWikiService < Service
nil
end
end
def
self
.
supported_events
%w()
end
end
app/models/project_services/flowdock_service.rb
View file @
30d5e9fa
...
...
@@ -12,7 +12,7 @@ class FlowdockService < Service
'Flowdock is a collaboration web app for technical teams.'
end
def
to_param
def
self
.
to_param
'flowdock'
end
...
...
@@ -22,7 +22,7 @@ class FlowdockService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/gemnasium_service.rb
View file @
30d5e9fa
...
...
@@ -12,7 +12,7 @@ class GemnasiumService < Service
'Gemnasium monitors your project dependencies and alerts you about updates and security vulnerabilities.'
end
def
to_param
def
self
.
to_param
'gemnasium'
end
...
...
@@ -23,7 +23,7 @@ class GemnasiumService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/gitlab_issue_tracker_service.rb
View file @
30d5e9fa
...
...
@@ -7,7 +7,7 @@ class GitlabIssueTrackerService < IssueTrackerService
default_value_for
:default
,
true
def
to_param
def
self
.
to_param
'gitlab'
end
...
...
app/models/project_services/hipchat_service.rb
View file @
30d5e9fa
...
...
@@ -27,7 +27,7 @@ class HipchatService < Service
'Private group chat and IM'
end
def
to_param
def
self
.
to_param
'hipchat'
end
...
...
@@ -45,7 +45,7 @@ class HipchatService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push issue confidential_issue merge_request note tag_push build)
end
...
...
app/models/project_services/irker_service.rb
View file @
30d5e9fa
...
...
@@ -17,11 +17,11 @@ class IrkerService < Service
'gateway.'
end
def
to_param
def
self
.
to_param
'irker'
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/issue_tracker_service.rb
View file @
30d5e9fa
...
...
@@ -57,7 +57,7 @@ class IssueTrackerService < Service
end
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/jira_service.rb
View file @
30d5e9fa
...
...
@@ -12,7 +12,7 @@ class JiraService < IssueTrackerService
# This is confusing, but JiraService does not really support these events.
# The values here are required to display correct options in the service
# configuration screen.
def
supported_events
def
s
elf
.
s
upported_events
%w(commit merge_request)
end
...
...
@@ -81,7 +81,7 @@ class JiraService < IssueTrackerService
end
end
def
to_param
def
self
.
to_param
'jira'
end
...
...
app/models/project_services/kubernetes_service.rb
View file @
30d5e9fa
...
...
@@ -52,7 +52,7 @@ class KubernetesService < DeploymentService
'deployments with `app=$CI_ENVIRONMENT_SLUG`'
end
def
to_param
def
self
.
to_param
'kubernetes'
end
...
...
app/models/project_services/mattermost_service.rb
View file @
30d5e9fa
...
...
@@ -7,7 +7,7 @@ class MattermostService < ChatNotificationService
'Receive event notifications in Mattermost'
end
def
to_param
def
self
.
to_param
'mattermost'
end
...
...
app/models/project_services/mattermost_slash_commands_service.rb
View file @
30d5e9fa
...
...
@@ -15,7 +15,7 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
"Perform common operations on GitLab in Mattermost"
end
def
to_param
def
self
.
to_param
'mattermost_slash_commands'
end
...
...
app/models/project_services/pipelines_email_service.rb
View file @
30d5e9fa
...
...
@@ -15,11 +15,11 @@ class PipelinesEmailService < Service
'Email the pipelines status to a list of recipients.'
end
def
to_param
def
self
.
to_param
'pipelines_email'
end
def
supported_events
def
s
elf
.
s
upported_events
%w[pipeline]
end
...
...
app/models/project_services/pivotaltracker_service.rb
View file @
30d5e9fa
...
...
@@ -14,7 +14,7 @@ class PivotaltrackerService < Service
'Project Management Software (Source Commits Endpoint)'
end
def
to_param
def
self
.
to_param
'pivotaltracker'
end
...
...
@@ -34,7 +34,7 @@ class PivotaltrackerService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/pushover_service.rb
View file @
30d5e9fa
...
...
@@ -13,7 +13,7 @@ class PushoverService < Service
'Pushover makes it easy to get real-time notifications on your Android device, iPhone, iPad, and Desktop.'
end
def
to_param
def
self
.
to_param
'pushover'
end
...
...
@@ -61,7 +61,7 @@ class PushoverService < Service
]
end
def
supported_events
def
s
elf
.
s
upported_events
%w(push)
end
...
...
app/models/project_services/redmine_service.rb
View file @
30d5e9fa
...
...
@@ -19,7 +19,7 @@ class RedmineService < IssueTrackerService
end
end
def
to_param
def
self
.
to_param
'redmine'
end
end
app/models/project_services/slack_service.rb
View file @
30d5e9fa
...
...
@@ -7,7 +7,7 @@ class SlackService < ChatNotificationService
'Receive event notifications in Slack'
end
def
to_param
def
self
.
to_param
'slack'
end
...
...
app/models/project_services/slack_slash_commands_service.rb
View file @
30d5e9fa
...
...
@@ -9,7 +9,7 @@ class SlackSlashCommandsService < ChatSlashCommandsService
"Perform common operations on GitLab in Slack"
end
def
to_param
def
self
.
to_param
'slack_slash_commands'
end
...
...
app/models/project_services/teamcity_service.rb
View file @
30d5e9fa
...
...
@@ -43,14 +43,10 @@ class TeamcityService < CiService
'requests build, that setting is in the vsc root advanced settings.'
end
def
to_param
def
self
.
to_param
'teamcity'
end
def
supported_events
%w(push)
end
def
fields
[
{
type:
'text'
,
name:
'teamcity_url'
,
...
...
app/models/service.rb
View file @
30d5e9fa
...
...
@@ -76,6 +76,11 @@ class Service < ActiveRecord::Base
def
to_param
# implement inside child
self
.
class
.
to_param
end
def
self
.
to_param
raise
NotImplementedError
end
def
fields
...
...
@@ -92,7 +97,11 @@ class Service < ActiveRecord::Base
end
def
event_names
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
self
.
class
.
event_names
end
def
self
.
event_names
self
.
supported_events
.
map
{
|
event
|
"
#{
event
}
_events"
}
end
def
event_field
(
event
)
...
...
@@ -104,6 +113,10 @@ class Service < ActiveRecord::Base
end
def
supported_events
self
.
class
.
supported_events
end
def
self
.
supported_events
%w(push tag_push issue confidential_issue merge_request wiki_page)
end
...
...
changelogs/unreleased/22974-trigger-service-events-through-api.yml
0 → 100644
View file @
30d5e9fa
---
title
:
Adds service trigger events to api
merge_request
:
8324
author
:
lib/api/services.rb
View file @
30d5e9fa
...
...
@@ -145,7 +145,7 @@ module API
name: :room
,
type:
String
,
desc:
'Campfire room'
}
,
}
],
'custom-issue-tracker'
=>
[
{
...
...
@@ -534,7 +534,36 @@ module API
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
=
{
'mattermost-slash-commands'
=>
[
...
...
@@ -568,6 +597,19 @@ module API
services
.
each
do
|
service_slug
,
settings
|
desc
"Set
#{
service_slug
}
service for project"
params
do
service_classes
.
each
do
|
service
|
event_names
=
service
.
try
(
:event_names
)
||
[]
event_names
.
each
do
|
event_name
|
services
[
service
.
to_param
.
tr
(
"_"
,
"-"
)]
<<
{
required:
false
,
name:
event_name
.
to_sym
,
type:
String
,
desc:
ServicesHelper
.
service_event_description
(
event_name
)
}
end
end
services
.
freeze
settings
.
each
do
|
setting
|
if
setting
[
:required
]
requires
setting
[
:name
],
type:
setting
[
:type
],
desc:
setting
[
:desc
]
...
...
@@ -581,7 +623,7 @@ module API
service_params
=
declared_params
(
include_missing:
false
).
merge
(
active:
true
)
if
service
.
update_attributes
(
service_params
)
true
present
service
,
with:
Entities
::
ProjectService
,
include_passwords:
current_user
.
is_admin?
else
render_api_error!
(
'400 Bad Request'
,
400
)
end
...
...
spec/controllers/projects/services_controller_spec.rb
View file @
30d5e9fa
...
...
@@ -54,6 +54,7 @@ describe Projects::ServicesController do
context
'on successful update'
do
it
'sets the flash'
do
expect
(
service
).
to
receive
(
:to_param
).
and_return
(
'hipchat'
)
expect
(
service
).
to
receive
(
:event_names
).
and_return
(
HipchatService
.
event_names
)
put
:update
,
namespace_id:
project
.
namespace
.
id
,
...
...
spec/requests/api/services_spec.rb
View file @
30d5e9fa
...
...
@@ -6,7 +6,7 @@ describe API::Services, api: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
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
|
describe
"PUT /projects/:id/services/
#{
service
.
dasherize
}
"
do
...
...
@@ -16,6 +16,15 @@ describe API::Services, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user
),
service_attrs
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
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