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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
d9da81f7
Commit
d9da81f7
authored
Jan 04, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add triggers feature to API
parent
0a62d3b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
4 deletions
+71
-4
lib/api/entities.rb
lib/api/entities.rb
+10
-0
lib/api/triggers.rb
lib/api/triggers.rb
+18
-0
spec/factories/ci/trigger_requests.rb
spec/factories/ci/trigger_requests.rb
+2
-0
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+41
-4
No files found.
lib/api/entities.rb
View file @
d9da81f7
...
...
@@ -365,5 +365,15 @@ module API
class
TriggerRequest
<
Grape
::
Entity
expose
:id
,
:variables
end
class
Trigger
<
Grape
::
Entity
expose
:id
,
:token
,
:created_at
,
:updated_at
,
:deleted_at
expose
:last_used
do
|
repo_obj
,
_options
|
if
repo_obj
.
respond_to?
(
:last_trigger_request
)
request
=
repo_obj
.
last_trigger_request
request
.
created_at
if
request
end
end
end
end
end
lib/api/triggers.rb
View file @
d9da81f7
...
...
@@ -43,6 +43,24 @@ module API
render_api_error!
(
errors
,
400
)
end
end
# Get triggers list
#
# Parameters:
# id (required) - The ID of a project
# page (optional) - The page number for pagination
# per_page (optional) - The value of items per page to show
# Example Request:
# GET /projects/:id/triggers
get
':id/triggers'
do
authenticate!
authorize_admin_project
triggers
=
user_project
.
triggers
.
includes
(
:trigger_requests
)
triggers
=
paginate
(
triggers
)
present
triggers
,
with:
Entities
::
Trigger
end
end
end
end
spec/factories/ci/trigger_requests.rb
View file @
d9da81f7
...
...
@@ -3,6 +3,8 @@
FactoryGirl
.
define
do
factory
:ci_trigger_request
,
class:
Ci
::
TriggerRequest
do
factory
:ci_trigger_request_with_variables
do
trigger
:ci_trigger
variables
do
{
TRIGGER_KEY
:
'TRIGGER_VALUE'
...
...
spec/requests/api/triggers_spec.rb
View file @
d9da81f7
...
...
@@ -3,11 +3,19 @@ require 'spec_helper'
describe
API
::
API
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let!
(
:trigger_token
)
{
'secure token'
}
let!
(
:trigger_token_2
)
{
'secure token 2'
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:master
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
MASTER
)
}
let!
(
:developer
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
DEVELOPER
)
}
let!
(
:trigger
)
{
create
(
:ci_trigger
,
project:
project
,
token:
trigger_token
)
}
let!
(
:trigger2
)
{
create
(
:ci_trigger
,
project:
project
,
token:
trigger_token_2
)
}
let!
(
:trigger_request
)
{
create
(
:ci_trigger_request
,
trigger:
trigger
,
created_at:
'2015-01-01 12:13:14'
)
}
describe
'POST /projects/:project_id/trigger'
do
let!
(
:trigger_token
)
{
'secure token'
}
let!
(
:project
)
{
FactoryGirl
.
create
(
:project
)
}
let!
(
:project2
)
{
FactoryGirl
.
create
(
:empty_project
)
}
let!
(
:trigger
)
{
FactoryGirl
.
create
(
:ci_trigger
,
project:
project
,
token:
trigger_token
)
}
let!
(
:project2
)
{
create
(
:empty_project
)
}
let
(
:options
)
do
{
token:
trigger_token
...
...
@@ -77,4 +85,33 @@ describe API::API do
end
end
end
describe
'GET /projects/:id/triggets'
do
context
'authenticated user with valid permissions'
do
it
'should return list of triggers'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
expect
(
json_response
[
0
][
'token'
]).
to
eq
(
trigger_token
)
expect
(
json_response
[
1
][
'token'
]).
to
eq
(
trigger_token_2
)
end
end
context
'authenticated user with invalid permissions'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'unauthentikated user'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
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