Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c4b9bd04
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 搜索 >>
提交
c4b9bd04
编写于
4月 22, 2016
作者:
P
Paco Guzman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
API support for the 'since' and 'until' operators on commit requests
- Parameter validation as ISO8601 format
上级
a792427e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
71 addition
and
9 deletion
+71
-9
CHANGELOG
CHANGELOG
+1
-0
Gemfile.lock
Gemfile.lock
+1
-1
app/controllers/projects/commits_controller.rb
app/controllers/projects/commits_controller.rb
+1
-1
app/controllers/projects/graphs_controller.rb
app/controllers/projects/graphs_controller.rb
+2
-2
app/models/repository.rb
app/models/repository.rb
+4
-2
doc/api/commits.md
doc/api/commits.md
+2
-0
lib/api/commits.rb
lib/api/commits.rb
+7
-1
lib/api/helpers.rb
lib/api/helpers.rb
+16
-0
lib/gitlab/push_data_builder.rb
lib/gitlab/push_data_builder.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+1
-1
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+35
-0
未找到文件。
CHANGELOG
浏览文件 @
c4b9bd04
...
...
@@ -8,6 +8,7 @@ v 8.8.0 (unreleased)
- Replace Devise Async with Devise ActiveJob integration. !3902 (Connor Shea)
- Allow "NEWS" and "CHANGES" as alternative names for CHANGELOG. !3768 (Connor Shea)
- Added button to toggle whitespaces changes on diff view
- API support for the 'since' and 'until' operators on commit requests (Paco Guzman)
v 8.7.1 (unreleased)
- Throttle the update of `project.last_activity_at` to 1 minute. !3848
...
...
Gemfile.lock
浏览文件 @
c4b9bd04
...
...
@@ -351,7 +351,7 @@ GEM
posix-spawn (~> 0.3)
gitlab_emoji (0.3.1)
gemojione (~> 2.2, >= 2.2.1)
gitlab_git (10.0.
0
)
gitlab_git (10.0.
2
)
activesupport (~> 4.0)
charlock_holmes (~> 0.7.3)
github-linguist (~> 4.7.0)
...
...
app/controllers/projects/commits_controller.rb
浏览文件 @
c4b9bd04
...
...
@@ -15,7 +15,7 @@ class Projects::CommitsController < Projects::ApplicationController
if
search
.
present?
@repository
.
find_commits_by_message
(
search
,
@ref
,
@path
,
@limit
,
@offset
).
compact
else
@repository
.
commits
(
@ref
,
@path
,
@limit
,
@offset
)
@repository
.
commits
(
@ref
,
path:
@path
,
limit:
@limit
,
offset:
@offset
)
end
@note_counts
=
project
.
notes
.
where
(
commit_id:
@commits
.
map
(
&
:id
)).
...
...
app/controllers/projects/graphs_controller.rb
浏览文件 @
c4b9bd04
...
...
@@ -17,7 +17,7 @@ class Projects::GraphsController < Projects::ApplicationController
end
def
commits
@commits
=
@project
.
repository
.
commits
(
@ref
,
nil
,
2000
,
0
,
true
)
@commits
=
@project
.
repository
.
commits
(
@ref
,
limit:
2000
,
skip_merges:
true
)
@commits_graph
=
Gitlab
::
Graphs
::
Commits
.
new
(
@commits
)
@commits_per_week_days
=
@commits_graph
.
commits_per_week_days
@commits_per_time
=
@commits_graph
.
commits_per_time
...
...
@@ -55,7 +55,7 @@ class Projects::GraphsController < Projects::ApplicationController
private
def
fetch_graph
@commits
=
@project
.
repository
.
commits
(
@ref
,
nil
,
6000
,
0
,
true
)
@commits
=
@project
.
repository
.
commits
(
@ref
,
limit:
6000
,
skip_merges:
true
)
@log
=
[]
@commits
.
each
do
|
commit
|
...
...
app/models/repository.rb
浏览文件 @
c4b9bd04
...
...
@@ -87,13 +87,15 @@ class Repository
nil
end
def
commits
(
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
,
skip_merges
=
false
)
def
commits
(
ref
,
path
:
nil
,
limit:
nil
,
offset:
nil
,
skip_merges:
false
,
after:
nil
,
before:
nil
)
options
=
{
repo:
raw_repository
,
ref:
ref
,
path:
path
,
limit:
limit
,
offset:
offset
,
after:
after
,
before:
before
,
# --follow doesn't play well with --skip. See:
# https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520
follow:
false
,
...
...
@@ -575,7 +577,7 @@ class Repository
end
def
contributors
commits
=
self
.
commits
(
nil
,
nil
,
2000
,
0
,
true
)
commits
=
self
.
commits
(
nil
,
limit:
2000
,
offset:
0
,
skip_merges:
true
)
commits
.
group_by
(
&
:author_email
).
map
do
|
email
,
commits
|
contributor
=
Gitlab
::
Contributor
.
new
...
...
doc/api/commits.md
浏览文件 @
c4b9bd04
...
...
@@ -12,6 +12,8 @@ GET /projects/:id/repository/commits
| --------- | ---- | -------- | ----------- |
|
`id`
| integer | yes | The ID of a project |
|
`ref_name`
| string | no | The name of a repository branch or tag or if not given the default branch |
|
`since`
| string | no | Only commits after or in this date will be returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ |
|
`until`
| string | no | Only commits before or in this date will be returned in ISO 8601 format YYYY-MM-DDTHH:MM:SSZ |
```
bash
curl
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
"https://gitlab.example.com/api/v3/projects/5/repository/commits"
...
...
lib/api/commits.rb
浏览文件 @
c4b9bd04
...
...
@@ -12,14 +12,20 @@ module API
# Parameters:
# id (required) - The ID of a project
# ref_name (optional) - The name of a repository branch or tag, if not given the default branch is used
# since (optional) - Only commits after or in this date will be returned
# until (optional) - Only commits before or in this date will be returned
# Example Request:
# GET /projects/:id/repository/commits
get
":id/repository/commits"
do
datetime_attributes!
:since
,
:until
page
=
(
params
[
:page
]
||
0
).
to_i
per_page
=
(
params
[
:per_page
]
||
20
).
to_i
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
after
=
params
[
:since
]
before
=
params
[
:until
]
commits
=
user_project
.
repository
.
commits
(
ref
,
nil
,
per_page
,
page
*
per_pag
e
)
commits
=
user_project
.
repository
.
commits
(
ref
,
limit:
per_page
,
offset:
page
*
per_page
,
after:
after
,
before:
befor
e
)
present
commits
,
with:
Entities
::
RepoCommit
end
...
...
lib/api/helpers.rb
浏览文件 @
c4b9bd04
...
...
@@ -183,6 +183,22 @@ module API
Gitlab
::
Access
.
options_with_owner
.
values
.
include?
level
.
to_i
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
issuable_order_by
if
params
[
"order_by"
]
==
'updated_at'
'updated_at'
...
...
lib/gitlab/push_data_builder.rb
浏览文件 @
c4b9bd04
...
...
@@ -66,7 +66,7 @@ module Gitlab
# This method provide a sample data generated with
# existing project and commits to test webhooks
def
build_sample
(
project
,
user
)
commits
=
project
.
repository
.
commits
(
project
.
default_branch
,
nil
,
3
)
commits
=
project
.
repository
.
commits
(
project
.
default_branch
,
limit:
3
)
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
project
.
default_branch
}
"
build
(
project
,
user
,
commits
.
last
.
id
,
commits
.
first
.
id
,
ref
,
commits
)
end
...
...
spec/models/repository_spec.rb
浏览文件 @
c4b9bd04
...
...
@@ -561,7 +561,7 @@ describe Repository, models: true do
end
describe
:skip_merged_commit
do
subject
{
repository
.
commits
(
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
"'test'"
,
nil
,
100
,
0
,
true
).
map
{
|
k
|
k
.
id
}
}
subject
{
repository
.
commits
(
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
"'test'"
,
limit:
100
,
skip_merges:
true
).
map
{
|
k
|
k
.
id
}
}
it
{
is_expected
.
not_to
include
(
'e56497bb5f03a90a51293fc6d516788730953899'
)
}
end
...
...
spec/requests/api/commits_spec.rb
浏览文件 @
c4b9bd04
...
...
@@ -32,6 +32,41 @@ describe API::API, api: true do
expect
(
response
.
status
).
to
eq
(
401
)
end
end
context
"since optional parameter"
do
it
"should return project commits since provided parameter"
do
commits
=
project
.
repository
.
commits
(
"master"
)
since
=
commits
.
second
.
created_at
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits?since=
#{
since
.
utc
.
iso8601
}
"
,
user
)
expect
(
json_response
.
size
).
to
eq
2
expect
(
json_response
.
first
[
"id"
]).
to
eq
(
commits
.
first
.
id
)
expect
(
json_response
.
second
[
"id"
]).
to
eq
(
commits
.
second
.
id
)
end
end
context
"until optional parameter"
do
it
"should return project commits until provided parameter"
do
commits
=
project
.
repository
.
commits
(
"master"
)
before
=
commits
.
second
.
created_at
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits?until=
#{
before
.
utc
.
iso8601
}
"
,
user
)
expect
(
json_response
.
size
).
to
eq
(
commits
.
size
-
1
)
expect
(
json_response
.
first
[
"id"
]).
to
eq
(
commits
.
second
.
id
)
expect
(
json_response
.
second
[
"id"
]).
to
eq
(
commits
.
third
.
id
)
end
end
context
"invalid xmlschema date parameters"
do
it
"should return an invalid parameter error message"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits?since=invalid-date"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
json_response
[
'message'
]).
to
include
"
\"
since
\"
must be a timestamp in ISO 8601 format"
end
end
end
describe
"GET /projects:id/repository/commits/:sha"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录