Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
fix(audit_runner): Notify issue status change support for monorepos (#…
Browse files Browse the repository at this point in the history
…383)

Co-authored-by: Jaroslav Sevcik <[email protected]>
  • Loading branch information
jarosevcik and Jaroslav Sevcik authored Mar 2, 2021
1 parent 1d1444c commit 1f6a974
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
27 changes: 27 additions & 0 deletions test/auditing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,30 @@ def test_notify_status_change(mocker, issue_factory, service_factory):
log.exception.assert_called_once_with(
"auditing.update_issue.slack_error", error="Error('channel_not_found')"
)


def test_notify_status_change_monorepo(mocker, issue_factory, service_factory):
service = service_factory()
service_2 = service_factory(repository=service.repository)
issue = issue_factory(repository=service.repository)
log = mocker.patch("zoo.auditing.runner.log", mocker.Mock())
slack = mocker.patch("zoo.auditing.runner.slack", mocker.Mock())
m_reverse = mocker.patch("zoo.auditing.runner.reverse", mocker.Mock())

uut.notify_status_change(issue)
assert slack.chat.post_message.call_count == 2
channels = []
texts = []
for args_list in slack.chat.post_message.call_args_list:
channels.append(args_list.args[0])
texts.append(args_list.args[1])
assert service.slack_channel in channels
assert service_2.slack_channel in channels
assert any(issue.kind.title in text for text in texts)
assert any(issue.repository.name in text for text in texts)
assert m_reverse.call_count == 2

# Unhappy path
slack.chat.post_message.side_effect = SlackError("channel_not_found")
uut.notify_status_change(issue)
assert log.exception.call_count == 2
26 changes: 13 additions & 13 deletions zoo/auditing/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ def update_issue(issue: Issue, is_found, details=None):
def notify_status_change(issue: Issue):
if Issue.Status(issue.status) in [Issue.Status.NEW, Issue.Status.REOPENED]:
site = Site.objects.get_current()
service = Service.objects.get(repository=issue.repository)
audit_url = reverse(
"audit_report",
args=("services", service.owner_slug, service.name_slug),
services = Service.objects.filter(repository=issue.repository).exclude(
slack_channel__isnull=True
)
text = "{status} issue {issue} on <{repo.url}|{repo.name}>.".format(
status=issue.status.title(),
issue=f"<http://{site.domain}{audit_url}|{issue.kind.title}>",
repo=issue.repository,
)
for channel in issue.repository.services.values_list(
"slack_channel", flat=True
):
for service in services:
audit_url = reverse(
"audit_report",
args=("services", service.owner_slug, service.name_slug),
)
text = "{status} issue {issue} on <{repo.url}|{repo.name}>.".format(
status=issue.status.title(),
issue=f"<http://{site.domain}{audit_url}|{issue.kind.title}>",
repo=issue.repository,
)
try:
slack.chat.post_message(channel, text)
slack.chat.post_message(service.slack_channel, text)
except SlackError as error:
log.exception("auditing.update_issue.slack_error", error=repr(error))

Expand Down

0 comments on commit 1f6a974

Please sign in to comment.