From 242e5b75323086d96cc41f68f4bfa395fe6e1597 Mon Sep 17 00:00:00 2001
From: Diego Herrera <dherrera@redhat.com>
Date: Jul 08 2024 21:07:08 +0000
Subject: [PATCH 1/6] Test for valid EPEL branch names


Signed-off-by: Diego Herrera <dherrera@redhat.com>

---

diff --git a/test/test_utils.py b/test/test_utils.py
index e8648e4..4d055ec 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -207,6 +207,21 @@ class TestVerifySLS(unittest.TestCase):
         )
 
 
+class TestIsEpel(unittest.TestCase):
+    """Test is_epel"""
+
+    def test_valid_epel_branch_names(self):
+        self.assertEqual(utils.is_epel("el6"), True)
+        self.assertEqual(utils.is_epel("epel7"), True)
+        self.assertEqual(utils.is_epel("epel8"), True)
+        self.assertEqual(utils.is_epel("epel8-next"), True)
+        self.assertEqual(utils.is_epel("epel9"), True)
+        self.assertEqual(utils.is_epel("epel9-next"), True)
+
+        self.assertEqual(utils.is_epel("f36"), False)
+        self.assertEqual(utils.is_epel("rawhide"), False)
+
+
 @patch('requests.get')
 class TestAssertValidEPELPackage(unittest.TestCase):
     """Test assert_valid_epel_package"""

From d385505ad98b8044fdd8800acd96c5c6a18b1d22 Mon Sep 17 00:00:00 2001
From: Diego Herrera <dherrera@redhat.com>
Date: Jul 08 2024 21:07:08 +0000
Subject: [PATCH 2/6] Add EPEL10 branch name cases as valid


Signed-off-by: Diego Herrera <dherrera@redhat.com>

---

diff --git a/fedpkg/utils.py b/fedpkg/utils.py
index 9e5c5bf..028fba2 100644
--- a/fedpkg/utils.py
+++ b/fedpkg/utils.py
@@ -311,7 +311,7 @@ def is_epel(branch):
     :param branch: a string of the branch name
     :return: a boolean
     """
-    return bool(re.match(r'^(?:el|epel)\d+(?:-next)?$', branch))
+    return bool(re.match(r'^(?:el|epel)\d+(?:\.\d+)?(?:-next)?$', branch))
 
 
 def assert_valid_epel_package(name, branch):
diff --git a/test/test_utils.py b/test/test_utils.py
index 4d055ec..6b6050a 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -217,6 +217,10 @@ class TestIsEpel(unittest.TestCase):
         self.assertEqual(utils.is_epel("epel8-next"), True)
         self.assertEqual(utils.is_epel("epel9"), True)
         self.assertEqual(utils.is_epel("epel9-next"), True)
+        self.assertEqual(utils.is_epel("epel10"), True)
+        self.assertEqual(utils.is_epel("epel10.1"), True)
+        self.assertEqual(utils.is_epel("epel10.10"), True)
+        self.assertEqual(utils.is_epel("epel10.11"), True)
 
         self.assertEqual(utils.is_epel("f36"), False)
         self.assertEqual(utils.is_epel("rawhide"), False)

From d669322e730803824ea6113c9d31306df172c989 Mon Sep 17 00:00:00 2001
From: Diego Herrera <dherrera@redhat.com>
Date: Jul 08 2024 21:07:09 +0000
Subject: [PATCH 3/6] Test url usage in assert_valid_epel_package


Signed-off-by: Diego Herrera <dherrera@redhat.com>

---

diff --git a/test/test_utils.py b/test/test_utils.py
index 6b6050a..2e66fe6 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -244,6 +244,47 @@ class TestAssertValidEPELPackage(unittest.TestCase):
             self, rpkgError, 'The status code was: 404',
             utils.assert_valid_epel_package, 'pkg', 'epel7')
 
+    def test_correct_url_epel7(self, get):
+        get.return_value = Mock(ok=False, status_code=404)
+
+        six.assertRaisesRegex(
+            self, rpkgError, 'The status code was: 404',
+            utils.assert_valid_epel_package, 'pkg', 'epel7')
+        get.assert_called_once_with(
+            'https://infrastructure.fedoraproject.org/repo/json/pkg_el7.json',
+            timeout=60)
+
+    def test_correct_url_epel8(self, get):
+        get.return_value = Mock(ok=False, status_code=404)
+
+        six.assertRaisesRegex(
+            self, rpkgError, 'The status code was: 404',
+            utils.assert_valid_epel_package, 'pkg', 'epel8')
+        get.assert_called_once_with(
+            'https://infrastructure.fedoraproject.org/repo/json/pkg_el8.json',
+            timeout=60)
+
+    def test_correct_url_epel8_next(self, get):
+        get.return_value = Mock(ok=False, status_code=404)
+
+        six.assertRaisesRegex(
+            self, rpkgError, 'The status code was: 404',
+            utils.assert_valid_epel_package, 'pkg', 'epel8-next')
+        get.assert_called_once_with(
+            'https://infrastructure.fedoraproject.org/repo/json/pkg_el8.json',
+            timeout=60)
+
+    def test_correct_url_epel9(self, get):
+        get.return_value = Mock(ok=False, status_code=404)
+
+        six.assertRaisesRegex(
+            self, rpkgError, 'The status code was: 404',
+            utils.assert_valid_epel_package, 'pkg', 'epel9')
+        get.assert_called_once_with(
+            'https://composes.stream.centos.org/production/'
+            'latest-CentOS-Stream/compose/metadata/rpms.json',
+            timeout=60)
+
     def test_should_not_have_epel_branch_for_el6_pkg(self, get):
         get.return_value.json.return_value = {
             'arches': [

From e8dc1c25335b4bde25478e432f0314032ac24ab4 Mon Sep 17 00:00:00 2001
From: Diego Herrera <dherrera@redhat.com>
Date: Jul 08 2024 21:07:09 +0000
Subject: [PATCH 4/6] Add EPEL10+ url pattern on assert_valid_epel_package


Signed-off-by: Diego Herrera <dherrera@redhat.com>

---

diff --git a/fedpkg/utils.py b/fedpkg/utils.py
index 028fba2..3620e73 100644
--- a/fedpkg/utils.py
+++ b/fedpkg/utils.py
@@ -322,16 +322,22 @@ def assert_valid_epel_package(name, branch):
     :param branch: a string of the EPEL branch name (e.g. epel7)
     :return: None or rpkgError
     """
