forked from adamm/git-importer
Store API URL in the revision table
Will be important once we get into SLE
This commit is contained in:
parent
f1457e8f8e
commit
5ae02a413d
@ -215,6 +215,12 @@ class DB:
|
|||||||
"CREATE INDEX ON linked_revs(considered)",
|
"CREATE INDEX ON linked_revs(considered)",
|
||||||
"UPDATE scheme SET version=20",
|
"UPDATE scheme SET version=20",
|
||||||
)
|
)
|
||||||
|
schemes[21] = (
|
||||||
|
"ALTER TABLE revisions ADD COLUMN api_url VARCHAR(40)",
|
||||||
|
"UPDATE revisions SET api_url='https://api.opensuse.org'",
|
||||||
|
"ALTER TABLE revisions ALTER COLUMN api_url SET NOT NULL",
|
||||||
|
"UPDATE scheme SET version=21",
|
||||||
|
)
|
||||||
schema_version = self.schema_version()
|
schema_version = self.schema_version()
|
||||||
if (schema_version + 1) not in schemes:
|
if (schema_version + 1) not in schemes:
|
||||||
return
|
return
|
||||||
|
@ -26,6 +26,7 @@ class DBRevision:
|
|||||||
self.request_number,
|
self.request_number,
|
||||||
self.request_id,
|
self.request_id,
|
||||||
self.files_hash,
|
self.files_hash,
|
||||||
|
self.api_url,
|
||||||
) = row
|
) = row
|
||||||
self.rev = float(self.rev)
|
self.rev = float(self.rev)
|
||||||
self._files = None
|
self._files = None
|
||||||
@ -67,6 +68,7 @@ class DBRevision:
|
|||||||
"comment": self.comment,
|
"comment": self.comment,
|
||||||
"broken": self.broken,
|
"broken": self.broken,
|
||||||
"expanded_srcmd5": self.expanded_srcmd5,
|
"expanded_srcmd5": self.expanded_srcmd5,
|
||||||
|
"api_url": self.api_url,
|
||||||
"files_hash": self.files_hash,
|
"files_hash": self.files_hash,
|
||||||
"files": self.files_list(),
|
"files": self.files_list(),
|
||||||
}
|
}
|
||||||
@ -85,8 +87,8 @@ class DBRevision:
|
|||||||
def import_obs_rev(db: DB, revision: OBSRevision):
|
def import_obs_rev(db: DB, revision: OBSRevision):
|
||||||
with db.cursor() as cur:
|
with db.cursor() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, commit_time, userid, comment, request_number)
|
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, commit_time, userid, comment, request_number, api_url)
|
||||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s)""",
|
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)""",
|
||||||
(
|
(
|
||||||
revision.project,
|
revision.project,
|
||||||
revision.package,
|
revision.package,
|
||||||
@ -96,6 +98,7 @@ class DBRevision:
|
|||||||
revision.userid,
|
revision.userid,
|
||||||
revision.comment,
|
revision.comment,
|
||||||
revision.request_number,
|
revision.request_number,
|
||||||
|
revision.obs.url,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return DBRevision.fetch_revision(
|
return DBRevision.fetch_revision(
|
||||||
@ -104,6 +107,8 @@ class DBRevision:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch_revision(db, project, package, rev):
|
def fetch_revision(db, project, package, rev):
|
||||||
|
"""Technically we would need the api_url as well, but we assume projects are unique
|
||||||
|
(e.g. not importing SLE from obs)"""
|
||||||
with db.cursor() as cur:
|
with db.cursor() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
||||||
@ -266,9 +271,9 @@ class DBRevision:
|
|||||||
"""Used in test cases to read a revision from fixtures into the test database"""
|
"""Used in test cases to read a revision from fixtures into the test database"""
|
||||||
with db.cursor() as cur:
|
with db.cursor() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, expanded_srcmd5,
|
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, expanded_srcmd5,
|
||||||
commit_time, userid, comment, broken, files_hash)
|
commit_time, userid, comment, broken, files_hash, api_url)
|
||||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id""",
|
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id""",
|
||||||
(
|
(
|
||||||
rev_dict["project"],
|
rev_dict["project"],
|
||||||
rev_dict["package"],
|
rev_dict["package"],
|
||||||
@ -280,6 +285,7 @@ class DBRevision:
|
|||||||
rev_dict["comment"],
|
rev_dict["comment"],
|
||||||
rev_dict["broken"],
|
rev_dict["broken"],
|
||||||
rev_dict["files_hash"],
|
rev_dict["files_hash"],
|
||||||
|
rev_dict.get("api_url", "https://api.opensuse.org"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
rev_id = cur.fetchone()[0]
|
rev_id = cur.fetchone()[0]
|
||||||
|
@ -23,7 +23,6 @@ class Git:
|
|||||||
def is_open(self):
|
def is_open(self):
|
||||||
return self.repo is not None
|
return self.repo is not None
|
||||||
|
|
||||||
# TODO: Extend it to packages and files
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
"""Check if the path is a valid git repository"""
|
"""Check if the path is a valid git repository"""
|
||||||
return (self.path / ".git").exists()
|
return (self.path / ".git").exists()
|
||||||
|
@ -14,11 +14,9 @@ from lib.user import User
|
|||||||
|
|
||||||
class GitExporter:
|
class GitExporter:
|
||||||
def __init__(self, api_url, project, package, repodir, cachedir):
|
def __init__(self, api_url, project, package, repodir, cachedir):
|
||||||
self.obs = OBS()
|
self.obs = OBS(api_url)
|
||||||
self.project = project
|
self.project = project
|
||||||
self.package = package
|
self.package = package
|
||||||
# TODO: Store the api url in the revision
|
|
||||||
self.obs.change_url(api_url)
|
|
||||||
self.proxy_sha256 = ProxySHA256(self.obs, enabled=True)
|
self.proxy_sha256 = ProxySHA256(self.obs, enabled=True)
|
||||||
self.git = Git(
|
self.git = Git(
|
||||||
repodir / package,
|
repodir / package,
|
||||||
@ -99,6 +97,7 @@ class GitExporter:
|
|||||||
)
|
)
|
||||||
self.git.add_lfs(file.name, file_sha256["sha256"], size)
|
self.git.add_lfs(file.name, file_sha256["sha256"], size)
|
||||||
else:
|
else:
|
||||||
|
self.obs.change_url(flat.commit.api_url)
|
||||||
self.obs.download(
|
self.obs.download(
|
||||||
flat.commit.project,
|
flat.commit.project,
|
||||||
flat.commit.package,
|
flat.commit.package,
|
||||||
|
@ -28,9 +28,8 @@ class Importer:
|
|||||||
self.project = project
|
self.project = project
|
||||||
|
|
||||||
self.db = DB()
|
self.db = DB()
|
||||||
self.obs = OBS()
|
self.obs = OBS(api_url)
|
||||||
assert project == "openSUSE:Factory"
|
assert project == "openSUSE:Factory"
|
||||||
self.obs.change_url(api_url)
|
|
||||||
self.refreshed_packages = set()
|
self.refreshed_packages = set()
|
||||||
|
|
||||||
def import_request(self, number):
|
def import_request(self, number):
|
||||||
|
11
lib/obs.py
11
lib/obs.py
@ -59,13 +59,14 @@ osc.core.http_GET = retry(osc.core.http_GET)
|
|||||||
|
|
||||||
|
|
||||||
class OBS:
|
class OBS:
|
||||||
def __init__(self, url=None):
|
def __init__(self, url):
|
||||||
if url:
|
self.url = None
|
||||||
self.change_url(url)
|
self.change_url(url)
|
||||||
|
|
||||||
def change_url(self, url):
|
def change_url(self, url):
|
||||||
self.url = url
|
if url != self.url:
|
||||||
osc.conf.get_config(override_apiurl=url)
|
self.url = url
|
||||||
|
osc.conf.get_config(override_apiurl=url)
|
||||||
|
|
||||||
def _xml(self, url_path, **params):
|
def _xml(self, url_path, **params):
|
||||||
url = osc.core.makeurl(self.url, [url_path], params)
|
url = osc.core.makeurl(self.url, [url_path], params)
|
||||||
|
@ -6,11 +6,14 @@ from lib.db_revision import DBRevision
|
|||||||
from lib.obs import OBS
|
from lib.obs import OBS
|
||||||
from lib.obs_revision import OBSRevision
|
from lib.obs_revision import OBSRevision
|
||||||
|
|
||||||
|
# needs to exist in local oscrc (little tricky)
|
||||||
|
API_URL = "https://api.opensuse.org"
|
||||||
|
|
||||||
|
|
||||||
class TestDBMethods(unittest.TestCase):
|
class TestDBMethods(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.db = DB(section="test")
|
self.db = DB(section="test")
|
||||||
self.obs = OBS()
|
self.obs = OBS(API_URL)
|
||||||
|
|
||||||
def test_import(self):
|
def test_import(self):
|
||||||
test_rev = OBSRevision(self.obs, "openSUSE:Factory", "xz")
|
test_rev = OBSRevision(self.obs, "openSUSE:Factory", "xz")
|
||||||
@ -30,6 +33,7 @@ class TestDBMethods(unittest.TestCase):
|
|||||||
db_rev = DBRevision.fetch_revision(
|
db_rev = DBRevision.fetch_revision(
|
||||||
self.db, project="openSUSE:Factory", package="xz", rev="70"
|
self.db, project="openSUSE:Factory", package="xz", rev="70"
|
||||||
)
|
)
|
||||||
|
self.assertEqual(db_rev.api_url, API_URL)
|
||||||
self.assertEqual(str(test_rev), str(db_rev))
|
self.assertEqual(str(test_rev), str(db_rev))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user