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
c6d13e36
Commit
c6d13e36
authored
Aug 18, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Github API commits layer
parent
bfc57099
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
185 additions
and
7 deletions
+185
-7
app/controllers/oauth/jira/authorizations_controller.rb
app/controllers/oauth/jira/authorizations_controller.rb
+3
-4
config/initializers/etag_caching.rb
config/initializers/etag_caching.rb
+1
-0
lib/api/api.rb
lib/api/api.rb
+5
-3
lib/api/entities.rb
lib/api/entities.rb
+13
-0
lib/api/v3/github_repos.rb
lib/api/v3/github_repos.rb
+92
-0
lib/api/v3/users.rb
lib/api/v3/users.rb
+5
-0
lib/gitlab/jira/middleware.rb
lib/gitlab/jira/middleware.rb
+17
-0
spec/requests/api/v3/github_repos_spec.rb
spec/requests/api/v3/github_repos_spec.rb
+49
-0
No files found.
app/controllers/oauth/jira/authorizations_controller.rb
View file @
c6d13e36
# This controller's role is to mimic
the Gitlab OAuth flow routes for Jira DVCS
# integration.
# This controller's role is to mimic
and rewire the Gitlab OAuth
#
flow routes for Jira DVCS
integration.
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/2381
#
class
Oauth::Jira::AuthorizationsController
<
ActionController
::
Base
...
...
@@ -24,8 +24,7 @@ class Oauth::Jira::AuthorizationsController < ActionController::Base
.
slice
(
:code
,
:client_id
,
:client_secret
)
.
merge
(
grant_type:
'authorization_code'
,
redirect_uri:
oauth_jira_callback_url
)
auth_response
=
HTTParty
.
post
(
oauth_token_url
,
body:
auth_params
)
auth_response
=
HTTParty
.
post
(
oauth_token_url
,
body:
auth_params
)
# TODO: join url params in a better way
token
=
"access_token="
+
...
...
config/initializers/etag_caching.rb
View file @
c6d13e36
...
...
@@ -2,3 +2,4 @@
# in the middleware stack, because it tracks events with
# GitLab Performance Monitoring
Rails
.
application
.
config
.
middleware
.
use
(
Gitlab
::
EtagCaching
::
Middleware
)
Rails
.
application
.
config
.
middleware
.
use
(
Gitlab
::
Jira
::
Middleware
)
lib/api/api.rb
View file @
c6d13e36
...
...
@@ -5,6 +5,9 @@ module API
allow_access_with_scope
:api
prefix
:api
NO_SLASH_URL_PART_REGEX
=
%r{[^/]+}
PROJECT_ENDPOINT_REQUIREMENTS
=
{
id:
NO_SLASH_URL_PART_REGEX
}.
freeze
version
%w(v3 v4)
,
using: :path
version
'v3'
,
using: :path
do
...
...
@@ -12,6 +15,8 @@ module API
helpers
::
API
::
Helpers
::
CommonHelpers
mount
::
API
::
V3
::
AwardEmoji
mount
::
API
::
V3
::
GithubRepos
mount
::
API
::
V3
::
Boards
mount
::
API
::
V3
::
Branches
mount
::
API
::
V3
::
BroadcastMessages
...
...
@@ -90,9 +95,6 @@ module API
helpers
::
API
::
Helpers
helpers
::
API
::
Helpers
::
CommonHelpers
NO_SLASH_URL_PART_REGEX
=
%r{[^/]+}
PROJECT_ENDPOINT_REQUIREMENTS
=
{
id:
NO_SLASH_URL_PART_REGEX
}.
freeze
# Keep in alphabetical order
mount
::
API
::
AccessRequests
mount
::
API
::
AwardEmoji
...
...
lib/api/entities.rb
View file @
c6d13e36
...
...
@@ -1090,5 +1090,18 @@ module API
expose
:failing_on_hosts
expose
:total_failures
end
class
GithubRepoOwner
<
Grape
::
Entity
expose
:id
expose
:login
do
|
project
|
project
.
namespace
&
.
name
end
end
class
GithubUserRepo
<
Grape
::
Entity
expose
:id
expose
:owner
,
using:
GithubRepoOwner
,
unless:
->
(
project
,
options
)
{
project
.
group
}
expose
:name
end
end
end
lib/api/v3/github_repos.rb
0 → 100644
View file @
c6d13e36
module
API
module
V3
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
:users
do
get
':namespace/repos'
do
present
[{
"id"
=>
11
,
"owner"
=>
{
"login"
=>
"oswaldo"
,
"id"
=>
1
,
},
"name"
=>
"test"
,
}]
end
end
resource
:repos
do
get
':namespace/:repo/branches'
do
present
[
{
"name"
=>
"feature"
,
"commit"
=>
{
"type"
=>
'commit'
,
"sha"
=>
"6367e27cc0928789a860676f560ceda6b41b6215"
}
}
]
end
get
':namespace/:repo/commits/:sha'
do
hash
=
{
"sha"
=>
"6367e27cc0928789a860676f560ceda6b41b6215"
,
"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-1 [1]"
,
},
"author"
=>
{
"login"
=>
"oswaldo"
,
"gravatar_id"
=>
""
,
},
"committer"
=>
{
"login"
=>
"oswaldo"
,
"gravatar_id"
=>
""
,
},
"parents"
=>
[
{
"sha"
=>
"357fb168fc667ef07a3303e4bb528fbcb2147430"
}
],
"files"
=>
[
{
"filename"
=>
"file1.txt"
,
"additions"
=>
10
,
"deletions"
=>
2
,
"changes"
=>
12
,
"status"
=>
"modified"
,
"patch"
=>
"@@ -29,7 +29,7 @@
\n
....."
}
]
}
present
hash
end
end
resource
:user
do
get
:repos
do
present
[]
end
end
end
end
end
lib/api/v3/users.rb
View file @
c6d13e36
...
...
@@ -64,6 +64,11 @@ module API
end
end
# desc ':org/repos' do
# Rails.logger.info("Requesting /users/#{params[:org]}/repos with params #{params}")
# Rails.logger.info("User: #{current_user.name}")
# end
desc
'Get the SSH keys of a specified user. Available only for admins.'
do
success
::
API
::
Entities
::
SSHKey
end
...
...
lib/gitlab/jira/middleware.rb
0 → 100644
View file @
c6d13e36
module
Gitlab
module
Jira
class
Middleware
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
return
@app
.
call
(
env
)
unless
/JIRA DVCS Connector/
.
match
(
env
[
'HTTP_USER_AGENT'
])
env
[
'HTTP_AUTHORIZATION'
]
=
env
[
'HTTP_AUTHORIZATION'
].
sub
(
'token'
,
'Bearer'
)
@app
.
call
(
env
)
end
end
end
end
spec/requests/api/v3/github_repos_spec.rb
0 → 100644
View file @
c6d13e36
require
'spec_helper'
describe
API
::
V3
::
GithubRepos
do
let
(
:user
)
{
create
(
:user
)
}
describe
'GET /orgs/:id/repos'
do
let
(
:current_user
)
{
user
}
it
'returns repos with expected format'
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
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
(
Array
)
expect
(
json_response
).
to
eq
(
''
)
end
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
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
(
Array
)
expect
(
json_response
).
to
eq
(
''
)
end
end
describe
'GET /repos/:namespace/:repo/commits/:sha'
do
it
'returns commit with expected format'
do
get
v3_api
(
"/repos/
#{
user
.
namespace
.
path
}
/foo/commits/sha123"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
(
Hash
)
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