diff --git a/reusable_workflows/check_cla/check_cla_pr.py b/reusable_workflows/check_cla/check_cla_pr.py index f474046..f6f9533 100644 --- a/reusable_workflows/check_cla/check_cla_pr.py +++ b/reusable_workflows/check_cla/check_cla_pr.py @@ -69,24 +69,22 @@ def create_cla_issue(self, user: str, pr_url: str) -> GHIssue: user, self.cla_link, user_agreement_message, pr_url ), ) - issue.add_labels(PENDING_LABEL) return issue def handle_cla_signed(self, issue: GHIssue, user: str) -> None: for label in issue.original_labels: if label.name == APPROVED_LABEL: return + + # if a pending label exists, remove it for pending_label in [GH_WORKFLOW_LABEL, PENDING_LABEL]: if label.name == pending_label: - agreement_message = messages.AGREED_MESSAGE.format(user) - issue.create_comment(agreement_message) issue.remove_label(pending_label) - issue.add_labels(APPROVED_LABEL) - return - print( - "No cla labels found - manually check the cla issue to see what state it is in. Exiting program." # noqa - ) - sys.exit(1) + + # once all pending labels have been removed and no approved label was found, add the agreement message with an approved label + agreement_message = messages.AGREED_MESSAGE.format(user) + issue.create_comment(agreement_message) + issue.add_labels(APPROVED_LABEL) def main() -> None: diff --git a/reusable_workflows/tests/test_cla_pr.py b/reusable_workflows/tests/test_cla_pr.py index dcf02e6..65bff83 100644 --- a/reusable_workflows/tests/test_cla_pr.py +++ b/reusable_workflows/tests/test_cla_pr.py @@ -142,7 +142,6 @@ def test_create_cla_issue(): "cla: @username", body=cla_agreement_message, ) - issue.add_labels.assert_called_with("cla:pending") def test_handle_cla_signed_with_agreed_label(): @@ -158,22 +157,19 @@ def test_handle_cla_signed_with_agreed_label(): issue.remove_label.assert_not_called() -def test_handle_cla_signed_with_pending_label(): +def test_handle_cla_signed_with_no_label(): issue = mock.Mock() - label = mock.Mock() - label.name = "cla:gh-wf-pending" - issue.original_labels = [label] + issue.original_labels = [] agreement_message = AGREED_MESSAGE.format("username") cla = CLAHandler(mock.Mock()) cla.handle_cla_signed(issue, "username") issue.create_comment.assert_called_with(agreement_message) - issue.remove_label.assert_called_once() issue.add_labels.assert_called_once() -def test_handle_cla_signed_with_new_pending_label(): +def test_handle_cla_signed_with_old_pending_label(): issue = mock.Mock() label = mock.Mock() label.name = "cla:pending" @@ -188,17 +184,6 @@ def test_handle_cla_signed_with_new_pending_label(): issue.add_labels.assert_called_once() -def test_handle_cla_signed_with_no_label(capfd): - issue = mock.Mock() - issue.original_labels = [] - - with pytest.raises(SystemExit): - cla = CLAHandler(mock.Mock()) - cla.handle_cla_signed(issue, "username") - out, err = capfd.readouterr() - assert out == "No cla labels found - manually check the cla issue to see what state it is in. Exiting program.\n" # fmt: skip - - @mock.patch.dict( os.environ, {"GH_ORG": "my_org", "GH_TOKEN": "secret", "REPO": "repo-name", "PR_ID": "1"},