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
a6b1f018
Commit
a6b1f018
authored
Sep 02, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and remove hardcoded remainings
parent
2b9d0ef7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
167 deletions
+115
-167
lib/api/entities.rb
lib/api/entities.rb
+14
-11
lib/api/users.rb
lib/api/users.rb
+0
-37
lib/api/v3/github_repos.rb
lib/api/v3/github_repos.rb
+17
-57
spec/requests/api/v3/github_repos_spec.rb
spec/requests/api/v3/github_repos_spec.rb
+84
-62
No files found.
lib/api/entities.rb
View file @
a6b1f018
...
@@ -1092,13 +1092,13 @@ module API
...
@@ -1092,13 +1092,13 @@ module API
end
end
module
Github
module
Github
class
Namespace
<
Grape
::
Entity
class
User
<
Grape
::
Entity
expose
:
path
,
as: :login
expose
:
username
end
end
class
Repository
<
Grape
::
Entity
class
Repository
<
Grape
::
Entity
expose
:id
expose
:id
expose
:
namespace
,
as: :owner
,
using:
Namespace
expose
:
owner
,
using:
User
expose
:name
expose
:name
end
end
...
@@ -1109,20 +1109,18 @@ module API
...
@@ -1109,20 +1109,18 @@ module API
end
end
end
end
class
CommitUser
<
Grape
::
Entity
expose
:path
,
as: :login
end
class
RepoCommit
<
Grape
::
Entity
class
RepoCommit
<
Grape
::
Entity
expose
:id
,
as: :sha
expose
:id
,
as: :sha
expose
:author
do
|
commit
|
expose
:author
do
|
commit
|
{
{
"login"
=>
"oswaldo"
,
login:
commit
.
author
.
username
,
email:
commit
.
author_email
}
}
end
end
expose
:committer
do
|
commit
|
expose
:committer
do
|
commit
|
{
{
"login"
=>
"oswaldo"
,
login:
commit
.
author
.
username
,
email:
commit
.
committer_email
}
}
end
end
expose
:commit
do
|
commit
|
expose
:commit
do
|
commit
|
...
@@ -1131,12 +1129,14 @@ module API
...
@@ -1131,12 +1129,14 @@ module API
author:
{
author:
{
name:
commit
.
author_name
,
name:
commit
.
author_name
,
email:
commit
.
author_email
,
email:
commit
.
author_email
,
date:
commit
.
authored_date
.
iso8601
(
3
)
date:
commit
.
authored_date
.
iso8601
,
type:
'User'
},
},
committer:
{
committer:
{
name:
commit
.
committer_name
,
name:
commit
.
committer_name
,
email:
commit
.
committer_email
,
email:
commit
.
committer_email
,
date:
commit
.
committed_date
.
iso8601
(
3
)
date:
commit
.
committed_date
.
iso8601
,
type:
'User'
},
},
message:
commit
.
safe_message
message:
commit
.
safe_message
}
}
...
@@ -1145,6 +1145,9 @@ module API
...
@@ -1145,6 +1145,9 @@ module API
# TODO: export to entity
# TODO: export to entity
commit
.
parent_ids
.
map
{
|
id
|
{
sha:
id
}
}
commit
.
parent_ids
.
map
{
|
id
|
{
sha:
id
}
}
end
end
expose
:files
do
|
commit
|
[]
end
end
end
class
Branch
<
Grape
::
Entity
class
Branch
<
Grape
::
Entity
...
...
lib/api/users.rb
View file @
a6b1f018
...
@@ -5,43 +5,6 @@ module API
...
@@ -5,43 +5,6 @@ module API
allow_access_with_scope
:read_user
,
if:
->
(
request
)
{
request
.
get?
}
allow_access_with_scope
:read_user
,
if:
->
(
request
)
{
request
.
get?
}
resource
:users
do
get
':id'
do
present
{
"login"
=>
"oswaldo"
,
"id"
=>
1
,
"avatar_url"
=>
"https://github.com/images/error/octocat_happy.gif"
,
"gravatar_id"
=>
""
,
"url"
=>
"https://api.github.com/users/octocat"
,
"html_url"
=>
"https://github.com/octocat"
,
"followers_url"
=>
"https://api.github.com/users/octocat/followers"
,
"following_url"
=>
"https://api.github.com/users/octocat/following{/other_user}"
,
"gists_url"
=>
"https://api.github.com/users/octocat/gists{/gist_id}"
,
"starred_url"
=>
"https://api.github.com/users/octocat/starred{/owner}{/repo}"
,
"subscriptions_url"
=>
"https://api.github.com/users/octocat/subscriptions"
,
"organizations_url"
=>
"https://api.github.com/users/octocat/orgs"
,
"repos_url"
=>
"https://api.github.com/users/octocat/repos"
,
"events_url"
=>
"https://api.github.com/users/octocat/events{/privacy}"
,
"received_events_url"
=>
"https://api.github.com/users/octocat/received_events"
,
"type"
=>
"User"
,
"site_admin"
=>
false
,
"name"
=>
"monalisa octocat"
,
"company"
=>
"GitHub"
,
"blog"
=>
"https://github.com/blog"
,
"location"
=>
"San Francisco"
,
"email"
=>
"octocat@github.com"
,
"hireable"
=>
false
,
"bio"
=>
"There once was..."
,
"public_repos"
=>
2
,
"public_gists"
=>
1
,
"followers"
=>
20
,
"following"
=>
0
,
"created_at"
=>
"2008-01-14T04:33:35Z"
,
"updated_at"
=>
"2008-01-14T04:33:35Z"
}
end
end
resource
:users
,
requirements:
{
uid:
/[0-9]*/
,
id:
/[0-9]*/
}
do
resource
:users
,
requirements:
{
uid:
/[0-9]*/
,
id:
/[0-9]*/
}
do
before
do
before
do
authenticate_non_get!
authenticate_non_get!
...
...
lib/api/v3/github_repos.rb
View file @
a6b1f018
...
@@ -3,6 +3,13 @@ module API
...
@@ -3,6 +3,13 @@ module API
class
GithubRepos
<
Grape
::
API
class
GithubRepos
<
Grape
::
API
before
{
authenticate!
}
before
{
authenticate!
}
helpers
do
params
:project_full_path
do
requires
:namespace
,
type:
String
requires
:project
,
type:
String
end
end
resource
:orgs
do
resource
:orgs
do
get
':namespace/repos'
do
get
':namespace/repos'
do
present
[]
present
[]
...
@@ -17,20 +24,19 @@ module API
...
@@ -17,20 +24,19 @@ module API
resource
:users
do
resource
:users
do
get
':namespace/repos'
do
get
':namespace/repos'
do
projs
=
::
API
::
Entities
::
Github
::
Repository
.
represent
(
current_user
.
authorized_projects
).
as_json
present
paginate
(
current_user
.
authorized_projects
),
with:
::
API
::
Entities
::
Github
::
Repository
Rails
.
logger
.
info
(
"PROJS JSON:
#{
projs
}
"
)
present
paginate
(
current_user
.
authorized_projects
),
with:
::
API
::
Entities
::
Github
::
Repository
end
end
end
end
param
s
do
resource
:repo
s
do
requires
:namespace
,
type:
String
get
'/-/jira/pulls'
do
requires
:project
,
type:
String
present
[]
end
end
resource
:repos
do
params
do
use
:project_full_path
end
get
':namespace/:project/branches'
do
get
':namespace/:project/branches'
do
namespace
=
params
[
:namespace
]
namespace
=
params
[
:namespace
]
project
=
params
[
:project
]
project
=
params
[
:project
]
...
@@ -40,8 +46,6 @@ module API
...
@@ -40,8 +46,6 @@ module API
.
represent
(
user_project
.
repository
.
branches
.
sort_by
(
&
:name
),
project:
user_project
)
.
represent
(
user_project
.
repository
.
branches
.
sort_by
(
&
:name
),
project:
user_project
)
.
as_json
.
as_json
Rails
.
logger
.
info
(
"BRANCHES:
#{
branches
}
"
)
branches
=
::
Kaminari
.
paginate_array
(
user_project
.
repository
.
branches
.
sort_by
(
&
:name
))
branches
=
::
Kaminari
.
paginate_array
(
user_project
.
repository
.
branches
.
sort_by
(
&
:name
))
present
paginate
(
branches
),
present
paginate
(
branches
),
...
@@ -50,8 +54,7 @@ module API
...
@@ -50,8 +54,7 @@ module API
end
end
params
do
params
do
requires
:namespace
,
type:
String
use
:project_full_path
requires
:project
,
type:
String
end
end
get
':namespace/:project/commits/:sha'
do
get
':namespace/:project/commits/:sha'
do
namespace
=
params
[
:namespace
]
namespace
=
params
[
:namespace
]
...
@@ -66,49 +69,6 @@ module API
...
@@ -66,49 +69,6 @@ module API
Rails
.
logger
.
info
(
"JSON COMMIT:
#{
json_commit
}
"
)
Rails
.
logger
.
info
(
"JSON COMMIT:
#{
json_commit
}
"
)
present
commit
,
with:
::
API
::
Entities
::
Github
::
RepoCommit
present
commit
,
with:
::
API
::
Entities
::
Github
::
RepoCommit
# hash =
# {
# "sha" => "b0ee36f0a5356c092a5d4913f3523db93a1db565",
# "commit" => {
# "author" => {
# "name" => "oswaksd",
# "email" => "oswluizf@gmail.com",
# "date" => "2011-04-14T16:00:49Z"
# },
# "committer" => {
# "name" => "oswaksd",
# "email" => "oswluizf@gmail.com",
# "date" => "2011-04-14T16:00:49Z"
# },
# "message" => "Fix all the bugs GL-2",
# },
# "author" => {
# "login" => "oswaldo",
# "gravatar_id" => "",
# },
# "committer" => {
# "login" => "oswaldo",
# "gravatar_id" => "",
# },
# "parents" => [
# {
# "sha" => "e7d7eb49018d7bffa6be52586c518974778965c5"
# }
# ],
# "files" => [
# {
# "filename" => "file1.txt",
# "additions" => 10,
# "deletions" => 2,
# "changes" => 12,
# "status" => "modified",
# "patch" => "@@ -29,7 +29,7 @@\n....."
# }
# ]
# }
# present hash
end
end
end
end
end
end
...
...
spec/requests/api/v3/github_repos_spec.rb
View file @
a6b1f018
...
@@ -8,13 +8,32 @@ describe API::V3::GithubRepos do
...
@@ -8,13 +8,32 @@ describe API::V3::GithubRepos do
project
.
add_master
(
user
)
project
.
add_master
(
user
)
end
end
describe
'GET /orgs/:
id
/repos'
do
describe
'GET /orgs/:
namespace
/repos'
do
it
'returns an
array of projects
'
do
it
'returns an
empty array
'
do
group
=
create
(
:group
)
group
=
create
(
:group
)
get
v3_api
(
"/orgs/
#{
group
.
path
}
/repos"
,
user
)
get
v3_api
(
"/orgs/
#{
group
.
path
}
/repos"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
([])
end
end
describe
'GET /user/repos'
do
it
'returns an empty array'
do
get
v3_api
(
"/user/repos"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
([])
end
end
describe
'GET /-/jira/pulls'
do
it
'returns an empty array'
do
get
v3_api
(
"/repos/-/jira/pulls"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
eq
([])
end
end
end
end
...
@@ -32,7 +51,7 @@ describe API::V3::GithubRepos do
...
@@ -32,7 +51,7 @@ describe API::V3::GithubRepos do
end
end
context
'unauthenticated'
do
context
'unauthenticated'
do
it
'returns
an array of projects with github format
'
do
it
'returns
401
'
do
get
v3_api
(
"/users/whatever/repos"
,
nil
)
get
v3_api
(
"/users/whatever/repos"
,
nil
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
...
@@ -41,6 +60,7 @@ describe API::V3::GithubRepos do
...
@@ -41,6 +60,7 @@ describe API::V3::GithubRepos do
end
end
describe
'GET /repos/:namespace/:repo/branches'
do
describe
'GET /repos/:namespace/:repo/branches'
do
context
'authenticated'
do
context
'when user namespace path'
do
context
'when user namespace path'
do
it
'returns an array of project branches with github format'
do
it
'returns an array of project branches with github format'
do
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/branches"
,
user
)
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/branches"
,
user
)
...
@@ -51,8 +71,14 @@ describe API::V3::GithubRepos do
...
@@ -51,8 +71,14 @@ describe API::V3::GithubRepos do
expect
(
json_response
.
first
[
'commit'
].
keys
).
to
contain_exactly
(
'sha'
,
'type'
)
expect
(
json_response
.
first
[
'commit'
].
keys
).
to
contain_exactly
(
'sha'
,
'type'
)
end
end
end
end
end
context
'unauthenticated'
do
it
'returns 401'
do
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/branches"
,
nil
)
xcontext
'when group path'
do
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
end
end
...
@@ -60,6 +86,7 @@ describe API::V3::GithubRepos do
...
@@ -60,6 +86,7 @@ describe API::V3::GithubRepos do
let
(
:commit
)
{
project
.
repository
.
commit
}
let
(
:commit
)
{
project
.
repository
.
commit
}
let
(
:commit_id
)
{
commit
.
id
}
let
(
:commit_id
)
{
commit
.
id
}
context
'authenticated'
do
it
'returns commit with expected format'
do
it
'returns commit with expected format'
do
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/commits/
#{
commit_id
}
"
,
user
)
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/commits/
#{
commit_id
}
"
,
user
)
...
@@ -83,20 +110,15 @@ describe API::V3::GithubRepos do
...
@@ -83,20 +110,15 @@ describe API::V3::GithubRepos do
expect
(
json_response
.
dig
(
'commit'
,
'author'
)).
to
eq
(
commit_author
)
expect
(
json_response
.
dig
(
'commit'
,
'author'
)).
to
eq
(
commit_author
)
expect
(
json_response
.
dig
(
'commit'
,
'committer'
)).
to
eq
(
commit_committer
)
expect
(
json_response
.
dig
(
'commit'
,
'committer'
)).
to
eq
(
commit_committer
)
expect
(
json_response
.
dig
(
'commit'
,
'message'
)).
to
eq
(
commit
.
safe_message
)
expect
(
json_response
.
dig
(
'commit'
,
'message'
)).
to
eq
(
commit
.
safe_message
)
end
end
context
'unauthenticated'
do
it
'returns 401'
do
get
v3_api
(
"/repos/
#{
project
.
namespace
.
path
}
/
#{
project
.
path
}
/commits/
#{
commit_id
}
"
,
nil
)
# expect(json_response['short_id']).to eq(commit.short_id)
expect
(
response
).
to
have_http_status
(
401
)
# expect(json_response['title']).to eq(commit.title)
end
# expect(json_response['author_name']).to eq(commit.author_name)
# expect(json_response['author_email']).to eq(commit.author_email)
# expect(json_response['authored_date']).to eq(commit.authored_date.iso8601(3))
# expect(json_response['committer_name']).to eq(commit.committer_name)
# expect(json_response['committer_email']).to eq(commit.committer_email)
# expect(json_response['committed_date']).to eq(commit.committed_date.iso8601(3))
# expect(json_response['parent_ids']).to eq(commit.parent_ids)
# expect(json_response['stats']['additions']).to eq(commit.stats.additions)
# expect(json_response['stats']['deletions']).to eq(commit.stats.deletions)
# expect(json_response['stats']['total']).to eq(commit.stats.total)
# expect(json_response['status']).to be_nil
end
end
end
end
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