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
Tatuya Kamada
gitlab-ce
Commits
173dbeb9
Commit
173dbeb9
authored
Feb 20, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'api-grape-datetime' into 'master'
Use grape validation for dates See merge request !9375
parents
bc0b438d
612e61f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
22 deletions
+3
-22
lib/api/commits.rb
lib/api/commits.rb
+2
-5
lib/api/helpers.rb
lib/api/helpers.rb
+0
-16
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+1
-1
No files found.
lib/api/commits.rb
View file @
173dbeb9
...
...
@@ -16,16 +16,13 @@ module API
end
params
do
optional
:ref_name
,
type:
String
,
desc:
'The name of a repository branch or tag, if not given the default branch is used'
optional
:since
,
type:
String
,
desc:
'Only commits after or in this date will be returned'
optional
:until
,
type:
String
,
desc:
'Only commits before or in this date will be returned'
optional
:since
,
type:
DateTime
,
desc:
'Only commits after or in this date will be returned'
optional
:until
,
type:
DateTime
,
desc:
'Only commits before or in this date will be returned'
optional
:page
,
type:
Integer
,
default:
0
,
desc:
'The page for pagination'
optional
:per_page
,
type:
Integer
,
default:
20
,
desc:
'The number of results per page'
optional
:path
,
type:
String
,
desc:
'The file path'
end
get
":id/repository/commits"
do
# TODO remove the next line for 9.0, use DateTime type in the params block
datetime_attributes!
:since
,
:until
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
offset
=
params
[
:page
]
*
params
[
:per_page
]
...
...
lib/api/helpers.rb
View file @
173dbeb9
...
...
@@ -160,22 +160,6 @@ module API
ActionController
::
Parameters
.
new
(
attrs
).
permit!
end
# Checks the occurrences of datetime attributes, each attribute if present in the params hash must be in ISO 8601
# format (YYYY-MM-DDTHH:MM:SSZ) or a Bad Request error is invoked.
#
# Parameters:
# keys (required) - An array consisting of elements that must be parseable as dates from the params hash
def
datetime_attributes!
(
*
keys
)
keys
.
each
do
|
key
|
begin
params
[
key
]
=
Time
.
xmlschema
(
params
[
key
])
if
params
[
key
].
present?
rescue
ArgumentError
message
=
"
\"
"
+
key
.
to_s
+
"
\"
must be a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ"
render_api_error!
(
message
,
400
)
end
end
end
def
filter_by_iid
(
items
,
iid
)
items
.
where
(
iid:
iid
)
end
...
...
spec/requests/api/commits_spec.rb
View file @
173dbeb9
...
...
@@ -72,7 +72,7 @@ describe API::Commits, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits?since=invalid-date"
,
user
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'
message'
]).
to
include
"
\"
since
\"
must be a timestamp in ISO 8601 format"
expect
(
json_response
[
'
error'
]).
to
eq
(
'since is invalid'
)
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