Example #1
0
 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"])
Example #2
0
 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"])
Example #3
0
 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"])
Example #4
0
 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))
Example #5
0
 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))
Example #6
0
 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)
Example #7
0
 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"])
Example #8
0
    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
Example #9
0
 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"])
Example #10
0
 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"])
Example #11
0
 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"])
Example #12
0
 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))
Example #13
0
    file_handler = logging.handlers.RotatingFileHandler(
        "/var/log/jirabot/jirabot.log", maxBytes=10485760, backupCount=10)
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)
    logger.setLevel(args.log_level)
    logger.addHandler(stream_handler)

    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