Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
612e61f4
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
612e61f4
编写于
2月 20, 2017
作者:
R
Robert Schilling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use grape validation for dates
上级
c89449e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
3 addition
and
22 deletion
+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
未找到文件。
lib/api/commits.rb
浏览文件 @
612e61f4
...
...
@@ -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
浏览文件 @
612e61f4
...
...
@@ -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
浏览文件 @
612e61f4
...
...
@@ -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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录