Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
811e2416
Commit
811e2416
authored
3 years ago
by
Eva Bardou
Committed by
Erwan Rouchet
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle branch deletion during GitLab webhook
parent
4039015f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1342
Handle branch deletion during GitLab webhook
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/dataimport/providers.py
+10
-1
10 additions, 1 deletion
arkindex/dataimport/providers.py
arkindex/dataimport/tests/test_gitlab_provider.py
+33
-8
33 additions, 8 deletions
arkindex/dataimport/tests/test_gitlab_provider.py
with
43 additions
and
9 deletions
arkindex/dataimport/providers.py
+
10
−
1
View file @
811e2416
...
...
@@ -394,7 +394,16 @@ class GitLabProvider(GitProvider):
return
if
not
sha
:
raise
ValidationError
(
'
Missing checkout SHA
'
)
# If there isn't any SHA it means that a branch was deleted
ref
=
request
.
data
.
get
(
'
ref
'
)
if
not
ref
:
raise
ValidationError
(
'
Missing branch reference
'
)
# Delete existing branch
branch_name
=
ref
[
11
:]
if
ref
.
startswith
(
'
refs/heads/
'
)
else
ref
repo
.
refs
.
filter
(
name
=
branch_name
,
type
=
GitRefType
.
Branch
).
delete
()
return
# Already took care of this event
if
repo
.
revisions
.
filter
(
hash
=
sha
).
exists
():
...
...
This diff is collapsed.
Click to expand it.
arkindex/dataimport/tests/test_gitlab_provider.py
+
33
−
8
View file @
811e2416
...
...
@@ -484,14 +484,6 @@ class TestGitLabProvider(FixtureTestCase):
self
.
assertFalse
(
rev
.
exists
())
self
.
assertFalse
(
repo_imports
.
exists
())
# Missing SHA
request_mock
.
data
[
'
object_kind
'
]
=
'
push
'
del
request_mock
.
data
[
'
checkout_sha
'
]
with
self
.
assertRaises
(
ValidationError
):
glp
.
handle_webhook
(
self
.
repo
,
request_mock
)
self
.
assertFalse
(
rev
.
exists
())
self
.
assertFalse
(
repo_imports
.
exists
())
# Breaking change: a list!
request_mock
.
data
=
[
request_mock
.
data
]
with
self
.
assertRaises
(
ValidationError
):
...
...
@@ -499,6 +491,39 @@ class TestGitLabProvider(FixtureTestCase):
self
.
assertFalse
(
rev
.
exists
())
self
.
assertFalse
(
repo_imports
.
exists
())
def
test_handle_webhook_delete_branch
(
self
):
"""
Test GitLabProvider properly handles a branch deletion
"""
rev
=
Revision
(
repo
=
self
.
repo
,
hash
=
'
1
'
,
message
=
'
commit message
'
,
author
=
'
bob
'
,
)
rev
.
save
()
self
.
assertTrue
(
self
.
repo
.
revisions
.
filter
(
hash
=
'
1
'
).
exists
())
repo_imports
=
DataImport
.
objects
.
filter
(
revision__repo_id
=
str
(
self
.
repo
.
id
))
glp
=
GitLabProvider
(
url
=
'
http://aaa
'
,
credentials
=
self
.
creds
)
glp
.
update_or_create_ref
(
self
.
repo
,
rev
,
'
test
'
,
GitRefType
.
Branch
)
self
.
assertEqual
(
len
(
self
.
repo
.
refs
.
all
()),
1
)
request_mock
=
MagicMock
()
request_mock
.
META
=
{
'
HTTP_X_GITLAB_EVENT
'
:
'
Push Hook
'
,
'
HTTP_X_GITLAB_TOKEN
'
:
'
hook-token
'
,
}
request_mock
.
data
=
{
'
object_kind
'
:
'
push
'
,
'
ref
'
:
'
refs/heads/test
'
,
'
commits
'
:
[]
}
glp
.
handle_webhook
(
self
.
repo
,
request_mock
)
self
.
assertTrue
(
self
.
repo
.
revisions
.
filter
(
hash
=
'
1
'
).
exists
())
self
.
assertEqual
(
len
(
self
.
repo
.
refs
.
all
()),
0
)
self
.
assertFalse
(
repo_imports
.
exists
())
def
test_retrieve_repo_type
(
self
):
"""
Gitlab provider allow to retrieve a project type
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment