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
c46f933b
Commit
c46f933b
authored
Feb 05, 2017
by
George Andrinopoulos
Committed by
Oswaldo Ferreira
Mar 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pagination headers for repository commits api endpoint
parent
473cab81
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
4 deletions
+45
-4
changelogs/unreleased/13605-add-pagination-headers-for-repository-commits-api-endpoint.yml
...agination-headers-for-repository-commits-api-endpoint.yml
+4
-0
lib/api/commits.rb
lib/api/commits.rb
+2
-3
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+10
-1
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+29
-0
No files found.
changelogs/unreleased/13605-add-pagination-headers-for-repository-commits-api-endpoint.yml
0 → 100644
View file @
c46f933b
---
title
:
Fix pagination headers for repository commits api endpoint
merge_request
:
author
:
George Andrinopoulos
lib/api/commits.rb
View file @
c46f933b
...
@@ -24,7 +24,7 @@ module API
...
@@ -24,7 +24,7 @@ module API
end
end
get
":id/repository/commits"
do
get
":id/repository/commits"
do
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
offset
=
params
[
:page
]
*
params
[
:per_page
]
offset
=
(
params
[
:page
]
-
1
)
*
params
[
:per_page
]
commits
=
user_project
.
repository
.
commits
(
ref
,
commits
=
user_project
.
repository
.
commits
(
ref
,
path:
params
[
:path
],
path:
params
[
:path
],
...
@@ -33,8 +33,7 @@ module API
...
@@ -33,8 +33,7 @@ module API
after:
params
[
:since
],
after:
params
[
:since
],
before:
params
[
:until
])
before:
params
[
:until
])
commit_count
=
user_project
.
repository
.
commit_count_for_ref
(
ref
)
paginated_commits
=
Kaminari
.
paginate_array
(
commits
,
total_count:
commits
.
size
)
paginated_commits
=
Kaminari
.
paginate_array
(
commits
,
total_count:
commit_count
)
present
paginate
(
paginated_commits
),
with:
Entities
::
RepoCommit
present
paginate
(
paginated_commits
),
with:
Entities
::
RepoCommit
end
end
...
...
lib/gitlab/git/repository.rb
View file @
c46f933b
...
@@ -292,7 +292,6 @@ module Gitlab
...
@@ -292,7 +292,6 @@ module Gitlab
}
}
options
=
default_options
.
merge
(
options
)
options
=
default_options
.
merge
(
options
)
options
[
:limit
]
||=
0
options
[
:offset
]
||=
0
options
[
:offset
]
||=
0
actual_ref
=
options
[
:ref
]
||
root_ref
actual_ref
=
options
[
:ref
]
||
root_ref
begin
begin
...
@@ -354,6 +353,16 @@ module Gitlab
...
@@ -354,6 +353,16 @@ module Gitlab
lines
.
map!
{
|
c
|
Rugged
::
Commit
.
new
(
rugged
,
c
.
strip
)
}
lines
.
map!
{
|
c
|
Rugged
::
Commit
.
new
(
rugged
,
c
.
strip
)
}
end
end
def
count_commits
(
options
)
cmd
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
--git-dir=
#{
path
}
rev-list)
cmd
+=
%W(--after=
#{
options
[
:after
].
iso8601
}
)
if
options
[
:after
]
cmd
+=
%W(--before=
#{
options
[
:before
].
iso8601
}
)
if
options
[
:before
]
cmd
+=
%W(--count
#{
options
[
:ref
]
}
)
cmd
+=
%W(--
#{
options
[
:path
]
}
)
if
options
[
:path
].
present?
raw_output
=
IO
.
popen
(
cmd
)
{
|
io
|
io
.
read
}
raw_output
.
to_i
end
def
sha_from_ref
(
ref
)
def
sha_from_ref
(
ref
)
rev_parse_target
(
ref
).
oid
rev_parse_target
(
ref
).
oid
end
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
c46f933b
...
@@ -824,6 +824,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -824,6 +824,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
it
{
is_expected
.
to
eq
(
17
)
}
it
{
is_expected
.
to
eq
(
17
)
}
end
end
describe
'#count_commits'
do
context
'with after timestamp'
do
options
=
{
ref:
'master'
,
limit:
nil
,
after:
Time
.
iso8601
(
'2013-03-03T20:15:01+00:00'
)
}
it
'returns the number of commits after timestamp'
do
commits
=
repository
.
log
(
options
)
expect
(
repository
.
count_commits
(
options
)).
to
eq
(
commits
.
size
)
end
end
context
'with before timestamp'
do
options
=
{
ref:
'feature'
,
limit:
nil
,
before:
Time
.
iso8601
(
'2015-03-03T20:15:01+00:00'
)
}
it
'returns the number of commits after timestamp'
do
commits
=
repository
.
log
(
options
)
expect
(
repository
.
count_commits
(
options
)).
to
eq
(
commits
.
size
)
end
end
context
'with path'
do
options
=
{
ref:
'master'
,
limit:
nil
,
path:
"encoding"
}
it
'returns the number of commits with path '
do
commits
=
repository
.
log
(
options
)
expect
(
repository
.
count_commits
(
options
)).
to
eq
(
commits
.
size
)
end
end
end
describe
"branch_names_contains"
do
describe
"branch_names_contains"
do
subject
{
repository
.
branch_names_contains
(
SeedRepo
::
LastCommit
::
ID
)
}
subject
{
repository
.
branch_names_contains
(
SeedRepo
::
LastCommit
::
ID
)
}
...
...
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