-    # Extract any digits in the branch name to determine the EL version
-    version = ''.join([i for i in branch if re.match(r'\d', i)])
+    # Extract the major part of the EL version
+    version, _ = re.findall(r'(\d+)(?:\.(\d+))?', branch)[0]
 
     # Starting with epel9 and epel9-next, check against CentOS compose metadata.
     if int(version) >= 9:
-        # Currently we only have a latest symlink.  In the future we'll need
-        # separate latest symlinks that include the major version.
+        # Currently the stream-9 branch resides in the production address path..
+        # To remove this block, we need for the stream-9 link to point to production
         # https://bugzilla.redhat.com/show_bug.cgi?id=2005139
-        url = 'https://composes.stream.centos.org/production/' \
-              'latest-CentOS-Stream/compose/metadata/rpms.json'
+        if int(version) == 9:
+            url = 'https://composes.stream.centos.org/production/' \
+                  'latest-CentOS-Stream/compose/metadata/rpms.json'
+        else:
+            url = ('https://composes.stream.centos.org/stream-{0}/'
+                'production/latest-CentOS-Stream/compose/metadata/rpms.json'
+                .format(version))
+
         error_msg = ('The connection to composes.stream.centos.org failed while '
                      'trying to determine if this is a valid EPEL package.')
         try:
diff --git a/test/test_utils.py b/test/test_utils.py
index 2e66fe6..7a38740 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -285,6 +285,28 @@ class TestAssertValidEPELPackage(unittest.TestCase):
             'latest-CentOS-Stream/compose/metadata/rpms.json',
             timeout=60)
 
