Skip to content

Commit

Permalink
frontend: support build-time dependencies from other storages
Browse files Browse the repository at this point in the history
Fix #3446

When a Copr defines a build-time dependency on `copr://foo/bar` and the
`foo/bar` project uses Pulp storage, the repository baseurl is now generated
correctly.
  • Loading branch information
FrostyX committed Oct 15, 2024
1 parent c8ff8d3 commit 62f0680
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
14 changes: 10 additions & 4 deletions frontend/coprs_frontend/coprs/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import posixpath
from urllib.parse import urlparse, parse_qs, urlunparse, urlencode
import flask
from sqlalchemy.orm.exc import NoResultFound
from coprs import app
from coprs.logic.coprs_logic import CoprDirsLogic


def generate_repo_url(mock_chroot, url, arch=None):
Expand Down Expand Up @@ -71,10 +73,14 @@ def pre_process_repo_url(chroot, repo_url):
if parsed_url.scheme == "copr":
user = parsed_url.netloc
prj = parsed_url.path.split("/")[1]
repo_url = "/".join([
flask.current_app.config["BACKEND_BASE_URL"],
"results", user, prj, chroot
]) + "/"
try:
coprdir = CoprDirsLogic.get_by_ownername(user, prj).one()
repo_url = "{0}/{1}/".format(coprdir.repo_url, chroot)
except NoResultFound:
repo_url = "/".join([
flask.current_app.config["BACKEND_BASE_URL"],
"results", user, prj, chroot
]) + "/"

elif "priority" in query:
query.pop("priority")
Expand Down
22 changes: 22 additions & 0 deletions frontend/coprs_frontend/tests/test_repos.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from copy import deepcopy
from unittest import mock
import pytest
from coprs import app
from coprs.repos import (
generate_repo_url,
pre_process_repo_url,
parse_repo_params,
)
from tests.coprs_test_case import CoprsTestCase
from copr_common.enums import StorageEnum


class TestRepos(CoprsTestCase):
Expand Down Expand Up @@ -84,6 +86,26 @@ def test_pre_process_repo_url(self):
for url, exp in test_cases:
assert pre_process_repo_url("fedora-rawhide-x86_64", url) == exp

@pytest.mark.usefixtures("f_users", "f_coprs", "f_pr_dir", "f_db")
def test_pre_process_repo_url_coprdir(self):
"""
Test that we generate correct URLs for CoprDirs. We use Pulp storage to
easily test this but this but that it only an implementation detail.
"""
app.config["BACKEND_BASE_URL"] = "http://backend"
app.config["PULP_CONTENT_URL"] = "http://pulp"

# We set the storage to Pulp, therefore the fallback for constructing
# the repository URL won't be accurate anymore.
self.c1.storage = StorageEnum.pulp
self.db.session.add_all([self.c1, self.c4_dir])
self.db.session.commit()

assert self.c1.dirs[1].full_name == "user1/foocopr:PR"
url = "copr://user1/foocopr:PR"
expected = "http://pulp/user1/foocopr:PR/fedora-rawhide-x86_64/"
assert pre_process_repo_url("fedora-rawhide-x86_64", url) == expected

def test_parse_repo_params(self):
test_cases = [
("copr://foo/bar", {}),
Expand Down

0 comments on commit 62f0680

Please sign in to comment.