Repository: qiskit-community/ecosystem
Pull request #442 (2023-07-07 14:26:26)

Ignore website field if not provided
<!--
⚠️ If you do not respect this template, your pull request will be closed.
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Also, please add a release note file using reno if the change needs to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary

Having `_No response_` in the website field could causes broken links on qiskit.org/ecosystem. This PR removes the field if no website is provided.

Example: https://github.com/qiskit-community/ecosystem/pull/441#discussion_r1255687040


Patch:
diff --git a/ecosystem/models/utils.py b/ecosystem/models/utils.py
index 16e28a8..9895dc9 100644
--- a/ecosystem/models/utils.py
+++ b/ecosystem/models/utils.py
@@ -23,6 +23,8 @@ class JsonSerializable(ABC):
             if key.startswith("_"):
                 continue
             element = []
+            if val is None:
+                continue
             if isinstance(val, list):
                 for item in val:
                     if isinstance(item, JsonSerializable):
diff --git a/ecosystem/utils/submission_parser.py b/ecosystem/utils/submission_parser.py
index 586ff53..36d171f 100644
--- a/ecosystem/utils/submission_parser.py
+++ b/ecosystem/utils/submission_parser.py
@@ -41,6 +41,8 @@ def parse_submission_issue(body_of_issue: str) -> Repository:
     licence = sections["License"]
     affiliations = sections["Affiliations"]
     website = sections["Website"]
+    if website == "_No response_":
+        website = None
 
     labels = [l.strip() for l in sections["Tags"].split(",")]
 


Test patch:
diff --git a/tests/resources/issue_2.md b/tests/resources/issue_2.md
new file mode 100644
index 0000000..d652655
--- /dev/null
+++ b/tests/resources/issue_2.md
@@ -0,0 +1,31 @@
+### Github repo
+
+http://github.com/awesome/awesome
+
+### Description
+
+An awesome repo for awesome project
+
+### Email
+
+toto@gege.com
+
+### Alternatives
+
+_No response_
+
+### License
+
+Apache License 2.0
+
+### Affiliations
+
+Awesome Inc.
+
+### Tags
+
+_No response_
+
+### Website
+
+_No response_
diff --git a/tests/test_manager.py b/tests/test_manager.py
index e68e24b..a98f625 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -1,8 +1,8 @@
 """Tests for manager cli."""
 import os
 import io
-import sys
 from unittest import TestCase
+from contextlib import redirect_stdout
 
 import responses
 
@@ -67,6 +67,10 @@ class TestManager(TestCase):
             "{}/resources/issue.md".format(self.current_dir), "r"
         ) as issue_body_file:
             self.issue_body = issue_body_file.read()
+        with open(
+            "{}/resources/issue_2.md".format(self.current_dir), "r"
+        ) as issue_body_file:
+            self.issue_body_2 = issue_body_file.read()
 
     def tearDown(self) -> None:
         self._delete_members_json()
@@ -85,11 +89,12 @@ class TestManager(TestCase):
         Args:
             issue_body
         """
+
+        # Issue 1
         captured_output = io.StringIO()
-        sys.stdout = captured_output
-        Manager.parser_issue(self.issue_body)
+        with redirect_stdout(captured_output):
+            Manager.parser_issue(self.issue_body)
 
-        sys.stdout = sys.__stdout__
         output_value = captured_output.getvalue().split("\n")
 
         self.assertEqual(output_value[0], "SUBMISSION_NAME=awesome")
@@ -115,6 +120,35 @@ class TestManager(TestCase):
             "SUBMISSION_WEBSITE=https://qiskit.org/ecosystem/",
         )
 
+        # Issue 2
+        captured_output = io.StringIO()
+        with redirect_stdout(captured_output):
+            Manager.parser_issue(self.issue_body_2)
+
+        output_value = captured_output.getvalue().split("\n")
+
+        self.assertEqual(output_value[0], "SUBMISSION_NAME=awesome")
+        self.assertEqual(
+            output_value[1],
+            "SUBMISSION_REPO=http://github.com/awesome/awesome",
+        )
+        self.assertEqual(
+            output_value[2],
+            "SUBMISSION_DESCRIPTION=An awesome repo for awesome project",
+        )
+        self.assertEqual(output_value[3], "SUBMISSION_LICENCE=Apache License 2.0")
+        self.assertEqual(output_value[4], "SUBMISSION_CONTACT=toto@gege.com")
+        self.assertEqual(output_value[5], "SUBMISSION_ALTERNATIVES=_No response_")
+        self.assertEqual(output_value[6], "SUBMISSION_AFFILIATIONS=Awesome Inc.")
+        self.assertEqual(
+            output_value[7],
+            "SUBMISSION_LABELS=['_No response_']",
+        )
+        self.assertEqual(
+            output_value[8],
+            "SUBMISSION_WEBSITE=None",
+        )
+
     @responses.activate
     def test_dispatch_repository(self):
         """Test github dispatch event.