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
0aa920a9
Commit
0aa920a9
authored
4 years ago
by
Valentin Rigal
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Limit max GitRef and DataImport name fields from Gitlab provider
parent
9cb44bfb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1272
Limit max GitRef and DataImport name fields from Gitlab provider
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/dataimport/providers.py
+4
-2
4 additions, 2 deletions
arkindex/dataimport/providers.py
arkindex/dataimport/tests/test_gitlab_provider.py
+6
-3
6 additions, 3 deletions
arkindex/dataimport/tests/test_gitlab_provider.py
with
10 additions
and
5 deletions
arkindex/dataimport/providers.py
+
4
−
2
View file @
0aa920a9
...
...
@@ -69,7 +69,8 @@ class GitProvider(ABC):
ref
.
revision
=
revision
ref
.
save
()
except
GitRef
.
DoesNotExist
:
repo
.
refs
.
create
(
name
=
name
,
type
=
type
,
revision
=
revision
)
# Limit the name length to the max size of GitRef name field
repo
.
refs
.
create
(
name
=
name
[:
250
],
type
=
type
,
revision
=
revision
)
def
get_or_create_revision
(
self
,
repo
,
sha
,
save
=
True
):
from
arkindex.dataimport.models
import
Revision
...
...
@@ -111,7 +112,8 @@ class GitProvider(ABC):
refs
=
"
,
"
.
join
(
rev
.
refs
.
values_list
(
'
name
'
,
flat
=
True
))
if
not
refs
:
refs
=
rev
.
hash
name
=
f
"
Import
{
refs
}
from
{
rev
.
repo
.
url
}
"
# Limit the name length to the max size of DataImport name field
name
=
f
"
Import
{
refs
}
from
{
rev
.
repo
.
url
}
"
[:
100
]
if
rev
.
repo
.
type
==
RepositoryType
.
Worker
:
# Build revision workers in a new process
...
...
This diff is collapsed.
Click to expand it.
arkindex/dataimport/tests/test_gitlab_provider.py
+
6
−
3
View file @
0aa920a9
...
...
@@ -583,7 +583,8 @@ class TestGitLabProvider(FixtureTestCase):
# Add 2 commits on 2 branches
self
.
gl_mock
().
projects
.
get
.
return_value
.
branches
.
list
=
lambda
:
[
Ref
(
"
master
"
,
{
"
id
"
:
"
commit1
"
,
"
message
"
:
"
A commit on master
"
,
"
author_email
"
:
"
someone@teklia.com
"
}),
Ref
(
"
killer-feature
"
,
{
"
id
"
:
"
commit2
"
,
"
message
"
:
"
My fancy feature
"
,
"
author_email
"
:
"
another@teklia.com
"
})
# Create a commit with a very long branch name
Ref
(
"
A
"
*
1000
,
{
"
id
"
:
"
commit2
"
,
"
message
"
:
"
My fancy feature
"
,
"
author_email
"
:
"
another@teklia.com
"
})
]
# Add 1 new commit on a tag, and reuse a commit on another tag
...
...
@@ -623,7 +624,8 @@ class TestGitLabProvider(FixtureTestCase):
(
'
v0.1
'
,
GitRefType
.
Tag
),
])
self
.
assertListEqual
(
list
(
commit2
.
refs
.
values_list
(
'
name
'
,
'
type
'
).
order_by
(
'
name
'
)),
[
(
'
killer-feature
'
,
GitRefType
.
Branch
),
# Name has been restricted to 250 chars due to GitRef model constraint
(
'
A
'
*
250
,
GitRefType
.
Branch
),
])
# We should now have 3 dataimport for these refs
...
...
@@ -631,5 +633,6 @@ class TestGitLabProvider(FixtureTestCase):
self
.
assertListEqual
(
list
(
DataImport
.
objects
.
values_list
(
'
name
'
,
'
mode
'
,
'
revision__hash
'
).
order_by
(
'
revision__hash
'
)),
[
(
"
Import v0.1 from http://gitlab/repo
"
,
DataImportMode
.
Repository
,
'
commit0
'
),
(
"
Import master from http://gitlab/repo
"
,
DataImportMode
.
Repository
,
'
commit1
'
),
(
"
Import killer-feature from http://gitlab/repo
"
,
DataImportMode
.
Repository
,
'
commit2
'
),
# Last import name has been limited to 100 chars due to DataImport model constraint
(
f
"
Import
{
'
A
'
*
93
}
"
,
DataImportMode
.
Repository
,
'
commit2
'
),
])
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