From 075f610a82245a6804c89741f73b2fc0ae67bb2f Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Sep 30 2017 02:09:36 +0000 Subject: Allow to override build URL This change makes it possible to override the build URL in downstream client tool for its own specific use case. Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index f5e9c6a..56fd9b4 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1876,6 +1876,12 @@ 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""" + return '{0}?#{1}'.format( + self._get_namespace_anongiturl(self.ns_module_name), + self.commithash) + def build(self, skip_tag=False, scratch=False, background=False, url=None, chain=None, arches=None, sets=False, nvr_check=True): """Initiate a build of the module. Available options are: @@ -1917,8 +1923,7 @@ class Commands(object): str(e), 'Try option --srpm to make scratch build from local changes.') raise rpkgError(msg) - url = self._get_namespace_anongiturl(self.ns_module_name) + \ - '?#%s' % self.commithash + url = self.construct_build_url() # Check to see if the target is valid build_target = self.kojisession.getBuildTarget(self.target) if not build_target: @@ -2583,8 +2588,7 @@ class Commands(object): if dest_tag['locked'] and 'scratch' not in opts: self.log.error("Destination tag %s is locked", dest_tag['name']) - source = self._get_namespace_anongiturl(self.ns_module_name) - source += "#%s" % self.commithash + source = self.construct_build_url() task_opts = {} for key in ('scratch', 'name', 'version', 'release', diff --git a/tests/test_commands.py b/tests/test_commands.py index fe0f963..2f8fe05 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -659,3 +659,24 @@ class TestLoginKojiSession(CommandTestCase): self.cmd.login_koji_session(self.koji_config, self.session) self.session.krb_login.assert_called_once_with(proxyuser=None) + + +class TestConstructBuildURL(CommandTestCase): + """Test Commands.construct_build_url""" + + @patch('pyrpkg.Commands.ns_module_name', new_callable=PropertyMock) + @patch('pyrpkg.Commands.commithash', new_callable=PropertyMock) + def test_construct_url(self, commithash, ns_module_name): + commithash.return_value = '12345' + ns_module_name.return_value = 'container/fedpkg' + + cmd = self.make_commands() + + anongiturl = 'https://src.example.com/%(module)s' + with patch.object(cmd, 'anongiturl', new=anongiturl): + url = cmd.construct_build_url() + + expected_url = '{0}?#{1}'.format( + anongiturl % {'module': ns_module_name.return_value}, + commithash.return_value) + self.assertEqual(expected_url, url)