gitlab: implement project export
This commit is contained in:
parent
c3bcdbebf9
commit
23f3969e75
|
@ -101,6 +101,27 @@ class GitLab(object):
|
||||||
else:
|
else:
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
def project_export(self, namespace, project, filename):
|
||||||
|
url = f'{self.s.api}/projects/{namespace}%2F{project}/export'
|
||||||
|
r = self.s.post(url)
|
||||||
|
assert r.status_code == 202, f'{r.status_code} {r.text}'
|
||||||
|
|
||||||
|
while True:
|
||||||
|
r = self.s.get(url)
|
||||||
|
r.raise_for_status()
|
||||||
|
status = r.json()["export_status"]
|
||||||
|
logger.info(f"waiting {namespace}/{project} export: status is {status}")
|
||||||
|
if status == "finished":
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
logger.info(f"download {namespace}/{project} into {filename}")
|
||||||
|
with self.s.get(f'{url}/download', stream=True) as r:
|
||||||
|
r.raise_for_status()
|
||||||
|
with open(filename, 'wb') as f:
|
||||||
|
for chunk in r.iter_content(chunk_size=8192):
|
||||||
|
f.write(chunk)
|
||||||
|
return True
|
||||||
|
|
||||||
def create_api_application(self, domain):
|
def create_api_application(self, domain):
|
||||||
callbacks = [
|
callbacks = [
|
||||||
f'https://api.{domain}/accounts/gitlab/login/callback/',
|
f'https://api.{domain}/accounts/gitlab/login/callback/',
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
import gzip
|
||||||
|
|
||||||
from fedeproxy.common.gitlab import GitLab
|
from fedeproxy.common.gitlab import GitLab
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gitlab
|
@pytest.mark.gitlab
|
||||||
def test_create_project(tmpdir):
|
def test_project_create():
|
||||||
ip = os.environ.get('FEDEPROXY_IP', '0.0.0.0')
|
ip = os.environ.get('FEDEPROXY_IP', '0.0.0.0')
|
||||||
gitlab = GitLab(f'http://{ip}:8181')
|
gitlab = GitLab(f'http://{ip}:8181')
|
||||||
gitlab.login('root', 'Wrobyak4')
|
gitlab.login('root', 'Wrobyak4')
|
||||||
|
@ -13,3 +14,15 @@ def test_create_project(tmpdir):
|
||||||
assert gitlab.project_get('root', 'testproject') is None
|
assert gitlab.project_get('root', 'testproject') is None
|
||||||
p = gitlab.project_create('root', 'testproject')
|
p = gitlab.project_create('root', 'testproject')
|
||||||
assert p['id'] == gitlab.project_create('root', 'testproject')['id']
|
assert p['id'] == gitlab.project_create('root', 'testproject')['id']
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.gitlab
|
||||||
|
def test_project_export(tmpdir):
|
||||||
|
ip = os.environ.get('FEDEPROXY_IP', '0.0.0.0')
|
||||||
|
gitlab = GitLab(f'http://{ip}:8181')
|
||||||
|
gitlab.login('root', 'Wrobyak4')
|
||||||
|
gitlab.project_delete('root', 'testproject')
|
||||||
|
gitlab.project_create('root', 'testproject')
|
||||||
|
exported = f'{tmpdir}/testproject.zip'
|
||||||
|
gitlab.project_export('root', 'testproject', exported)
|
||||||
|
assert gzip.open(exported)
|
||||||
|
|
Loading…
Reference in New Issue