Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Rob Jennings
git-export-import
Commits
dbededea
Commit
dbededea
authored
4 months ago
by
Rob Jennings
Browse files
Options
Download
Email Patches
Plain Diff
Added paging to variables/environments call
parent
cc98eef2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
20 deletions
+31
-20
git_migration/project_migration.py
git_migration/project_migration.py
+31
-20
No files found.
git_migration/project_migration.py
View file @
dbededea
...
...
@@ -84,29 +84,40 @@ class ProjectExportImport:
def
get_ci_variables
(
self
)
->
list
:
"""Getter for the CI/CD variables of the project."""
resp
=
requests
.
get
(
f
"
{
self
.
get_project_url
()
}
/variables"
,
headers
=
self
.
get_headers
(
self
.
source_token
),
)
data
=
resp
.
json
()
# Returns all CI/CD variables except for "id".
return
[{
key
:
value
for
key
,
value
in
variable
.
items
()
if
key
!=
"id"
}
for
variable
in
data
]
variables
=
[]
next_url
=
f
"
{
self
.
get_project_url
()
}
/variables?page=1&per_page=100"
while
next_url
is
not
None
:
print
(
"Getting: "
,
next_url
)
resp
=
requests
.
get
(
next_url
,
headers
=
self
.
get_headers
(
self
.
source_token
))
# Returns all CI/CD variables except for "id" key. (Not needed for variables POST api).
variables
.
extend
(
[
{
key
:
value
for
key
,
value
in
variable
.
items
()
if
key
!=
"id"
}
for
variable
in
resp
.
json
()
]
)
next_url
=
resp
.
links
[
"next"
][
"url"
]
if
"next"
in
resp
.
links
else
None
return
variables
def
get_environments
(
self
)
->
list
:
"""Getter for the project's environments. I.e. name, slug, desc, etc."""
resp
=
requests
.
get
(
f
"
{
self
.
get_project_url
()
}
/environments"
,
headers
=
self
.
get_headers
(
self
.
source_token
),
)
data
=
resp
.
json
()
return
[
{
"name"
:
env
[
"name"
],
"description"
:
env
.
get
(
"description"
,
None
),
"external_url"
:
env
[
"external_url"
],
}
for
env
in
data
]
environments
=
[]
next_url
=
f
"
{
self
.
get_project_url
()
}
/environments?page=1&per_page=100"
while
next_url
is
not
None
:
print
(
"Getting: "
,
next_url
)
resp
=
requests
.
get
(
next_url
,
headers
=
self
.
get_headers
(
self
.
source_token
))
# Returns required data for the environments POST api for each environment.
environments
.
extend
(
[
{
"name"
:
env
[
"name"
],
"description"
:
env
.
get
(
"description"
,
None
),
"external_url"
:
env
[
"external_url"
],
}
for
env
in
resp
.
json
()
]
)
next_url
=
resp
.
links
[
"next"
][
"url"
]
if
"next"
in
resp
.
links
else
None
return
environments
def
request_export_project
(
self
)
->
None
:
"""Exports the project via the API call."""
...
...
This diff is collapsed.
Click to expand it.
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