Skip to content
Snippets Groups Projects
Unverified Commit 531f2a88 authored by Fredrik Jonsson's avatar Fredrik Jonsson Committed by GitHub
Browse files

Merge pull request #1806 from...

Merge pull request #1806 from OpenTechFund/enhancement/add-option-for-comment-notification-slack-room

Add SLACK_DESTINATION_ROOM_COMMENTS setting allowing comments notific…
parents 68e5eb0f c725456f
No related branches found
Tags v1.29.0
No related merge requests found
...@@ -429,6 +429,7 @@ class SlackAdapter(AdapterBase): ...@@ -429,6 +429,7 @@ class SlackAdapter(AdapterBase):
super().__init__() super().__init__()
self.destination = settings.SLACK_DESTINATION_URL self.destination = settings.SLACK_DESTINATION_URL
self.target_room = settings.SLACK_DESTINATION_ROOM self.target_room = settings.SLACK_DESTINATION_ROOM
self.comments_room = settings.SLACK_DESTINATION_ROOM_COMMENTS
def slack_links(self, links, sources): def slack_links(self, links, sources):
return ', '.join( return ', '.join(
...@@ -591,7 +592,7 @@ class SlackAdapter(AdapterBase): ...@@ -591,7 +592,7 @@ class SlackAdapter(AdapterBase):
return f'<{user.slack}>' return f'<{user.slack}>'
def slack_channels(self, source): def slack_channels(self, source, **kwargs):
target_rooms = [self.target_room] target_rooms = [self.target_room]
try: try:
extra_rooms = source.get_from_parent('slack_channel').split(',') extra_rooms = source.get_from_parent('slack_channel').split(',')
...@@ -601,6 +602,13 @@ class SlackAdapter(AdapterBase): ...@@ -601,6 +602,13 @@ class SlackAdapter(AdapterBase):
else: else:
target_rooms.extend(extra_rooms) target_rooms.extend(extra_rooms)
try:
if self.comments_room and kwargs['comment']:
target_rooms.extend([self.comments_room])
except KeyError:
# Not a comment.
pass
# Make sure each channel name starts with a "#". # Make sure each channel name starts with a "#".
target_rooms = [ target_rooms = [
room if room.startswith('#') else '#' + room room if room.startswith('#') else '#' + room
...@@ -611,7 +619,7 @@ class SlackAdapter(AdapterBase): ...@@ -611,7 +619,7 @@ class SlackAdapter(AdapterBase):
return target_rooms return target_rooms
def send_message(self, message, recipient, source, **kwargs): def send_message(self, message, recipient, source, **kwargs):
target_rooms = self.slack_channels(source) target_rooms = self.slack_channels(source, **kwargs)
if not self.destination or not any(target_rooms): if not self.destination or not any(target_rooms):
errors = list() errors = list()
......
...@@ -505,6 +505,7 @@ if not SEND_MESSAGES: ...@@ -505,6 +505,7 @@ if not SEND_MESSAGES:
SLACK_DESTINATION_URL = env.get('SLACK_DESTINATION_URL', None) SLACK_DESTINATION_URL = env.get('SLACK_DESTINATION_URL', None)
SLACK_DESTINATION_ROOM = env.get('SLACK_DESTINATION_ROOM', None) SLACK_DESTINATION_ROOM = env.get('SLACK_DESTINATION_ROOM', None)
SLACK_DESTINATION_ROOM_COMMENTS = env.get('SLACK_DESTINATION_ROOM_COMMENTS', None)
# Celery config # Celery config
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment