Skip to content

Commit

Permalink
fix(IDX): remove pending label (#77)
Browse files Browse the repository at this point in the history
* wip

* remove
  • Loading branch information
cgundy authored Dec 12, 2024
1 parent cdde4f9 commit 768965f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
16 changes: 7 additions & 9 deletions reusable_workflows/check_cla/check_cla_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 3 additions & 18 deletions reusable_workflows/tests/test_cla_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"
Expand All @@ -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"},
Expand Down

0 comments on commit 768965f

Please sign in to comment.