def test_messages_when_nothing_interesting_happening(self): jira = MockJira(issues=[ { "id": "XXX-1", "summary": "My first Jira", "status": "Backlog" }, { "id": "XXX-2", "summary": "My second Jira", "status": "Backlog" }, ]) slack = MockSlack() bot = JiraBot(jira, slack, "XXX", "LABEL", None, "#channel", wip_limit=3, logger=self.logger, supress_quotes=True) bot.send_periodic_update() self.assertEqual(len(slack.outgoing_messages), 2) self.assertEqual(":partyparrot:", slack.outgoing_messages[1]["message"])
def test_new_issues_in_backlog_notified_on_channel(self): jira = MockJira(issues=[{ "id": "AAA-2", "summary": "I am new", "status": "Backlog", "created": u'2016-08-10T07:55:00.000+0100' }, { "id": "AAA-1", "summary": "I am not new", "status": "Backlog", "created": u'2016-08-08T14:50:36.000+0100' }]) slack = MockSlack() bot = JiraBot(jira, slack, "AAA", "LABEL", None, "#whatever", logger=self.logger, supress_quotes=True) bot.send_periodic_update() self.assertEqual(3, len(slack.outgoing_messages)) self.assertEqual("There are no warnings. It's all good!", slack.outgoing_messages[0]["message"]) self.assertEqual(':partyparrot:', slack.outgoing_messages[1]["message"]) self.assertEqual(':memo: New issue AAA-2 added', slack.outgoing_messages[2]["message"])
def test_message_sent_if_too_many_issues_in_progress(self): jira = MockJira(issues=[ { "id": "XXX-1", "summary": "My first Jira", "assignee": "Busy Bob", "status": "In Progress" }, { "id": "XXX-2", "summary": "My second Jira", "assignee": "Busy Bob", "status": "In Progress" }, { "id": "XXX-3", "summary": "My third Jira", "assignee": "Busy Bob", "status": "In Progress" }, { "id": "XXX-4", "summary": "My fourth Jira", "assignee": "Busy Bob", "status": "In Progress" }, { "id": "XXX-5", "summary": "My fifth Jira", "assignee": "Busy Bob", "status": "In Progress" }, { "id": "XXX-6", "summary": "My sixth Jira", "assignee": "Lazy Susan", "status": "In Progress" }, ]) slack = MockSlack() bot = JiraBot(jira, slack, "XXX", "LABEL", None, "#chan1", 3, logger=self.logger, supress_quotes=True) bot.send_periodic_update() self.assertEqual(len(slack.outgoing_messages), 1) self.assertEqual("#chan1", slack.outgoing_messages[0]["recipient"]) self.assertEqual( ":warning: *Busy Bob* currently has 5 jira issues in progress. That's too many. Here's a list: XXX-1, XXX-2, XXX-3, XXX-4, XXX-5", slack.outgoing_messages[0]["message"])
def test_request_to_show_everything_after_sending_update(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) bot.send_periodic_update() self.assertEqual(3, len(slack.outgoing_messages)) slack.add_incoming({u'text': u'<@BOTID> show errors'}) bot.process_messages() self.assertEqual(4, len(slack.outgoing_messages))
def test_message_sent_if_issue_assigned_but_not_in_progress(self): jira = MockJira(issues=[ { "id": "XXX-1", "summary": "My first Jira", "assignee": "Fred Bloggs", "status": "Backlog" }, { "id": "XXX-2", "summary": "My second Jira", "assignee": "None", "status": "Backlog" }, { "id": "XXX-3", "summary": "My third Jira", "assignee": "Fred Jones", "status": "In Progress" }, ]) slack = MockSlack() bot = JiraBot(jira, slack, "XXX", "LABEL", None, "#channel_name", 3, logger=self.logger, supress_quotes=True) bot.send_periodic_update() self.assertEqual(len(slack.outgoing_messages), 1) self.assertEqual("#channel_name", slack.outgoing_messages[0]["recipient"]) self.assertEqual( ':warning: XXX-1 is assigned to *Fred Bloggs* but still in the Backlog state', slack.outgoing_messages[0]["message"])
def test_message_sent_if_issue_in_progress_but_not_assigned(self): jira = MockJira(issues=[ { "id": "XXX-1", "summary": "My first Jira", "assignee": "Cheesy Phil", "status": "In Progress" }, { "id": "XXX-2", "summary": "My second Jira", "assignee": "None", "status": "In Progress" }, { "id": "XXX-3", "summary": "My third Jira", "assignee": "Fred Jones", "status": "In Progress" }, ]) slack = MockSlack() bot = JiraBot(jira, slack, "XXX", "LABEL", None, "#the_channel", logger=self.logger, supress_quotes=True) bot.send_periodic_update() self.assertEqual(1, len(slack.outgoing_messages)) self.assertEqual("#the_channel", slack.outgoing_messages[0]["recipient"]) self.assertEqual( ":warning: XXX-2 is marked as In Progress but not assigned to anyone", slack.outgoing_messages[0]["message"])
def test_name_lookups_for_mentions(self): jira = MockJira(issues=[{ "id": "XXX-1", "summary": "My first Jira", "assignee": "Fred Bloggs", "status": "Backlog" }]) slack = MockSlack(name_lookup={"Fred Bloggs": "BLOGGSID"}) bot = JiraBot(jira, slack, "XXX", "LABEL", None, "#channel_name", 3, logger=self.logger, supress_quotes=True) bot.send_periodic_update() self.assertEqual(len(slack.outgoing_messages), 1) self.assertEqual("#channel_name", slack.outgoing_messages[0]["recipient"]) self.assertEqual( ':warning: XXX-1 is assigned to <@BLOGGSID> but still in the Backlog state', slack.outgoing_messages[0]["message"])
def test_new_issues_not_repeated_in_channel(self): jira = MockJira(issues=[{ "id": "AAA-2", "summary": "I am new", "status": "Backlog", "created": u'2016-08-10T07:55:00.000+0100' }, { "id": "AAA-1", "summary": "I am not new", "status": "Backlog", "created": u'2016-08-08T14:50:36.000+0100' }]) slack = MockSlack() bot = JiraBot(jira, slack, "AAA", "LABEL", None, "#things", logger=self.logger, supress_quotes=True) bot.send_periodic_update() bot.send_periodic_update() self.assertEqual(3, len(slack.outgoing_messages))
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)