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)",
|
||||
"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()
|
||||
if (schema_version + 1) not in schemes:
|
||||
return
|
||||
|
@ -26,6 +26,7 @@ class DBRevision:
|
||||
self.request_number,
|
||||
self.request_id,
|
||||
self.files_hash,
|
||||
self.api_url,
|
||||
) = row
|
||||
self.rev = float(self.rev)
|
||||
self._files = None
|
||||
@ -67,6 +68,7 @@ class DBRevision:
|
||||
"comment": self.comment,
|
||||
"broken": self.broken,
|
||||
"expanded_srcmd5": self.expanded_srcmd5,
|
||||
"api_url": self.api_url,
|
||||
"files_hash": self.files_hash,
|
||||
"files": self.files_list(),
|
||||
}
|
||||
@ -85,8 +87,8 @@ class DBRevision:
|
||||
def import_obs_rev(db: DB, revision: OBSRevision):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, commit_time, userid, comment, request_number)
|
||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s)""",
|
||||
"""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, %s)""",
|
||||
(
|
||||
revision.project,
|
||||
revision.package,
|
||||
@ -96,6 +98,7 @@ class DBRevision:
|
||||
revision.userid,
|
||||
revision.comment,
|
||||
revision.request_number,
|
||||
revision.obs.url,
|
||||
),
|
||||
)
|
||||
return DBRevision.fetch_revision(
|
||||
@ -104,6 +107,8 @@ class DBRevision:
|
||||
|
||||
@staticmethod
|
||||
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:
|
||||
cur.execute(
|
||||
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
||||
@ -267,8 +272,8 @@ class DBRevision:
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, expanded_srcmd5,
|
||||
commit_time, userid, comment, broken, files_hash)
|
||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id""",
|
||||
commit_time, userid, comment, broken, files_hash, api_url)
|
||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id""",
|
||||
(
|
||||
rev_dict["project"],
|
||||
rev_dict["package"],
|
||||
@ -280,6 +285,7 @@ class DBRevision:
|
||||
rev_dict["comment"],
|
||||
rev_dict["broken"],
|
||||
rev_dict["files_hash"],
|
||||
rev_dict.get("api_url", "https://api.opensuse.org"),
|
||||
),
|
||||
)
|
||||
rev_id = cur.fetchone()[0]
|
||||
|
@ -23,7 +23,6 @@ class Git:
|
||||
def is_open(self):
|
||||
return self.repo is not None
|
||||
|
||||
# TODO: Extend it to packages and files
|
||||
def exists(self):
|
||||
"""Check if the path is a valid git repository"""
|
||||
return (self.path / ".git").exists()
|
||||
|
@ -14,11 +14,9 @@ from lib.user import User
|
||||
|
||||
class GitExporter:
|
||||
def __init__(self, api_url, project, package, repodir, cachedir):
|
||||
self.obs = OBS()
|
||||
self.obs = OBS(api_url)
|
||||
self.project = project
|
||||
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.git = Git(
|
||||
repodir / package,
|
||||
@ -99,6 +97,7 @@ class GitExporter:
|
||||
)
|
||||
self.git.add_lfs(file.name, file_sha256["sha256"], size)
|
||||
else:
|
||||
self.obs.change_url(flat.commit.api_url)
|
||||
self.obs.download(
|
||||
flat.commit.project,
|
||||
flat.commit.package,
|
||||
|
@ -28,9 +28,8 @@ class Importer:
|
||||
self.project = project
|
||||
|
||||
self.db = DB()
|
||||
self.obs = OBS()
|
||||
self.obs = OBS(api_url)
|
||||
assert project == "openSUSE:Factory"
|
||||
self.obs.change_url(api_url)
|
||||
self.refreshed_packages = set()
|
||||
|
||||
def import_request(self, number):
|
||||
|
@ -59,11 +59,12 @@ osc.core.http_GET = retry(osc.core.http_GET)
|
||||
|
||||
|
||||
class OBS:
|
||||
def __init__(self, url=None):
|
||||
if url:
|
||||
def __init__(self, url):
|
||||
self.url = None
|
||||
self.change_url(url)
|
||||
|
||||
def change_url(self, url):
|
||||
if url != self.url:
|
||||
self.url = url
|
||||
osc.conf.get_config(override_apiurl=url)
|
||||
|
||||
|
@ -6,11 +6,14 @@ from lib.db_revision import DBRevision
|
||||
from lib.obs import OBS
|
||||
from lib.obs_revision import OBSRevision
|
||||
|
||||
# needs to exist in local oscrc (little tricky)
|
||||
API_URL = "https://api.opensuse.org"
|
||||
|
||||
|
||||
class TestDBMethods(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.db = DB(section="test")
|
||||
self.obs = OBS()
|
||||
self.obs = OBS(API_URL)
|
||||
|
||||
def test_import(self):
|
||||
test_rev = OBSRevision(self.obs, "openSUSE:Factory", "xz")
|
||||
@ -30,6 +33,7 @@ class TestDBMethods(unittest.TestCase):
|
||||
db_rev = DBRevision.fetch_revision(
|
||||
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))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user