Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
0
Merge Requests
0
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-shell
Commits
09e48144
Commit
09e48144
authored
Feb 10, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use api/v4 for gitaly notification and add tests
parent
b98d59ac
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
12 deletions
+79
-12
lib/gitlab_net.rb
lib/gitlab_net.rb
+13
-9
spec/gitlab_net_spec.rb
spec/gitlab_net_spec.rb
+22
-3
spec/vcr_cassettes/notify-post-receive.yml
spec/vcr_cassettes/notify-post-receive.yml
+44
-0
No files found.
lib/gitlab_net.rb
View file @
09e48144
...
@@ -32,7 +32,7 @@ class GitlabNet
...
@@ -32,7 +32,7 @@ class GitlabNet
params
.
merge!
(
user_id:
actor
.
gsub
(
"user-"
,
""
))
params
.
merge!
(
user_id:
actor
.
gsub
(
"user-"
,
""
))
end
end
url
=
"
#{
host
}
/allowed"
url
=
"
#{
host
_v3
}
/allowed"
resp
=
post
(
url
,
params
)
resp
=
post
(
url
,
params
)
if
resp
.
code
==
'200'
if
resp
.
code
==
'200'
...
@@ -44,7 +44,7 @@ class GitlabNet
...
@@ -44,7 +44,7 @@ class GitlabNet
def
discover
(
key
)
def
discover
(
key
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
resp
=
get
(
"
#{
host
}
/discover?key_id=
#{
key_id
}
"
)
resp
=
get
(
"
#{
host
_v3
}
/discover?key_id=
#{
key_id
}
"
)
JSON
.
parse
(
resp
.
body
)
rescue
nil
JSON
.
parse
(
resp
.
body
)
rescue
nil
end
end
...
@@ -54,7 +54,7 @@ class GitlabNet
...
@@ -54,7 +54,7 @@ class GitlabNet
key_id:
key
.
gsub
(
'key-'
,
''
)
key_id:
key
.
gsub
(
'key-'
,
''
)
}
}
resp
=
post
(
"
#{
host
}
/lfs_authenticate"
,
params
)
resp
=
post
(
"
#{
host
_v3
}
/lfs_authenticate"
,
params
)
if
resp
.
code
==
'200'
if
resp
.
code
==
'200'
GitlabLfsAuthentication
.
build_from_json
(
resp
.
body
)
GitlabLfsAuthentication
.
build_from_json
(
resp
.
body
)
...
@@ -62,23 +62,23 @@ class GitlabNet
...
@@ -62,23 +62,23 @@ class GitlabNet
end
end
def
broadcast_message
def
broadcast_message
resp
=
get
(
"
#{
host
}
/broadcast_message"
)
resp
=
get
(
"
#{
host
_v3
}
/broadcast_message"
)
JSON
.
parse
(
resp
.
body
)
rescue
{}
JSON
.
parse
(
resp
.
body
)
rescue
{}
end
end
def
merge_request_urls
(
repo_path
,
changes
)
def
merge_request_urls
(
repo_path
,
changes
)
changes
=
changes
.
join
(
"
\n
"
)
unless
changes
.
kind_of?
(
String
)
changes
=
changes
.
join
(
"
\n
"
)
unless
changes
.
kind_of?
(
String
)
changes
=
changes
.
encode
(
'UTF-8'
,
'ASCII'
,
invalid: :replace
,
replace:
''
)
changes
=
changes
.
encode
(
'UTF-8'
,
'ASCII'
,
invalid: :replace
,
replace:
''
)
resp
=
get
(
"
#{
host
}
/merge_request_urls?project=
#{
URI
.
escape
(
repo_path
)
}
&changes=
#{
URI
.
escape
(
changes
)
}
"
)
resp
=
get
(
"
#{
host
_v3
}
/merge_request_urls?project=
#{
URI
.
escape
(
repo_path
)
}
&changes=
#{
URI
.
escape
(
changes
)
}
"
)
JSON
.
parse
(
resp
.
body
)
rescue
[]
JSON
.
parse
(
resp
.
body
)
rescue
[]
end
end
def
check
def
check
get
(
"
#{
host
}
/check"
,
read_timeout:
CHECK_TIMEOUT
)
get
(
"
#{
host
_v3
}
/check"
,
read_timeout:
CHECK_TIMEOUT
)
end
end
def
authorized_key
(
key
)
def
authorized_key
(
key
)
resp
=
get
(
"
#{
host
}
/authorized_keys?key=
#{
URI
.
escape
(
key
,
'+/='
)
}
"
)
resp
=
get
(
"
#{
host
_v3
}
/authorized_keys?key=
#{
URI
.
escape
(
key
,
'+/='
)
}
"
)
JSON
.
parse
(
resp
.
body
)
if
resp
.
code
==
"200"
JSON
.
parse
(
resp
.
body
)
if
resp
.
code
==
"200"
rescue
rescue
nil
nil
...
@@ -86,7 +86,7 @@ class GitlabNet
...
@@ -86,7 +86,7 @@ class GitlabNet
def
two_factor_recovery_codes
(
key
)
def
two_factor_recovery_codes
(
key
)
key_id
=
key
.
gsub
(
'key-'
,
''
)
key_id
=
key
.
gsub
(
'key-'
,
''
)
resp
=
post
(
"
#{
host
}
/two_factor_recovery_codes"
,
key_id:
key_id
)
resp
=
post
(
"
#{
host
_v3
}
/two_factor_recovery_codes"
,
key_id:
key_id
)
JSON
.
parse
(
resp
.
body
)
if
resp
.
code
==
'200'
JSON
.
parse
(
resp
.
body
)
if
resp
.
code
==
'200'
rescue
rescue
...
@@ -135,10 +135,14 @@ class GitlabNet
...
@@ -135,10 +135,14 @@ class GitlabNet
@config
||=
GitlabConfig
.
new
@config
||=
GitlabConfig
.
new
end
end
def
host
def
host
_v3
"
#{
config
.
gitlab_url
}
/api/v3/internal"
"
#{
config
.
gitlab_url
}
/api/v3/internal"
end
end
def
host
"
#{
config
.
gitlab_url
}
/api/v4/internal"
end
def
http_client_for
(
uri
,
options
=
{})
def
http_client_for
(
uri
,
options
=
{})
if
uri
.
is_a?
(
URI
::
HTTPUNIX
)
if
uri
.
is_a?
(
URI
::
HTTPUNIX
)
http
=
Net
::
HTTPUNIX
.
new
(
uri
.
hostname
)
http
=
Net
::
HTTPUNIX
.
new
(
uri
.
hostname
)
...
...
spec/gitlab_net_spec.rb
View file @
09e48144
...
@@ -8,7 +8,8 @@ describe GitlabNet, vcr: true do
...
@@ -8,7 +8,8 @@ describe GitlabNet, vcr: true do
let
(
:changes
)
{
[
'0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'
]
}
let
(
:changes
)
{
[
'0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'
]
}
before
do
before
do
gitlab_net
.
stub
(
:host
).
and_return
(
'https://dev.gitlab.org/api/v3/internal'
)
gitlab_net
.
stub
(
:host_v3
).
and_return
(
'https://dev.gitlab.org/api/v3/internal'
)
gitlab_net
.
stub
(
:host
).
and_return
(
'https://dev.gitlab.org/api/v4/internal'
)
gitlab_net
.
stub
(
:secret_token
).
and_return
(
'a123'
)
gitlab_net
.
stub
(
:secret_token
).
and_return
(
'a123'
)
end
end
...
@@ -138,6 +139,16 @@ describe GitlabNet, vcr: true do
...
@@ -138,6 +139,16 @@ describe GitlabNet, vcr: true do
end
end
end
end
describe
'#notify_post_receive'
do
let
(
:repo_path
)
{
'/path/to/my/repo.git'
}
it
'returns true if notification was succesful'
do
VCR
.
use_cassette
(
'notify-post-receive'
)
do
expect
(
gitlab_net
.
notify_post_receive
(
repo_path
)).
to
be_true
end
end
end
describe
:check_access
do
describe
:check_access
do
context
'ssh key with access to project'
do
context
'ssh key with access to project'
do
it
'should allow pull access for dev.gitlab.org'
do
it
'should allow pull access for dev.gitlab.org'
do
...
@@ -233,6 +244,14 @@ describe GitlabNet, vcr: true do
...
@@ -233,6 +244,14 @@ describe GitlabNet, vcr: true do
let
(
:net
)
{
GitlabNet
.
new
}
let
(
:net
)
{
GitlabNet
.
new
}
subject
{
net
.
send
:host
}
subject
{
net
.
send
:host
}
it
{
should
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
(
"uses API version 4"
)
{
should
include
(
"api/v4"
)
}
end
describe
:host_v3
do
let
(
:net
)
{
GitlabNet
.
new
}
subject
{
net
.
send
:host_v3
}
it
{
should
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
{
should
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
(
"uses API version 3"
)
{
should
include
(
"api/v3"
)
}
it
(
"uses API version 3"
)
{
should
include
(
"api/v3"
)
}
end
end
...
@@ -258,14 +277,14 @@ describe GitlabNet, vcr: true do
...
@@ -258,14 +277,14 @@ describe GitlabNet, vcr: true do
let
(
:password
)
{
'password'
}
let
(
:password
)
{
'password'
}
let
(
:url
)
{
URI
'http://localhost/'
}
let
(
:url
)
{
URI
'http://localhost/'
}
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
}
subject
{
gitlab_net
.
send
:http_request_for
,
:get
,
url
}
before
do
before
do
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'user'
)
{
user
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'password'
)
{
password
}
get
.
should_receive
(
:basic_auth
).
with
(
user
,
password
).
once
get
.
should_receive
(
:basic_auth
).
with
(
user
,
password
).
once
get
.
should_receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
'a123'
)).
once
get
.
should_receive
(
:set_form_data
).
with
(
hash_including
(
secret_token:
'a123'
)).
once
end
end
it
{
should_not
be_nil
}
it
{
should_not
be_nil
}
end
end
...
...
spec/vcr_cassettes/notify-post-receive.yml
0 → 100644
View file @
09e48144
---
http_interactions
:
-
request
:
method
:
post
uri
:
https://dev.gitlab.org/api/v4/internal/notify_post_receive
body
:
encoding
:
US-ASCII
string
:
repo_path=%2Fpath%2Fto%2Fmy%2Frepo.git&secret_token=a123
headers
:
Accept-Encoding
:
-
gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept
:
-
"
*/*"
User-Agent
:
-
Ruby
Content-Type
:
-
application/x-www-form-urlencoded
response
:
status
:
code
:
200
message
:
OK
headers
:
Cache-Control
:
-
max-age=0, private, must-revalidate
Content-Length
:
-
'
2'
Content-Type
:
-
application/json
Date
:
-
Fri, 10 Feb 2017 17:06:53 GMT
Etag
:
-
W/"99914b932bd37a50b983c5e7c90ae93b"
Vary
:
-
Origin
X-Request-Id
:
-
cfefede6-9400-4ca5-a61d-2a519405295c
X-Runtime
:
-
'
20.623406'
body
:
encoding
:
UTF-8
string
:
"
{}"
http_version
:
recorded_at
:
Fri, 10 Feb 2017 17:06:53 GMT
recorded_with
:
VCR 2.4.0
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