Skip to content

Commit

Permalink
labhub: Allow missing username and msg link
Browse files Browse the repository at this point in the history
Some backends do not provide usernames or msg links.

Zulip and Slack both using msg.extra['url'], and a
patch is pending for the gitter backend to follow suite.
errbotio/err-backend-gitter#32

Fixes coala#392
Related to coala#255
  • Loading branch information
jayvdb committed Nov 29, 2017
1 parent 1f5d19f commit 7be6c84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
19 changes: 14 additions & 5 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,20 @@ def create_issue_cmd(self, msg, match):
repo_name = match.group(1)
iss_title = match.group(2)
iss_description = match.group(3) if match.group(3) is not None else ''
extra_msg = '\nOpened by @{username} at [{backend}]({msg_link})'.format(
username=msg.frm.nick,
backend=self.bot_config.BACKEND,
msg_link=message_link(self, msg)
)

extra_parts = []
if msg.frm.nick:
extra_parts.append('by @{}'.format(msg.frm.nick))
msg_link = message_link(self, msg)
if msg_link:
extra_parts.append(' at [{backend}]({msg_link})'.format(
backend=self.bot_config.BACKEND,
msg_link=message_link(self, msg)
)
else:
extra_parts.append(' on {}'.format(self.bot_config.BACKEND))

extra_msg = '\nOpened {}'.format(' '.join(extra_parts))

if repo_name in self.REPOS:
repo = self.REPOS[repo_name]
Expand Down
4 changes: 2 additions & 2 deletions tests/labhub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def test_create_issue_cmd(self):
'Here you go')

labhub.REPOS['repository'].create_issue.assert_called_once_with(
'this is the title', 'bo\ndy\nOpened by @None at [text]()'
'this is the title', 'bo\ndy\nOpened at [text]()'
)

testbot.assertCommand('!new issue repository.github.io another title\nand body',
'Here you go')

labhub.REPOS['repository.github.io'].create_issue.assert_called_with(
'another title', 'and body\nOpened by @None at [text]()'
'another title', 'and body\nOpened at [text]()'
)

testbot.assertCommand('!new issue coala title', 'repository that does not exist')
Expand Down
8 changes: 2 additions & 6 deletions utils/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ def message_link(bot, msg):
if backend == 'gitter':
return 'https://gitter.im/{uri}?at={idd}'.format(uri=msg.frm.room.uri,
idd=msg.extras['id'])
elif backend == 'slack':
elif 'url' in msg.extras:
return msg.extras['url']
elif backend == 'telegram':
return ''
elif backend == 'text':
return ''
else:
raise NotImplementedError
return None

0 comments on commit 7be6c84

Please sign in to comment.