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
cbb541ad
Commit
cbb541ad
authored
Mar 18, 2022
by
Jaime Martinez
Committed by
David Fernandez
Mar 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle 404 responses from the container registry import status API
parent
435ea6c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
13 deletions
+29
-13
lib/container_registry/gitlab_api_client.rb
lib/container_registry/gitlab_api_client.rb
+8
-2
spec/lib/container_registry/gitlab_api_client_spec.rb
spec/lib/container_registry/gitlab_api_client_spec.rb
+21
-11
No files found.
lib/container_registry/gitlab_api_client.rb
View file @
cbb541ad
...
@@ -53,8 +53,14 @@ module ContainerRegistry
...
@@ -53,8 +53,14 @@ module ContainerRegistry
# https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-import-status
# https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-import-status
def
import_status
(
path
)
def
import_status
(
path
)
with_import_token_faraday
do
|
faraday_client
|
with_import_token_faraday
do
|
faraday_client
|
body_hash
=
response_body
(
faraday_client
.
get
(
import_url_for
(
path
)))
response
=
faraday_client
.
get
(
import_url_for
(
path
))
body_hash
[
'status'
]
||
'error'
# Temporary solution for https://gitlab.com/gitlab-org/gitlab/-/issues/356085#solutions
# this will trigger a `retry_pre_import`
break
'pre_import_failed'
unless
response
.
success?
body_hash
=
response_body
(
response
)
body_hash
&
.
fetch
(
'status'
)
||
'error'
end
end
end
end
...
...
spec/lib/container_registry/gitlab_api_client_spec.rb
View file @
cbb541ad
...
@@ -107,20 +107,30 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
...
@@ -107,20 +107,30 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
describe
'#import_status'
do
describe
'#import_status'
do
subject
{
client
.
import_status
(
path
)
}
subject
{
client
.
import_status
(
path
)
}
before
do
context
'with successful response'
do
stub_import_status
(
path
,
status
)
before
do
end
stub_import_status
(
path
,
status
)
end
context
'with a status'
do
let
(
:status
)
{
'this_is_a_test'
}
it
{
is_expected
.
to
eq
(
status
)
}
end
context
'with a
status'
do
context
'with no
status'
do
let
(
:status
)
{
'this_is_a_test'
}
let
(
:status
)
{
nil
}
it
{
is_expected
.
to
eq
(
status
)
}
it
{
is_expected
.
to
eq
(
'error'
)
}
end
end
end
context
'with no status'
do
context
'with non successful response'
do
let
(
:status
)
{
nil
}
before
do
stub_import_status
(
path
,
nil
,
status_code:
404
)
end
it
{
is_expected
.
to
eq
(
'
error
'
)
}
it
{
is_expected
.
to
eq
(
'
pre_import_failed
'
)
}
end
end
end
end
...
@@ -230,11 +240,11 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
...
@@ -230,11 +240,11 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
.
to_return
(
status:
status_code
,
body:
''
)
.
to_return
(
status:
status_code
,
body:
''
)
end
end
def
stub_import_status
(
path
,
status
)
def
stub_import_status
(
path
,
status
,
status_code:
200
)
stub_request
(
:get
,
"
#{
registry_api_url
}
/gitlab/v1/import/
#{
path
}
/"
)
stub_request
(
:get
,
"
#{
registry_api_url
}
/gitlab/v1/import/
#{
path
}
/"
)
.
with
(
headers:
{
'Accept'
=>
described_class
::
JSON_TYPE
,
'Authorization'
=>
"bearer
#{
import_token
}
"
})
.
with
(
headers:
{
'Accept'
=>
described_class
::
JSON_TYPE
,
'Authorization'
=>
"bearer
#{
import_token
}
"
})
.
to_return
(
.
to_return
(
status:
200
,
status:
status_code
,
body:
{
status:
status
}.
to_json
,
body:
{
status:
status
}.
to_json
,
headers:
{
content_type:
'application/json'
}
headers:
{
content_type:
'application/json'
}
)
)
...
...
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