Exemple #1
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))
Exemple #2
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)
Exemple #3
0
 def help(self, cmd, args):
     out = '%s: %s %s' % (Tags.Green('usage'), Tags.Bold(cmd), args)
     self.bot.message(target, out)
Exemple #4
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(Tags.Black('[' + 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 = Tags.Green(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))