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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
76f5865d
Commit
76f5865d
authored
Aug 30, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove hardcoded code from /api/v3/repos/:ns/:prj/branches
parent
044a1713
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
22 deletions
+49
-22
lib/api/entities.rb
lib/api/entities.rb
+17
-2
lib/api/v3/github_repos.rb
lib/api/v3/github_repos.rb
+15
-11
spec/requests/api/v3/github_repos_spec.rb
spec/requests/api/v3/github_repos_spec.rb
+17
-9
No files found.
lib/api/entities.rb
View file @
76f5865d
...
...
@@ -1092,7 +1092,7 @@ module API
end
module
Github
class
GithubRepoOwn
er
<
Grape
::
Entity
class
Us
er
<
Grape
::
Entity
expose
:id
expose
:login
do
|
project
|
project
.
namespace
.
name
...
...
@@ -1101,9 +1101,24 @@ module API
class
Repository
<
Grape
::
Entity
expose
:id
expose
:owner
,
using:
GithubRepoOwn
er
,
unless:
->
(
project
,
options
)
{
project
.
group
}
expose
:owner
,
using:
Us
er
,
unless:
->
(
project
,
options
)
{
project
.
group
}
expose
:name
end
class
Commit
<
Grape
::
Entity
expose
:id
,
as: :sha
expose
:type
do
|
model
|
'commit'
end
end
class
Branch
<
Grape
::
Entity
expose
:name
expose
:commit
,
using:
Commit
do
|
repo_branch
,
options
|
options
[
:project
].
repository
.
commit
(
repo_branch
.
dereferenced_target
)
end
end
end
end
end
lib/api/v3/github_repos.rb
View file @
76f5865d
...
...
@@ -19,21 +19,25 @@ module API
get
':username/repos'
do
projects
=
ProjectsFinder
.
new
(
current_user:
current_user
,
params:
project_finder_params
).
execute
present
p
rojects
,
with:
::
API
::
Entities
::
Github
::
Repository
present
p
aginate
(
projects
)
,
with:
::
API
::
Entities
::
Github
::
Repository
end
end
params
do
requires
:namespace
,
type:
String
requires
:project
,
type:
String
end
resource
:repos
do
get
':namespace/:
repo
/branches'
do
present
[
{
"name"
=>
"feature"
,
"commit"
=>
{
"type"
=>
'commit'
,
"sha"
=>
"6367e27cc0928789a860676f560ceda6b41b6215"
}
}
]
get
':namespace/:
project
/branches'
do
namespace
=
params
[
:namespace
]
project
=
params
[
:project
]
user_project
=
find_project!
(
"
#{
namespace
}
/
#{
project
}
"
)
branches
=
::
Kaminari
.
paginate_array
(
user_project
.
repository
.
branches
.
sort_by
(
&
:name
))
present
paginate
(
branches
),
with:
::
API
::
Entities
::
Github
::
Branch
,
project:
user_project
end
get
':namespace/:repo/commits/:sha'
do
...
...
spec/requests/api/v3/github_repos_spec.rb
View file @
76f5865d
...
...
@@ -2,15 +2,17 @@ require 'spec_helper'
describe
API
::
V3
::
GithubRepos
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:project
)
{
create
(
:project
,
:repository
,
creator:
user
)
}
describe
'GET /orgs/:id/repos'
do
let
(
:current_user
)
{
user
}
before
do
project
.
add_master
(
user
)
end
describe
'GET /orgs/:id/repos'
do
it
'returns an array of projects'
do
group
=
create
(
:group
)
get
v3_api
(
"/orgs/
#{
group
.
path
}
/repos"
,
current_
user
)
get
v3_api
(
"/orgs/
#{
group
.
path
}
/repos"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
end
...
...
@@ -29,12 +31,18 @@ describe API::V3::GithubRepos do
end
describe
'GET /repos/:namespace/:repo/branches'
do
it
'returns branches with expected format'
do
get
v3_api
(
"/repos/
#{
user
.
namespace
.
path
}
/foo/branches"
,
user
)
context
'when user namespace path'
do
it
'returns an array of project branches with github format'
do
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/branches"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
(
Array
)
expect
(
json_response
.
first
.
keys
).
to
contain_exactly
(
'name'
,
'commit'
)
expect
(
json_response
.
first
[
'commit'
].
keys
).
to
contain_exactly
(
'sha'
,
'type'
)
end
end
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
(
Array
)
expect
(
json_response
).
to
eq
(
''
)
xcontext
'when group path'
do
end
end
...
...
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