Blob Blame History Raw
From 6373f0f785918e6e15e6541ad8f195c48e29002f Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Wed, 8 Nov 2017 11:11:26 +0800
Subject: [PATCH 1/2] Fix construct anongiturl for chain-build

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
---
 pyrpkg/__init__.py     | 19 +++++++++++++++----
 pyrpkg/cli.py          |  5 ++++-
 tests/test_commands.py | 14 ++++++++++++++
 3 files changed, 33 insertions(+), 5 deletions(-)

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"""
-- 
2.9.5