diff --git a/src/psrt_ghsa_bot/app.py b/src/psrt_ghsa_bot/app.py index d860e71..406fed7 100644 --- a/src/psrt_ghsa_bot/app.py +++ b/src/psrt_ghsa_bot/app.py @@ -161,6 +161,14 @@ def apply_to_repo( print(f" 🧹 Closed {ghsa_id}") continue + # Maintain a dictionary of updates to make and then submit them all at once. + patch_data = {} + + # If the summary contains '[ACCEPT{ED}]' we can move the ticket to draft + if state == "triage" and re.search(r"\[ACCEPT(?:ED)?\]", summary.upper()) is not None: + patch_data["state"] = state = "draft" + print(f" ✅ Will accept {ghsa_id}") + # Advisories that are in the 'draft' state without a private # fork active will have a fork requested. if state == "draft" and security_advisory.get("private_fork") is None: @@ -175,9 +183,6 @@ def apply_to_repo( print(f" ⚠️ Error creating private fork: {e.response.json()}") raise e - # Maintain a dictionary of updates to make and then submit them all at once. - patch_data = {} - # Advisories that are in the 'draft' state without a CVE ID # should have one allocated by the PSF CVE Numbering Authority. if state == "draft" and security_advisory.get("cve_id") is None: diff --git a/tests/test_app.py b/tests/test_app.py index 4c444fe..7d1fc8f 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -226,6 +226,35 @@ def test_closes_advisory_with_close_or_complete_tag(summary) -> None: ) +@pytest.mark.parametrize( + "summary", + [ + "[ACCEPT] Python is better than C", + "[ACCEPTED] 0.1 + 0.2 is broken?!?!?!?!?!", + "fix soemthing in datetime module [ACCEPTED]", + "blah blah [accepted] lowercase blah", + ], +) +def test_accepts_advisory_with_accept_tag(summary, cve_id, cve_reserve_response) -> None: + security_advisory = _create_advisory_dict("triage", None, ["psrt"], summary=summary) + + github = mock.Mock() + cve_api = mock.Mock() + cve_api.reserve.return_value = cve_reserve_response + + with mock.patch("psrt_ghsa_bot.app.get_repository_advisories") as get_repo_advs: + get_repo_advs.return_value = [security_advisory] + + app.apply_to_repo(github, "owner", "repo", cve_api) + + github.rest.security_advisories.update_repository_advisory.assert_called_once_with( + owner="owner", + repo="repo", + ghsa_id="GHSA-xxxx-xxxx-xxxx", + data={"state": "draft", "cve_id": cve_id}, + ) + + def test_load_psrt_members_from_devguide() -> None: with mock.patch("psrt_ghsa_bot.app.urllib3.request") as urllib3_request: resp = mock.Mock()