def test_request_to_show_everything(self): jira = MockJira(issues=self.get_test_issue_set()) slack = MockSlack() bot = JiraBot(jira, slack, "AAA", "LABEL", None, "#things", logger=self.logger, supress_quotes=True) slack.add_incoming({u'text': u'<@BOTID> show warnings'}) bot.process_messages() self.assertEqual(1, len(slack.outgoing_messages))
def test_request_to_show_progress_chart(self): jira = MockJira().with_n_fake_issues(50) slack = MockSlack() bot = JiraBot(jira, slack, "XXX", "LABEL", "#channel_4", 3, logger=self.logger, supress_quotes=True) slack.add_incoming({u'text': u'<@BOTID> chart progress'}) bot.process_messages() self.assertEqual(1, len(slack.uploaded_files)) self.assertEqual(0, len(slack.outgoing_messages))
def test_request_status_summary(self): jira = MockJira(issues=self.get_test_issue_set()) slack = MockSlack() bot = JiraBot(jira, slack, "AAA", "LABEL", None, "#things", logger=self.logger, supress_quotes=True) slack.add_incoming({u'text': u'<@BOTID> status summary'}) bot.process_messages() self.assertEqual(1, len(slack.outgoing_messages)) msg = slack.outgoing_messages[0]["message"].lower() self.assertTrue("backlog: *3*" in msg) self.assertTrue("to do: *1*" in msg) self.assertTrue("in progress: *2*" in msg)
def test_unknown_command(self): jira = MockJira(issues=[]) slack = MockSlack() bot = JiraBot(jira, slack, "AAA", "LABEL", None, "#things", logger=self.logger, supress_quotes=True) slack.add_incoming({ u'text': u'<@BOTID> herrings are obfuscation cheese', u'user': u'USER_ID' }) bot.process_messages() self.assertEqual(1, len(slack.outgoing_messages)) self.assertTrue("<@USER_ID>" in slack.outgoing_messages[0]["message"])
def do_leaderboard(self, msg="leader board", issues=None): if not issues: issues = self.get_completed_issue_set() jira = MockJira(issues=issues) slack = MockSlack(name_lookup=self.get_name_lookup_for_leaderboard()) bot = JiraBot(jira, slack, "XXX", "LABEL", None, "#channel_name", 3, logger=self.logger, supress_quotes=True) slack.add_incoming({u'text': u'<@BOTID> {0}'.format(msg)}) bot.process_messages() self.assertEqual(len(slack.outgoing_messages), 1) self.assertEqual("#channel_name", slack.outgoing_messages[0]["recipient"]) message = slack.outgoing_messages[0]["message"] return message
jira = Jira(args.jira, args.user, logger=logger) slack = Slack(args.slack_key, logger=logger) bot = JiraBot(jira=jira, slack=slack, project=args.project, label=args.label, fix_version=args.fix_version, channel=args.channel, logger=logger, wip_limit=args.wip_limit) slack.send(args.channel, ":tada: I just restarted. Hello!") count = 0 while True: try: bot.process_messages() hour = datetime.now().hour if count > (args.freq * 60 * 10) and args.wake_hour <= hour < args.sleep_hour: count = 0 bot.send_periodic_update() count += 1 except Exception as e: logger.exception(e) logger.error(e.message) if not args.forever: break sleep(0.1)