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