Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: labhub: Allow missing username and msg link #417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,22 @@ 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
16 changes: 10 additions & 6 deletions tests/labhub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from IGitt.GitLab.GitLabMergeRequest import GitLabMergeRequest
from IGitt.GitHub.GitHubIssue import GitHubIssue

from errbot.backends.test import TestBot
from errbot.backends.test import Message, TestBot

import plugins.labhub
from plugins.labhub import LabHub
Expand Down Expand Up @@ -88,22 +88,26 @@ def test_create_issue_cmd(self):
plugins.labhub.GitHubToken.assert_called_with(None)
plugins.labhub.GitLabPrivateToken.assert_called_with(None)


labhub.REPOS = {'repository': self.mock_repo,
'repository.github.io': self.mock_repo}

testbot.assertCommand('!new issue repository this is the title\nbo\ndy',
'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 on text'
)

testbot.assertCommand('!new issue repository.github.io another title\nand body',
'Here you go')
msg = Message('!new issue repository.github.io another title\nand body',
'Here you go')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jayvdb Invalid command args, it can be like

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't, I can say that from the errbot documentation, just change constructor and add assert command.

msg.extras['url'] = 'http://example.com'
msg.frm = testbot.bot.build_identifier('Jo')
msg.frm._nick = 'jo'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg.frm._nick --> msg.frm.nick

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure it is a non-writable property.


testbot.bot.callback_message(msg)

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

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