Commit 044a1713 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Remove hardcoded code from /api/v3/users/:ns/repos

parent 43095a61
...@@ -1091,17 +1091,19 @@ module API ...@@ -1091,17 +1091,19 @@ module API
expose :total_failures expose :total_failures
end end
class GithubRepoOwner < Grape::Entity module Github
expose :id class GithubRepoOwner < Grape::Entity
expose :login do |project| expose :id
project.namespace&.name expose :login do |project|
project.namespace.name
end
end end
end
class GithubUserRepo < Grape::Entity class Repository < Grape::Entity
expose :id expose :id
expose :owner, using: GithubRepoOwner, unless: -> (project, options) { project.group } expose :owner, using: GithubRepoOwner, unless: -> (project, options) { project.group }
expose :name expose :name
end
end end
end end
end end
...@@ -3,23 +3,23 @@ module API ...@@ -3,23 +3,23 @@ module API
class GithubRepos < Grape::API class GithubRepos < Grape::API
before { authenticate! } before { authenticate! }
desc 'Get a list of repos of a group'
resource :orgs do resource :orgs do
get ':namespace/repos' do get ':namespace/repos' do
present [] present []
end end
end end
resource :user do
get :repos do
present []
end
end
resource :users do resource :users do
get ':namespace/repos' do get ':username/repos' do
present [{ projects = ProjectsFinder.new(current_user: current_user, params: project_finder_params).execute
"id" => 11,
"owner" => { present projects, with: ::API::Entities::Github::Repository
"login" => "oswaldo",
"id" => 1,
},
"name" => "test",
}]
end end
end end
...@@ -81,12 +81,6 @@ module API ...@@ -81,12 +81,6 @@ module API
present hash present hash
end end
end end
resource :user do
get :repos do
present []
end
end
end end
end end
end end
...@@ -2,29 +2,29 @@ require 'spec_helper' ...@@ -2,29 +2,29 @@ require 'spec_helper'
describe API::V3::GithubRepos do describe API::V3::GithubRepos do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace) }
describe 'GET /orgs/:id/repos' do describe 'GET /orgs/:id/repos' do
let(:current_user) { user } let(:current_user) { user }
it 'returns repos with expected format' do it 'returns an array of projects' do
group = create(:group) group = create(:group)
get v3_api("/orgs/#{group.path}/repos", current_user) get v3_api("/orgs/#{group.path}/repos", current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_empty
end end
end end
describe 'GET /users/:id/repos' do describe 'GET /users/:id/repos' do
let(:current_user) { user } it 'returns an array of projects with github format' do
get v3_api("/users/whatever/repos", user)
it 'returns repos with expected format' do
get v3_api("/users/#{user.namespace.path}/repos", current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
expect(json_response).to eq('') expect(json_response.size).to eq(1)
expect(json_response.first.keys).to contain_exactly('id', 'owner', 'name')
expect(json_response.first['owner'].keys).to contain_exactly('login', 'id')
end end
end end
......
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