예제 #1
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))))
예제 #2
0
파일: ircclient.py 프로젝트: hackbar/sadm
 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))))
예제 #3
0
파일: ircclient.py 프로젝트: hackbar/sadm
    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))))
예제 #4
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))))
예제 #5
0
    def on_channel_message(self, who, channel, msg):
        direct = msg.startswith(self.cfg.nick)

        if direct:
            self.message(channel, Tags.LtGreen(Tags.Bold('WARK WARK WARK')))

        modes = who.user.modes_in(channel)
        evt = events.IRCMessage(str(who), channel, msg, modes, direct)
        events.dispatcher.dispatch('ircclient', evt)
예제 #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))))
예제 #7
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)
예제 #8
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))))
예제 #9
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))))
예제 #10
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)
예제 #11
0
 def check_last(self, rid, user, repo, channel):
     try:
         last_commits = self.get_last_commits(user, repo)
     except:
         return
     nb_commits = min(last_commits['limit'], last_commits['count'])
     logging.debug(last_commits)
     lc = last_commits['changesets'][nb_commits - 1]
     if not rid in self.bot.last_commits:
         self.bot.last_commits[rid] = lc
         return
     if lc['node'] == self.bot.last_commits[rid]['node']:
         return
     self.bot.last_commits[rid] = lc
     url = 'https://bitbucket.org/{}/{}/changeset/{}'.format(
             user, repo, lc['raw_node'])
     params = {
         'node': Tags.Red(lc['node']),
         'author': Tags.Green(lc['author']),
         'branch': Tags.Blue(lc['branch']),
         'message': lc['message'].strip(),
         'url': shortenurl(url),
     }
     self.bot.message(channel, rdc('commit').format(**params))
예제 #12
0
    def on_message(self, umask, target, msg):
        if umask.host not in self.bot.admins:
            return

        parts = msg.split()
        if msg.startswith('!snip ') and len(parts) >= 3:
            self.snippets[parts[1]] = ' '.join(parts[2:])

        if msg.startswith('!unsnip ') and len(parts) >= 2:
            try:
                del self.snippets[parts[1]]
            except KeyError:
                pass

        if msg.startswith('.') and parts[0][1:] in self.snippets:
            try:
                exec(self.snippets[parts[0][1:]], locals(), globals())
            except Exception as ex:
                self.bot.message(target, Tags.Bold('Exception: ') + repr(ex))
예제 #13
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))))
예제 #14
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))
예제 #15
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))))
예제 #16
0
파일: lodgeit.py 프로젝트: Zopieux/pypeul
 def help(self, cmd, args):
     out = '%s: %s %s' % (Tags.Green('usage'), Tags.Bold(cmd), args)
     self.bot.message(target, out)
예제 #17
0
 def format_nickname(self, nickname, avoid_hl=True):
     # Add a unicode zero-width space in the nickname to avoid highlights.
     if avoid_hl and nickname:
         nickname = nickname[0] + '\ufeff' + nickname[1:]
     return Tags.Green(nickname)
예제 #18
0
 def on_channel_message(self, umask, channel, msg):
     msg = Tags.strip(msg)