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
47a84a7c
Commit
47a84a7c
authored
4 years ago
by
Eva Bardou
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add git_clone_url attribute on Repository serializer
parent
f43187ed
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/dataimport/serializers/git.py
+6
-4
6 additions, 4 deletions
arkindex/dataimport/serializers/git.py
arkindex/dataimport/tests/test_repos.py
+5
-5
5 additions, 5 deletions
arkindex/dataimport/tests/test_repos.py
with
11 additions
and
9 deletions
arkindex/dataimport/serializers/git.py
+
6
−
4
View file @
47a84a7c
...
...
@@ -3,6 +3,7 @@ from arkindex.project.serializer_fields import EnumField
from
arkindex.documents.models
import
Corpus
from
arkindex.dataimport.models
import
DataImport
,
Repository
,
Revision
,
GitRef
,
GitRefType
,
WorkerVersionState
import
gitlab.v4.objects
import
urllib
class
GitRefSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -68,11 +69,12 @@ class RepositorySerializer(serializers.ModelSerializer):
Serialize a repository
"""
enabled
=
serializers
.
BooleanField
(
read_only
=
True
)
git
lab_token
=
serializers
.
SerializerMethodField
()
git
_clone_url
=
serializers
.
SerializerMethodField
()
def
get_git
lab_token
(
self
,
repository
):
def
get_git
_clone_url
(
self
,
repository
):
if
self
.
context
[
'
request
'
].
user
.
is_internal
and
isinstance
(
self
.
instance
,
Repository
)
and
self
.
instance
.
enabled
:
return
repository
.
credentials
.
token
url
=
urllib
.
parse
.
urlparse
(
self
.
instance
.
url
)
return
f
"
https://oauth2:
{
repository
.
credentials
.
token
}
@
{
url
.
netloc
}{
url
.
path
}
"
return
None
class
Meta
:
...
...
@@ -82,7 +84,7 @@ class RepositorySerializer(serializers.ModelSerializer):
'
url
'
,
'
enabled
'
,
'
corpus
'
,
'
git
lab_token
'
,
'
git
_clone_url
'
,
)
extra_kwargs
=
{
'
id
'
:
{
'
read_only
'
:
True
},
...
...
This diff is collapsed.
Click to expand it.
arkindex/dataimport/tests/test_repos.py
+
5
−
5
View file @
47a84a7c
...
...
@@ -77,7 +77,7 @@ class TestRepositories(FixtureTestCase):
'
id
'
:
str
(
self
.
repo
.
id
),
'
corpus
'
:
str
(
self
.
repo
.
corpus
.
id
),
'
enabled
'
:
True
,
'
git
lab_token
'
:
None
,
'
git
_clone_url
'
:
None
,
'
url
'
:
self
.
repo
.
url
,
})
...
...
@@ -91,7 +91,7 @@ class TestRepositories(FixtureTestCase):
'
id
'
:
str
(
self
.
repo
.
id
),
'
corpus
'
:
str
(
self
.
repo
.
corpus
.
id
),
'
enabled
'
:
True
,
'
git
lab_token
'
:
None
,
'
git
_clone_url
'
:
None
,
'
url
'
:
self
.
repo
.
url
,
})
...
...
@@ -121,7 +121,7 @@ class TestRepositories(FixtureTestCase):
'
id
'
:
str
(
self
.
repo
.
id
),
'
corpus
'
:
str
(
self
.
repo
.
corpus
.
id
),
'
enabled
'
:
True
,
'
git
lab_token
'
:
None
,
'
git
_clone_url
'
:
None
,
'
url
'
:
self
.
repo
.
url
,
})
...
...
@@ -136,7 +136,7 @@ class TestRepositories(FixtureTestCase):
'
id
'
:
str
(
self
.
repo
.
id
),
'
corpus
'
:
str
(
self
.
repo
.
corpus
.
id
),
'
enabled
'
:
True
,
'
git
lab_token
'
:
'
oauth-token
'
,
'
git
_clone_url
'
:
'
https://oauth2:oauth-token@gitlab/repo
'
,
'
url
'
:
self
.
repo
.
url
,
})
...
...
@@ -157,7 +157,7 @@ class TestRepositories(FixtureTestCase):
'
id
'
:
str
(
self
.
repo
.
id
),
'
corpus
'
:
str
(
self
.
repo
.
corpus
.
id
),
'
enabled
'
:
False
,
'
git
lab_token
'
:
None
,
'
git
_clone_url
'
:
None
,
'
url
'
:
self
.
repo
.
url
,
})
...
...
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