+    def test_correct_url_epel10(self, get):
+        get.return_value = Mock(ok=False, status_code=404)
+
+        six.assertRaisesRegex(
+            self, rpkgError, 'The status code was: 404',
+            utils.assert_valid_epel_package, 'pkg', 'epel10')
+        get.assert_called_once_with(
+            'https://composes.stream.centos.org/stream-10/production'
+            '/latest-CentOS-Stream/compose/metadata/rpms.json',
+            timeout=60)
+
+    def test_correct_url_epel10_10(self, get):
+        get.return_value = Mock(ok=False, status_code=404)
+
+        six.assertRaisesRegex(
+            self, rpkgError, 'The status code was: 404',
+            utils.assert_valid_epel_package, 'pkg', 'epel10.10')
+        get.assert_called_once_with(
+            'https://composes.stream.centos.org/stream-10/production'
+            '/latest-CentOS-Stream/compose/metadata/rpms.json',
+            timeout=60)
+
     def test_should_not_have_epel_branch_for_el6_pkg(self, get):
         get.return_value.json.return_value = {
             'arches': [

From 2f4399b9159c86d9a399163254ab7fa2fa1bd5bb Mon Sep 17 00:00:00 2001
From: Diego Herrera <dherrera@redhat.com>
Date: Jul 08 2024 21:07:09 +0000
Subject: [PATCH 5/6] Extend load_rpmdefines to work with EPEL10+


Signed-off-by: Diego Herrera <dherrera@redhat.com>

---

diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py
index abb4fb6..b3e9b3b 100644
--- a/fedpkg/__init__.py
+++ b/fedpkg/__init__.py
@@ -88,14 +88,17 @@ class Commands(pyrpkg.Commands):
             self.mockconfig = 'fedora-%s-%s' % (self._distval, self.localarch)
             self.override = 'f%s-override' % self._distval
             self._distunset = 'rhel'
-        # Works until RHEL 10
         elif re.match(r'el\d$', branch) or \
-                re.match(r'epel\d$', branch):
-            self._distval = branch.split('el')[1]
+                re.match(r'epel\d+(?:\.\d+)?$', branch):
+            major, minor = re.findall(r'(\d+)(?:\.(\d+))?', branch)[0]
+            self._distval = major
             self._distvar = 'rhel'
-            self._disttag = 'el%s' % self._distval
-            self.mockconfig = 'epel-%s-%s' % (self._distval, self.localarch)
-            self.override = 'epel%s-override' % self._distval
+            self._disttag = 'el%s' % major if minor == '' \
+                else 'el%s_%s' % (major, minor)
+            self.mockconfig = 'epel-%s-%s' % (major, self.localarch) if minor == '' \
+                else 'epel-%s.%s-%s' % (major, minor, self.localarch)
+            self.override = 'epel%s-override' % self._distval if minor == '' \
+                else 'epel%s.%s-override' % (major, minor)
             self._distunset = 'fedora'
         elif re.match(r'epel\d+-next$', branch):
             self._distval = re.search(r'\d+', branch).group(0)
diff --git a/test/test_commands.py b/test/test_commands.py
index fb417ff..a5b5ed5 100644
--- a/test/test_commands.py
+++ b/test/test_commands.py
@@ -267,6 +267,36 @@ class TestLoadRpmDefines(CommandTestCase):
         self.assert_rpmdefines()
 
     @patch('pyrpkg.Commands.branch_merge', new_callable=PropertyMock)
+    def test_load_epel10_dist_tag(self, branch_merge):
+        branch_merge.return_value = 'epel10'
+
+        self.cmd.load_rpmdefines()
+
+        self.assertEqual('10', self.cmd._distval)
+        self.assertEqual('rhel', self.cmd._distvar)
+        self.assertEqual('el10', self.cmd._disttag)
+        self.assertEqual('epel-10-i686', self.cmd.mockconfig)
+        self.assertEqual('epel10-override', self.cmd.override)
+        self.assertTrue(hasattr(self.cmd, '_distunset'))
+
+        self.assert_rpmdefines()
+
+    @patch('pyrpkg.Commands.branch_merge', new_callable=PropertyMock)
+    def test_load_epel10_10_dist_tag(self, branch_merge):
+        branch_merge.return_value = 'epel10.10'
+
+        self.cmd.load_rpmdefines()
+
+        self.assertEqual('10', self.cmd._distval)
+        self.assertEqual('rhel', self.cmd._distvar)
+        self.assertEqual('el10_10', self.cmd._disttag)
+        self.assertEqual('epel-10.10-i686', self.cmd.mockconfig)
+        self.assertEqual('epel10.10-override', self.cmd.override)
+        self.assertTrue(hasattr(self.cmd, '_distunset'))
+
+        self.assert_rpmdefines()
+
+    @patch('pyrpkg.Commands.branch_merge', new_callable=PropertyMock)
     @patch('fedpkg.Commands._findrawhidebranch')
     def test_load_rawhide_dist_tag(self, _findrawhidebranch, branch_merge):
         _findrawhidebranch.return_value = '28'

From d0e3d725294f268955b7cb9c4c0869caa1e81307 Mon Sep 17 00:00:00 2001
From: Diego Herrera <dherrera@redhat.com>
Date: Jul 08 2024 21:07:09 +0000
Subject: [PATCH 6/6] Intentation fix reported by flake8


Signed-off-by: Diego Herrera <dherrera@redhat.com>

---

diff --git a/fedpkg/utils.py b/fedpkg/utils.py
index 3620e73..6f7d2be 100644
--- a/fedpkg/utils.py
+++ b/fedpkg/utils.py
@@ -335,8 +335,8 @@ def assert_valid_epel_package(name, branch):
                   'latest-CentOS-Stream/compose/metadata/rpms.json'
         else:
             url = ('https://composes.stream.centos.org/stream-{0}/'
-                'production/latest-CentOS-Stream/compose/metadata/rpms.json'
-                .format(version))
+                   'production/latest-CentOS-Stream/compose/metadata/rpms.json'
+                   .format(version))
 
         error_msg = ('The connection to composes.stream.centos.org failed while '
                      'trying to determine if this is a valid EPEL package.')

