Commit 61caaa8d authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Define pagination params

parent 04094afc
...@@ -16,7 +16,7 @@ module API ...@@ -16,7 +16,7 @@ module API
class BranchCommit < Grape::Entity class BranchCommit < Grape::Entity
expose :id, as: :sha expose :id, as: :sha
expose :type do |model| expose :type do |_|
'commit' 'commit'
end end
end end
...@@ -36,7 +36,6 @@ module API ...@@ -36,7 +36,6 @@ module API
} }
end end
expose :commit do |commit| expose :commit do |commit|
# TODO: export to entity
{ {
author: { author: {
name: commit.author_name, name: commit.author_name,
...@@ -54,7 +53,6 @@ module API ...@@ -54,7 +53,6 @@ module API
} }
end end
expose :parents do |commit| expose :parents do |commit|
# TODO: export to entity
commit.parent_ids.map { |id| { sha: id } } commit.parent_ids.map { |id| { sha: id } }
end end
expose :files do |commit| expose :files do |commit|
......
module API module API
module V3 module V3
class Github < Grape::API class Github < Grape::API
include PaginationParams
before do before do
authenticate!
authorize_jira_user_agent!(request) authorize_jira_user_agent!(request)
authenticate!
end end
helpers do helpers do
...@@ -36,6 +38,9 @@ module API ...@@ -36,6 +38,9 @@ module API
end end
resource :users do resource :users do
params do
use :pagination
end
get ':namespace/repos' do get ':namespace/repos' do
projects = current_user.authorized_projects.select { |project| project.feature_available?(:jira_dev_panel_integration) } projects = current_user.authorized_projects.select { |project| project.feature_available?(:jira_dev_panel_integration) }
projects = ::Kaminari.paginate_array(projects) projects = ::Kaminari.paginate_array(projects)
...@@ -50,6 +55,7 @@ module API ...@@ -50,6 +55,7 @@ module API
params do params do
use :project_full_path use :project_full_path
use :pagination
end end
get ':namespace/:project/branches' do get ':namespace/:project/branches' do
namespace = params[:namespace] namespace = params[:namespace]
......
...@@ -50,6 +50,7 @@ describe API::V3::Github do ...@@ -50,6 +50,7 @@ describe API::V3::Github do
get v3_api('/users/foo/repos', user) get v3_api('/users/foo/repos', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
...@@ -81,6 +82,7 @@ describe API::V3::Github do ...@@ -81,6 +82,7 @@ describe API::V3::Github do
get v3_api('/users/foo/repos', user) get v3_api('/users/foo/repos', user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response.first['id']).to eq(licensed_project.id) expect(json_response.first['id']).to eq(licensed_project.id)
end end
...@@ -94,6 +96,7 @@ describe API::V3::Github do ...@@ -94,6 +96,7 @@ describe API::V3::Github do
get v3_api("/repos/#{project.namespace.path}/#{project.path}/branches", user) get v3_api("/repos/#{project.namespace.path}/#{project.path}/branches", user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response.first.keys).to contain_exactly('name', 'commit') expect(json_response.first.keys).to contain_exactly('name', 'commit')
expect(json_response.first['commit'].keys).to contain_exactly('sha', 'type') expect(json_response.first['commit'].keys).to contain_exactly('sha', 'type')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment