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

Commit 1f6a974

Browse files
jarosevcikJaroslav Sevcik
andauthored
fix(audit_runner): Notify issue status change support for monorepos (#383)
Co-authored-by: Jaroslav Sevcik <jaroslav.sevcik@kiwi.com>
1 parent 1d1444c commit 1f6a974

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

test/auditing/test_runner.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,30 @@ def test_notify_status_change(mocker, issue_factory, service_factory):
274274
log.exception.assert_called_once_with(
275275
"auditing.update_issue.slack_error", error="Error('channel_not_found')"
276276
)
277+
278+
279+
def test_notify_status_change_monorepo(mocker, issue_factory, service_factory):
280+
service = service_factory()
281+
service_2 = service_factory(repository=service.repository)
282+
issue = issue_factory(repository=service.repository)
283+
log = mocker.patch("zoo.auditing.runner.log", mocker.Mock())
284+
slack = mocker.patch("zoo.auditing.runner.slack", mocker.Mock())
285+
m_reverse = mocker.patch("zoo.auditing.runner.reverse", mocker.Mock())
286+
287+
uut.notify_status_change(issue)
288+
assert slack.chat.post_message.call_count == 2
289+
channels = []
290+
texts = []
291+
for args_list in slack.chat.post_message.call_args_list:
292+
channels.append(args_list.args[0])
293+
texts.append(args_list.args[1])
294+
assert service.slack_channel in channels
295+
assert service_2.slack_channel in channels
296+
assert any(issue.kind.title in text for text in texts)
297+
assert any(issue.repository.name in text for text in texts)
298+
assert m_reverse.call_count == 2
299+
300+
# Unhappy path
301+
slack.chat.post_message.side_effect = SlackError("channel_not_found")
302+
uut.notify_status_change(issue)
303+
assert log.exception.call_count == 2

zoo/auditing/runner.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ def update_issue(issue: Issue, is_found, details=None):
8080
def notify_status_change(issue: Issue):
8181
if Issue.Status(issue.status) in [Issue.Status.NEW, Issue.Status.REOPENED]:
8282
site = Site.objects.get_current()
83-
service = Service.objects.get(repository=issue.repository)
84-
audit_url = reverse(
85-
"audit_report",
86-
args=("services", service.owner_slug, service.name_slug),
83+
services = Service.objects.filter(repository=issue.repository).exclude(
84+
slack_channel__isnull=True
8785
)
88-
text = "{status} issue {issue} on <{repo.url}|{repo.name}>.".format(
89-
status=issue.status.title(),
90-
issue=f"<http://{site.domain}{audit_url}|{issue.kind.title}>",
91-
repo=issue.repository,
92-
)
93-
for channel in issue.repository.services.values_list(
94-
"slack_channel", flat=True
95-
):
86+
for service in services:
87+
audit_url = reverse(
88+
"audit_report",
89+
args=("services", service.owner_slug, service.name_slug),
90+
)
91+
text = "{status} issue {issue} on <{repo.url}|{repo.name}>.".format(
92+
status=issue.status.title(),
93+
issue=f"<http://{site.domain}{audit_url}|{issue.kind.title}>",
94+
repo=issue.repository,
95+
)
9696
try:
97-
slack.chat.post_message(channel, text)
97+
slack.chat.post_message(service.slack_channel, text)
9898
except SlackError as error:
9999
log.exception("auditing.update_issue.slack_error", error=repr(error))
100100

0 commit comments

Comments
 (0)