Repository: SFDO-Tooling/CumulusCI
Pull request #3293 (2022-07-19 04:13:21)

Make GithubIssuesParser fall back if issues are disabled


Patch:
diff --git a/cumulusci/tasks/release_notes/exceptions.py b/cumulusci/tasks/release_notes/exceptions.py
index 52334e65b..7db8f8077 100644
--- a/cumulusci/tasks/release_notes/exceptions.py
+++ b/cumulusci/tasks/release_notes/exceptions.py
@@ -1,9 +1,5 @@
 from cumulusci.core.exceptions import CumulusCIException
 
 
-class GithubIssuesError(CumulusCIException):
-    pass
-
-
 class LastReleaseTagNotFoundError(CumulusCIException):
     pass
diff --git a/cumulusci/tasks/release_notes/parser.py b/cumulusci/tasks/release_notes/parser.py
index c140110fb..3e307cfaa 100644
--- a/cumulusci/tasks/release_notes/parser.py
+++ b/cumulusci/tasks/release_notes/parser.py
@@ -1,3 +1,4 @@
+import logging
 import re
 import urllib.parse
 
@@ -7,8 +8,6 @@ from cumulusci.core.exceptions import GithubApiNotFoundError
 from cumulusci.core.versions import PackageVersionNumber
 from cumulusci.oauth.salesforce import PROD_LOGIN_URL, SANDBOX_LOGIN_URL
 
-from .exceptions import GithubIssuesError
-
 
 class BaseChangeNotesParser(object):
     def __init__(self, title):
@@ -185,15 +184,17 @@ class GithubIssuesParser(IssuesParser):
         "prod": "Included in production release",
     }
 
-    def __init__(self, release_notes_generator, title, issue_regex=None):
-        super(GithubIssuesParser, self).__init__(
-            release_notes_generator, title, issue_regex
-        )
+    def __new__(cls, release_notes_generator, title, issue_regex=None):
         if not release_notes_generator.has_issues:
-            raise GithubIssuesError(
-                "Cannot use {}".format(self.__class__.__name__)
-                + " because issues are disabled for this repository."
+            logging.getLogger(__file__).warn(
+                "Issues are disabled for this repository. Falling back to change notes parser."
             )
+            return GithubLinesParser(release_notes_generator, title)
+
+        return super().__new__(cls)
+
+    def __init__(self, release_notes_generator, title, issue_regex=None):
+        super().__init__(release_notes_generator, title, issue_regex)
         self.link_pr = release_notes_generator.link_pr
         self.pr_number = None
         self.pr_url = None


Test patch:
diff --git a/cumulusci/tasks/release_notes/tests/test_parser.py b/cumulusci/tasks/release_notes/tests/test_parser.py
index 51dda3516..81b779d1f 100644
--- a/cumulusci/tasks/release_notes/tests/test_parser.py
+++ b/cumulusci/tasks/release_notes/tests/test_parser.py
@@ -8,7 +8,6 @@ import responses
 from cumulusci.core.exceptions import GithubApiNotFoundError
 from cumulusci.core.github import get_github_api
 from cumulusci.tasks.github.tests.util_github_api import GithubApiTestMixin
-from cumulusci.tasks.release_notes.exceptions import GithubIssuesError
 from cumulusci.tasks.release_notes.generator import GithubReleaseNotesGenerator
 from cumulusci.tasks.release_notes.parser import (
     BaseChangeNotesParser,
@@ -314,10 +313,17 @@ class TestGithubIssuesParser(GithubApiTestMixin):
         with pytest.raises(GithubApiNotFoundError):
             parser.render()
 
+    def test_init__issues_enabled(self):
+        generator = mock.Mock(has_issues=True)
+        result = GithubIssuesParser(generator, self.title)
+        assert isinstance(result, GithubIssuesParser)
+        assert result.title == self.title
+
     def test_init__issues_disabled(self):
         generator = mock.Mock(has_issues=False)
-        with pytest.raises(GithubIssuesError):
-            GithubIssuesParser(generator, self.title)
+        result = GithubIssuesParser(generator, self.title)
+        assert isinstance(result, GithubLinesParser)
+        assert result.title == self.title
 
     def _create_expected_content(self, issue_numbers, pr_url):
         y = []