diff --git a/src/pyosmeta/parse_issues.py b/src/pyosmeta/parse_issues.py index 81b88c0..9f0952f 100644 --- a/src/pyosmeta/parse_issues.py +++ b/src/pyosmeta/parse_issues.py @@ -1,4 +1,5 @@ import re +import warnings from datetime import datetime import requests @@ -665,7 +666,13 @@ def comment_to_list(self, issue: dict[str, str]) -> tuple[str, list[str]]: None, ) - pkg_name = body_data[name_index][1] if name_index else None + if name_index is None: + warnings.warn( + "Package Name not found in the issue comment.", UserWarning + ) + pkg_name = "missing_name" + else: + pkg_name = body_data[name_index][1] return clean_markdown(pkg_name), body_data diff --git a/tests/unit/test_get_contrib_data.py b/tests/unit/test_get_contrib_data.py index f3f7697..cc28d53 100644 --- a/tests/unit/test_get_contrib_data.py +++ b/tests/unit/test_get_contrib_data.py @@ -1,4 +1,4 @@ -from pyosmeta.parse_issues import ProcessIssues +import pytest sample_response = { "url": "https://api.github.com/repos/pyOpenSci/software-submission/issues/147", @@ -26,28 +26,33 @@ "timeline_url": "https://api.github.com/repos/pyOpenSci/software-submission/issues/147/timeline", } -# Create a generic object to use in all tests -p_issues = ProcessIssues( - repo_name="pyostest", org="pyopensci", label_name="test" -) - -def test_comment_to_list_returns_list(): +def test_comment_to_list_returns_list(process_issues): """Test that comment_to_list returns a list""" - name, body = p_issues.comment_to_list(sample_response) + name, body = process_issues.comment_to_list(sample_response) assert isinstance(body, list) -def test_comment_no_name(): +def test_comment_no_name(process_issues): + """Test what happens if the package name key is missing in the review + this means that a user has likely modified the template. + + In that case we just insert a placeholder name and keep processing issues. + This is a template issue not a code issue. + """ - name, body = p_issues.comment_to_list(sample_response_no_name) + with pytest.warns( + UserWarning, match="Package Name not found in the issue comment." + ): + name, body = process_issues.comment_to_list(sample_response_no_name) + assert name == "missing_name" -def test_comment_to_list_package_name(): +def test_comment_to_list_package_name(process_issues): """Test that comment_to_list returns a proper package name""" - name, body = p_issues.comment_to_list(sample_response) + name, body = process_issues.comment_to_list(sample_response) assert name == "sunpy" diff --git a/tests/unit/test_parse_issue_header_methods.py b/tests/unit/test_parse_issue_header_methods.py index 8e82c33..396f812 100644 --- a/tests/unit/test_parse_issue_header_methods.py +++ b/tests/unit/test_parse_issue_header_methods.py @@ -22,12 +22,12 @@ def test_comment_to_list(process_issues, issue_list): ("`Code`", "Code"), ("**Bold**", "Bold"), ("***Strong***", "Strong"), - ("`*Code*`", "*Code*"), - ("`**Code**`", "**Code**"), - ("`***Code***`", "***Code***"), - ("`Code***`", "Code***"), - ("***Code`", "***Code"), - ("***Code*`", "***Code*"), + ("`*Code*`", "Code"), + ("`**Code**`", "Code"), + ("`***Code***`", "Code"), + ("`Code***`", "Code"), + ("***Code`", "Code"), + ("***Code*`", "Code"), ], ) def test_clean_markdown(input_string, expected_output):