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
Kazuhiko Shiozaki
gitlab-ce
Commits
d44653da
Commit
d44653da
authored
Jan 13, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some fixes after review
parent
e0ec69d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
19 deletions
+16
-19
app/models/ci/trigger.rb
app/models/ci/trigger.rb
+4
-0
lib/api/entities.rb
lib/api/entities.rb
+1
-7
lib/api/triggers.rb
lib/api/triggers.rb
+5
-6
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+6
-6
No files found.
app/models/ci/trigger.rb
View file @
d44653da
...
@@ -32,6 +32,10 @@ module Ci
...
@@ -32,6 +32,10 @@ module Ci
trigger_requests
.
last
trigger_requests
.
last
end
end
def
last_used
last_trigger_request
.
try
(
:created_at
)
end
def
short_token
def
short_token
token
[
0
...
10
]
token
[
0
...
10
]
end
end
...
...
lib/api/entities.rb
View file @
d44653da
...
@@ -367,13 +367,7 @@ module API
...
@@ -367,13 +367,7 @@ module API
end
end
class
Trigger
<
Grape
::
Entity
class
Trigger
<
Grape
::
Entity
expose
:token
,
:created_at
,
:updated_at
,
:deleted_at
expose
:token
,
:created_at
,
:updated_at
,
:deleted_at
,
:last_used
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
end
end
end
lib/api/triggers.rb
View file @
d44653da
...
@@ -73,10 +73,10 @@ module API
...
@@ -73,10 +73,10 @@ module API
authenticate!
authenticate!
authorize_admin_project
authorize_admin_project
trigger
s
=
user_project
.
triggers
.
where
(
token:
params
[
:token
]
)
trigger
=
user_project
.
triggers
.
find_by
(
token:
params
[
:token
].
to_s
)
return
not_found!
(
'Trigger'
)
if
triggers
.
empty?
return
not_found!
(
'Trigger'
)
unless
trigger
present
trigger
s
.
first
,
with:
Entities
::
Trigger
present
trigger
,
with:
Entities
::
Trigger
end
end
# Create trigger
# Create trigger
...
@@ -89,8 +89,7 @@ module API
...
@@ -89,8 +89,7 @@ module API
authenticate!
authenticate!
authorize_admin_project
authorize_admin_project
trigger
=
user_project
.
triggers
.
new
trigger
=
user_project
.
triggers
.
create
trigger
.
save
present
trigger
,
with:
Entities
::
Trigger
present
trigger
,
with:
Entities
::
Trigger
end
end
...
@@ -106,7 +105,7 @@ module API
...
@@ -106,7 +105,7 @@ module API
authenticate!
authenticate!
authorize_admin_project
authorize_admin_project
trigger
=
user_project
.
triggers
.
where
(
token:
params
[
:token
]).
first
trigger
=
user_project
.
triggers
.
find_by
(
token:
params
[
:token
].
to_s
)
return
not_found!
(
'Trigger'
)
unless
trigger
return
not_found!
(
'Trigger'
)
unless
trigger
trigger
.
destroy
trigger
.
destroy
...
...
spec/requests/api/triggers_spec.rb
View file @
d44653da
...
@@ -105,7 +105,7 @@ describe API::API do
...
@@ -105,7 +105,7 @@ describe API::API do
end
end
end
end
context
'unauthenti
k
ated user'
do
context
'unauthenti
c
ated user'
do
it
'should not return triggers list'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
...
@@ -123,7 +123,7 @@ describe API::API do
...
@@ -123,7 +123,7 @@ describe API::API do
expect
(
json_response
).
to
be_a
(
Hash
)
expect
(
json_response
).
to
be_a
(
Hash
)
end
end
it
'should respond
e
with 404 Not Found if requesting non-existing trigger'
do
it
'should respond with 404 Not Found if requesting non-existing trigger'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/abcdef012345"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/triggers/abcdef012345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
...
@@ -138,7 +138,7 @@ describe API::API do
...
@@ -138,7 +138,7 @@ describe API::API do
end
end
end
end
context
'unauthenti
k
ated user'
do
context
'unauthenti
c
ated user'
do
it
'should not return triggers list'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
...
@@ -167,7 +167,7 @@ describe API::API do
...
@@ -167,7 +167,7 @@ describe API::API do
end
end
end
end
context
'unauthenti
k
ated user'
do
context
'unauthenti
c
ated user'
do
it
'should not create trigger'
do
it
'should not create trigger'
do
post
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
post
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
...
@@ -185,7 +185,7 @@ describe API::API do
...
@@ -185,7 +185,7 @@ describe API::API do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
it
'should respond
e
with 404 Not Found if requesting non-existing trigger'
do
it
'should respond with 404 Not Found if requesting non-existing trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/abcdef012345"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/abcdef012345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
...
@@ -200,7 +200,7 @@ describe API::API do
...
@@ -200,7 +200,7 @@ describe API::API do
end
end
end
end
context
'unauthenti
k
ated user'
do
context
'unauthenti
c
ated user'
do
it
'should not delete trigger'
do
it
'should not delete trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
...
...
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