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))))
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))
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))