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
6a8359f3
Commit
6a8359f3
authored
May 04, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pacoguzman/gitlab-ce-15001-since-and-until-operators-api-commits'
# Conflicts: # Gemfile.lock
parents
72e4bd5f
c4b9bd04
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
71 additions
and
9 deletions
+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
No files found.
CHANGELOG
View file @
6a8359f3
...
...
@@ -17,6 +17,7 @@ v 8.8.0 (unreleased)
- Add support for supressing text diffs using .gitattributes on the default branch (Matt Oakes)
- Added multiple colors for labels in dropdowns when dups happen.
- Improve description for the Two-factor Authentication sign-in screen. (Connor Shea)
- API support for the 'since' and 'until' operators on commit requests (Paco Guzman)
v 8.7.3
- Emails, Gitlab::Email::Message, Gitlab::Diff, and Premailer::Adapter::Nokogiri are now instrumented
...
...
Gemfile.lock
View file @
6a8359f3
...
...
@@ -353,7 +353,7 @@ GEM
posix-spawn (~> 0.3)
gitlab_emoji (0.3.1)
gemojione (~> 2.2, >= 2.2.1)
gitlab_git (10.0.
1
)
gitlab_git (10.0.
2
)
activesupport (~> 4.0)
charlock_holmes (~> 0.7.3)
github-linguist (~> 4.7.0)
...
...
app/controllers/projects/commits_controller.rb
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
View file @
6a8359f3
...
...
@@ -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
...
...
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