From 6373f0f785918e6e15e6541ad8f195c48e29002f Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 08 2017 04:36:21 +0000 Subject: [PATCH 1/2] Fix construct anongiturl for chain-build Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 527133e..253b454 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1882,11 +1882,22 @@ class Commands(object): raise rpkgError('Packages in destination tag %(dest_tag_name)s are not inherited by' ' build tag %(build_tag_name)s' % build_target) - def construct_build_url(self): - """Construct build URL with namespaced anongiturl and commit hash""" + def construct_build_url(self, module_name=None, commit_hash=None): + """Construct build URL with namespaced anongiturl and commit hash + + :param str module_name: name of the module part of the build URL. If + omitted, module name with namespace will be guessed from current + repository. The given module name will be used in URL directly + without guessing namespace. + :param str commit_hash: the commit hash appended to build URL. It + omitted, the latest commit hash got from current repository will be + used. + :return: URL built from anongiturl. + :rtype: str + """ return '{0}?#{1}'.format( - self._get_namespace_anongiturl(self.ns_module_name), - self.commithash) + self._get_namespace_anongiturl(module_name or self.ns_module_name), + commit_hash or self.commithash) def build(self, skip_tag=False, scratch=False, background=False, url=None, chain=None, arches=None, sets=False, nvr_check=True): diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 24c97d1..c8ce3d7 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1156,7 +1156,10 @@ see API KEY section of copr-cli(1) man page. else: # Figure out the scm url to build from package name hash = self.cmd.get_latest_commit(component, self.cmd.branch_merge) - url = self.cmd.anongiturl % {'module': component} + '#%s' % hash + # Passing given package name to module_name parameter directly without + # guessing namespace as no way to guess that. rpms/ will be + # added by default if namespace is not given. + url = self.cmd.construct_build_url(component, hash) # If there are no ':' in the chain list, treat each object as # an individual chain if ':' in self.args.package: diff --git a/tests/test_commands.py b/tests/test_commands.py index 2641b90..ca63377 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -697,6 +697,20 @@ class TestConstructBuildURL(CommandTestCase): commithash.return_value) self.assertEqual(expected_url, url) + def test_construct_with_given_module_name_and_hash(self): + cmd = self.make_commands() + + anongiturl = 'https://src.example.com/%(module)s' + with patch.object(cmd, 'anongiturl', new=anongiturl): + for module_name in ('extra-cmake-modules', + 'rpms/kf5-kfilemetadata'): + url = cmd.construct_build_url(module_name, '123456') + + expected_url = '{0}?#{1}'.format( + anongiturl % {'module': module_name}, + '123456') + self.assertEqual(expected_url, url) + class TestCleanupTmpDir(CommandTestCase): """Test Commands._cleanup_tmp_dir for mockbuild command""" From 511ae50a2c5ef327e8b19f429fb2fbf483633eb4 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Nov 08 2017 04:37:47 +0000 Subject: [PATCH 2/2] Fix giturl as well by calling construct_build_url Make giturl command call construct_build_url instead of constructing URL from anongiturl directly. This should be useful for downstream client tools to return correct build URL specific to their own build environment configuration. Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 253b454..7783ef4 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2109,9 +2109,7 @@ class Commands(object): def giturl(self): """Return the git url that would be used for building""" self.check_repo(is_dirty=False, all_pushed=False) - url = self._get_namespace_anongiturl(self.ns_module_name) + \ - '?#%s' % self.commithash - return url + return self.construct_build_url() def koji_upload(self, file, path, callback=None): """Upload a file to koji