Example #1
0
 def handle_issue(self, evt):
     """Sends an IRC message notifying of a new issue update."""
     author = self.format_nickname(evt.author)
     if evt.new:
         short_url = 'https://dolp.in/i%d' % evt.issue
         url = Tags.UnderlineBlue(short_url)
         msg = 'Issue %d created: "%s" by %s - %s'
         msg = msg % (evt.issue, evt.title, author, url)
     else:
         short_url = 'https://dolp.in/i%d/%d' % (evt.issue, evt.update)
         url = Tags.UnderlineBlue(short_url)
         msg = 'Update %d to issue %d ("%s") by %s - %s'
         msg = msg % (evt.update, evt.issue, evt.title, author, url)
     self.bot.say(msg)
Example #2
0
 def handle_gh_pull_request_comment(self, evt):
     if evt.is_part_of_review or evt.action != 'created':
         return
     self.bot.say('[%s] %s commented on #%s %s: %s' %
                  (Tags.UnderlinePink(evt.repo),
                   self.format_nickname(evt.author), evt.id, evt.hash[:6],
                   Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #3
0
    def handle_gh_pull_request_review(self, evt):
        # GitHub sends a review event in addition to a review comment event
        # when someone replies to an earlier comment or adds a single comment,
        # even when they didn't really submit a pull request review.
        # To prevent useless notifications, we skip any "review" which only has
        # one comment, since there is already a comment notification for those.
        if len(evt.comments) == 1 and \
            evt.comments[0].created_at == evt.comments[0].updated_at:
            return

        if evt.state == 'pending':
            return

        if evt.action == 'submitted' and evt.state == 'approved':
            action = 'approved'
            if len(evt.comments) != 0:
                action += ' and commented on'
        elif evt.action == 'submitted' and evt.state == 'commented':
            action = 'reviewed and commented on'
        elif evt.action == 'submitted' and evt.state == 'changes_requested':
            action = 'requested changes to'
        elif evt.state == 'dismissed':
            action = 'dismissed their review on'
        else:
            action = '%s review on' % evt.action
        self.bot.say(
            '[%s] %s %s pull request #%s (%s): %s' %
            (Tags.UnderlinePink(evt.repo), self.format_nickname(
                evt.author), action, evt.pr_id, evt.pr_title,
             Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #4
0
 def handle_gh_pull_request(self, evt):
     self.bot.say(
         '[%s] %s %s pull request #%d: %s (%s...%s): %s' %
         (Tags.UnderlinePink(evt.repo), self.format_nickname(
             evt.author), evt.action, evt.id, evt.title,
          Tags.Purple(evt.base_ref_name), Tags.Purple(evt.head_ref_name),
          Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #5
0
 def handle_gh_issue_comment(self, evt):
     if evt.author == cfg.github.account.login:
         return
     self.bot.say('[%s] %s commented on #%s (%s): %s' %
                  (Tags.UnderlinePink(evt.repo),
                   self.format_nickname(evt.author), evt.id, evt.title,
                   Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #6
0
 def handle_gh_issue_comment(self, evt):
     if evt.author == cfg.github.account.login:
         return
     if evt.action == 'created':
         action = 'commented on'
     else:
         action = '%s a comment on' % evt.action
     self.bot.say('[%s] %s %s #%s (%s): %s' % (
         Tags.UnderlinePink(evt.repo), self.format_nickname(evt.author),
         action, evt.id, evt.title, Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #7
0
 def handle_gcode_issue(self, evt):
     """Sends an IRC message notifying of a new GCode issue update."""
     author = self.format_nickname(evt.author)
     url = Tags.UnderlineBlue(utils.shorten_url(evt.url))
     if evt.new:
         msg = 'Issue %d created: "%s" by %s - %s'
         msg = msg % (evt.issue, evt.title, author, url)
     else:
         msg = 'Update %d to issue %d ("%s") by %s - %s'
         msg = msg % (evt.update, evt.issue, evt.title, author, url)
     self.bot.say(msg)
Example #8
0
    def handle_build_status_settled(self, evts):
        per_shortrev = {}
        for evt in evts:
            per_shortrev.setdefault(evt.shortrev, []).append(evt)
        for shortrev, evts in per_shortrev.items():
            builders = [evt.service for evt in evts]
            builders.sort()

            evt = evts[0]
            if evt.pr is not None:
                shortrev = '#%s' % evt.pr
            self.bot.say('[%s] build for %s %s on builders [%s]: %s' %
                         (Tags.UnderlinePink(evt.repo), shortrev,
                          Tags.Red('failed'), ', '.join(builders),
                          Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #9
0
 def handle_gh_pull_request(self, evt):
     action = evt.action
     if action == 'synchronize':
         action = 'synchronized'
     elif action == 'review_requested':
         action = 'requested a review from %s for' % ', '.join([user.login for user in evt.requested_reviewers])
     elif action == 'review_request_removed':
         action = 'dismissed a review request on'
     elif action == 'closed' and evt.merged:
         action = 'merged'
     self.bot.say('[%s] %s %s pull request #%d: %s (%s...%s): %s' % (
         Tags.UnderlinePink(evt.repo), self.format_nickname(evt.author),
         action, evt.id, evt.title, Tags.Purple(evt.base_ref_name),
         Tags.Purple(evt.head_ref_name),
         Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #10
0
 def handle_gh_commit_comment(self, evt):
     self.bot.say('[%s] %s commented on commit %s: %s' % (
         Tags.UnderlinePink(evt.repo), self.format_nickname(evt.author),
         evt.commit, Tags.UnderlineBlue(utils.shorten_url(evt.url))))
Example #11
0
    def handle_gh_push(self, evt):
        fmt_url = Tags.UnderlineBlue
        fmt_repo_name = Tags.UnderlinePink
        fmt_ref = Tags.Purple
        fmt_hash = lambda h: Tags.Grey(h[:6])

        commits = [utils.ObjectLike(c) for c in evt.commits]
        distinct_commits = [c for c in commits
                            if c.distinct and c.message.strip()]
        num_commits = len(distinct_commits)

        parts = []
        parts.append('[' + fmt_repo_name(evt.repo) + ']')
        parts.append(self.format_nickname(evt.pusher))

        if evt.created:
            if evt.ref_type == 'tags':
                parts.append('tagged ' + fmt_ref(evt.ref_name) + ' at')
                parts.append(fmt_ref(evt.base_ref_name)
                             if evt.base_ref_name else fmt_hash(evt.after_sha))
            else:
                parts.append('created ' + fmt_ref(evt.ref_name))
                if evt.base_ref_name:
                    parts.append('from ' + fmt_ref(evt.base_ref_name))
                elif not distinct_commits:
                    parts.append('at ' + fmt_hash(evt.after_sha))

                if distinct_commits:
                    parts.append('+' + Tags.Bold(str(num_commits)))
                    parts.append('new commit' + ('s'
                                                 if num_commits > 1 else ''))
        elif evt.deleted:
            parts.append(Tags.Red('deleted ') + fmt_ref(evt.ref_name))
            parts.append('at ' + fmt_hash(evt.before_sha))
        elif evt.forced:
            parts.append(Tags.Red('force-pushed ') + fmt_ref(evt.ref_name))
            parts.append('from ' + fmt_hash(evt.before_sha) + ' to ' +
                         fmt_hash(evt.after_sha))
        elif commits and not distinct_commits:
            if evt.base_ref_name:
                parts.append('merged ' + fmt_ref(evt.base_ref_name) + ' into '
                             + fmt_ref(evt.ref_name))
            else:
                parts.append('fast-forwarded ' + fmt_ref(evt.ref_name))
                parts.append('from ' + fmt_hash(evt.before_sha) + ' to ' +
                             fmt_hash(evt.after_sha))
        else:
            parts.append('pushed ' + Tags.Bold(str(num_commits)))
            parts.append('new commit' + ('s' if num_commits > 1 else ''))
            parts.append('to ' + fmt_ref(evt.ref_name))

        self.bot.say(' '.join(str(p) for p in parts))

        for commit in distinct_commits[:4]:
            firstline = commit.message.split('\n')[0]
            author = self.format_nickname(commit.author.name)
            added = Tags.LtGreen(str(len(commit.added)))
            modified = Tags.LtGreen(str(len(commit.modified)))
            removed = Tags.Red(str(len(commit.removed)))
            url = Tags.UnderlineBlue(utils.shorten_url(commit.url))
            self.bot.say('%s by %s [%s|%s|%s] %s %s' %
                         (commit.hash[:6], author, added, modified, removed,
                          url, firstline))

        if len(distinct_commits) > 4:
            self.bot.say('... and %d more commits' %
                         (len(distinct_commits) - 4))
Example #12
0
 def handle_gh_pull_request_comment(self, evt):
     self.bot.say('[%s] %s commented on #%s %s: %s' %
                  (Tags.UnderlinePink(evt.repo),
                   self.format_nickname(evt.author), evt.id, evt.hash[:6],
                   Tags.UnderlineBlue(utils.shorten_url(evt.url))))