Skip to content

Commit

Permalink
fix(msteams): update action command from Ignore to Archive (#79776)
Browse files Browse the repository at this point in the history
update action command from Ignore to Archive


![image](https://github.com/user-attachments/assets/b9776812-2bd8-4be3-9ae2-dc4e6290cb1c)
  • Loading branch information
ameliahsu authored Oct 28, 2024
1 parent d0f530e commit 296e0d4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 49 deletions.
14 changes: 7 additions & 7 deletions src/sentry/integrations/msteams/card_builder/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ def build_group_actions(self) -> ContainerBlock:

ignore_action = self.create_issue_action_block(
toggled=GroupStatus.IGNORED == status,
action=ACTION_TYPE.IGNORE,
action_title=IssueConstants.IGNORE,
action=ACTION_TYPE.ARCHIVE,
action_title=IssueConstants.ARCHIVE,
reverse_action=ACTION_TYPE.UNRESOLVE,
reverse_action_title=IssueConstants.STOP_IGNORING,
reverse_action_title=IssueConstants.UNARCHIVE,
# card_kwargs
card_title=IssueConstants.IGNORE_INPUT_TITLE,
submit_button_title=IssueConstants.IGNORE,
input_id=IssueConstants.IGNORE_INPUT_ID,
choices=IssueConstants.IGNORE_INPUT_CHOICES,
card_title=IssueConstants.ARCHIVE_INPUT_TITLE,
submit_button_title=IssueConstants.ARCHIVE,
input_id=IssueConstants.ARCHIVE_INPUT_ID,
choices=IssueConstants.ARCHIVE_INPUT_CHOICES,
)

teams_choices = self.get_teams_choices()
Expand Down
17 changes: 2 additions & 15 deletions src/sentry/integrations/msteams/card_builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,8 @@ class IssueConstants:

UNRESOLVE = "Unresolve"

IGNORE = "Ignore"
IGNORE_INPUT_TITLE = "Ignore until this happens again..."
IGNORE_INPUT_ID = "ignoreInput"
IGNORE_INPUT_CHOICES = [
("Ignore indefinitely", -1),
("1 time", 1),
("10 times", 10),
("100 times", 100),
("1,000 times", 1000),
("10,000 times", 10000),
]

STOP_IGNORING = "Stop Ignoring"

ARCHIVE = "Archive"
ARCHIVE_INPUT_ID = "archiveInput"
ARCHIVE_INPUT_TITLE = "Archive until this happens again..."
ARCHIVE_INPUT_CHOICES = [
("Archive forever", -1),
Expand All @@ -120,7 +107,7 @@ class IssueConstants:
("1,000 times", 1000),
("10,000 times", 10000),
]
STOP_ARCHIVE = "Unarchive"
UNARCHIVE = "Unarchive"

ASSIGN = "Assign"
ASSIGN_INPUT_TITLE = "Assign to..."
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/integrations/msteams/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# cards, may as well just do that here first.
class ACTION_TYPE(str, enum.Enum):
RESOLVE = "1"
IGNORE = "2"
ARCHIVE = "2"
ASSIGN = "3"
UNRESOLVE = "4"
UNASSIGN = "5"
Expand Down
13 changes: 7 additions & 6 deletions src/sentry/integrations/msteams/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class MsTeamsIntegrationResolve(MsTeamsIntegrationAnalytics):
type = "integrations.msteams.resolve"


class MsTeamsIntegrationIgnore(MsTeamsIntegrationAnalytics):
type = "integrations.msteams.ignore"
class MsTeamsIntegrationArchive(MsTeamsIntegrationAnalytics):
type = "integrations.msteams.archive"


class MsTeamsIntegrationUnresolve(MsTeamsIntegrationAnalytics):
Expand All @@ -99,7 +99,7 @@ class MsTeamsIntegrationUnassign(MsTeamsIntegrationAnalytics):

analytics.register(MsTeamsIntegrationAssign)
analytics.register(MsTeamsIntegrationResolve)
analytics.register(MsTeamsIntegrationIgnore)
analytics.register(MsTeamsIntegrationArchive)
analytics.register(MsTeamsIntegrationUnresolve)
analytics.register(MsTeamsIntegrationUnassign)

Expand Down Expand Up @@ -446,8 +446,9 @@ def _make_action_data(self, data: Mapping[str, Any], user_id: int) -> dict[str,
action_data.update({"statusDetails": {"inNextRelease": True}})
elif resolve_type == "inCurrentRelease":
action_data.update({"statusDetails": {"inRelease": "latest"}})
elif action_type == ACTION_TYPE.IGNORE:
ignore_count = data.get("ignoreInput")
# ignore has been renamed to archive, but ignore is still used in the payload
elif action_type == ACTION_TYPE.ARCHIVE:
ignore_count = data.get("archiveInput")
if ignore_count:
action_data = {"status": "ignored"}
if int(ignore_count) > 0:
Expand All @@ -463,7 +464,7 @@ def _make_action_data(self, data: Mapping[str, Any], user_id: int) -> dict[str,

_ACTION_TYPES = {
ACTION_TYPE.RESOLVE: ("resolve", MessagingInteractionType.RESOLVE),
ACTION_TYPE.IGNORE: ("ignore", MessagingInteractionType.IGNORE),
ACTION_TYPE.ARCHIVE: ("archive", MessagingInteractionType.ARCHIVE),
ACTION_TYPE.ASSIGN: ("assign", MessagingInteractionType.ASSIGN),
ACTION_TYPE.UNRESOLVE: ("unresolve", MessagingInteractionType.UNRESOLVE),
ACTION_TYPE.UNASSIGN: ("unassign", MessagingInteractionType.UNASSIGN),
Expand Down
20 changes: 10 additions & 10 deletions tests/sentry/integrations/msteams/test_action_state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def post_webhook(
channel_id=None,
group_id=None,
resolve_input=None,
ignore_input=None,
archive_input=None,
assign_input=None,
):
replyToId = "12345"
Expand Down Expand Up @@ -111,7 +111,7 @@ def post_webhook(
"integrationId": self.integration.id,
},
"resolveInput": resolve_input,
"ignoreInput": ignore_input,
"archiveInput": archive_input,
"assignInput": assign_input,
},
"replyToId": replyToId,
Expand Down Expand Up @@ -170,30 +170,30 @@ def user_conversation_id_callback(request):

@responses.activate
@patch("sentry.integrations.msteams.webhook.verify_signature", return_value=True)
def test_ignore_issue(self, verify):
resp = self.post_webhook(action_type=ACTION_TYPE.IGNORE, ignore_input="-1")
def test_archive_issue(self, verify):
resp = self.post_webhook(action_type=ACTION_TYPE.ARCHIVE, archive_input="-1")
self.group1 = Group.objects.get(id=self.group1.id)

assert resp.status_code == 200, resp.content
assert self.group1.get_status() == GroupStatus.IGNORED

@responses.activate
@patch("sentry.integrations.msteams.webhook.verify_signature", return_value=True)
def test_no_ignore_input(self, verify):
resp = self.post_webhook(action_type=ACTION_TYPE.IGNORE, ignore_input="")
def test_no_archive_input(self, verify):
resp = self.post_webhook(action_type=ACTION_TYPE.ARCHIVE, archive_input="")
self.group1 = Group.objects.get(id=self.group1.id)

assert resp.status_code == 200, resp.content
assert self.group1.get_status() == GroupStatus.UNRESOLVED

@responses.activate
@patch("sentry.integrations.msteams.webhook.verify_signature", return_value=True)
def test_ignore_issue_with_additional_user_auth(self, verify):
def test_archive_issue_with_additional_user_auth(self, verify):
with assume_test_silo_mode(SiloMode.CONTROL):
auth_idp = AuthProvider.objects.create(organization_id=self.org.id, provider="nobody")
AuthIdentity.objects.create(auth_provider=auth_idp, user=self.user)

resp = self.post_webhook(action_type=ACTION_TYPE.IGNORE, ignore_input="-1")
resp = self.post_webhook(action_type=ACTION_TYPE.ARCHIVE, archive_input="-1")
self.group1 = Group.objects.get(id=self.group1.id)

assert resp.status_code == 200, resp.content
Expand All @@ -202,9 +202,9 @@ def test_ignore_issue_with_additional_user_auth(self, verify):
@responses.activate
@patch.object(ApiClient, "put")
@patch("sentry.integrations.msteams.webhook.verify_signature", return_value=True)
def test_ignore_with_params(self, verify, client_put):
def test_archive_with_params(self, verify, client_put):
client_put.return_value = HttpResponse(status=200)
self.post_webhook(action_type=ACTION_TYPE.IGNORE, ignore_input="100")
self.post_webhook(action_type=ACTION_TYPE.ARCHIVE, archive_input="100")

expected_data = {"status": "ignored", "statusDetails": {"ignoreCount": 100}}

Expand Down
20 changes: 10 additions & 10 deletions tests/sentry/integrations/msteams/test_message_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,17 @@ def test_issue_message_builder(self):
assert 2 == len(card_body)
assert "Input.ChoiceSet" == card_body[-1]["type"]

resolve_action, ignore_action, assign_action = actions
resolve_action, archive_action, assign_action = actions
assert "Resolve" == resolve_action["title"]
assert "Ignore" == ignore_action["title"]
assert "Archive" == archive_action["title"]
assert "Assign" == assign_action["title"]

assert _is_show_card_action(ignore_action)
body = ignore_action["card"]["body"]
assert _is_show_card_action(archive_action)
body = archive_action["card"]["body"]
assert 2 == len(body)
assert _is_text_block(body[0])
assert "Ignore until this happens again..." == body[0]["text"]
assert "Ignore" == ignore_action["card"]["actions"][0]["title"]
assert "Archive until this happens again..." == body[0]["text"]
assert "Archive" == archive_action["card"]["actions"][0]["title"]

assert _is_show_card_action(assign_action)
body = assign_action["card"]["body"]
Expand Down Expand Up @@ -427,7 +427,7 @@ def test_resolved_issue_message(self):
assert ActionType.SUBMIT == resolve_action["type"]
assert "Unresolve" == resolve_action["title"]

def test_ignored_issue_message(self):
def test_archived_issue_message(self):
self.group1.status = GroupStatus.IGNORED
self.group1.substatus = None

Expand All @@ -439,9 +439,9 @@ def test_ignored_issue_message(self):
action_set = issue_card["body"][2]["items"][0]

assert _is_action_set(action_set)
ignore_action = action_set["actions"][1]
assert ActionType.SUBMIT == ignore_action["type"]
assert "Stop Ignoring" == ignore_action["title"]
archive_action = action_set["actions"][1]
assert ActionType.SUBMIT == archive_action["type"]
assert "Unarchive" == archive_action["title"]

def test_assigned_issue_message(self):
GroupAssignee.objects.assign(self.group1, self.user)
Expand Down

0 comments on commit 296e0d4

Please sign in to comment.