def convert_commit(self, commit): commit = utils.ObjectLike(commit) return {'author': commit.author, 'distinct': commit.distinct, 'added': commit.added, 'modified': commit.modified, 'removed': commit.removed, 'message': commit.message, 'url': commit.url, 'hash': commit.id}
def get_pr_review_comments(owner_and_repo, pr_id, review_id): json = requests.get( 'https://api.github.com/repos/%s/pulls/%d/reviews/%d/comments' % (owner_and_repo, pr_id, review_id), headers={'Content-Type': 'application/json', # This API is currently in preview so we need to specify this, # but it will continue to work after the preview period ends. 'Accept': 'application/vnd.github.black-cat-preview+json'}, auth=basic_auth()).json() return [utils.ObjectLike(c) for c in json]
def dispatch(self, source, evt): transmitted = {'source': source} transmitted.update(evt) transmitted = utils.ObjectLike(transmitted) for tgt in self.targets: try: if tgt.accept_event(transmitted): tgt.push_event(transmitted) except Exception: logging.exception('Failed to pass event to %r' % tgt) continue
def run(self): while True: evt = self.queue.get() builder = evt.builder.name props = utils.ObjectLike( {k: v[0] for k, v in evt.properties.items()}) has_all_required = True for required in ('headrev', 'repo', 'shortrev'): if required not in props: has_all_required = False break if not has_all_required: continue headrev = props.headrev repo = props.repo pr_id = props.pr_id shortrev = props.shortrev pending = not evt.complete success = evt.results in (0, 1) # SUCCESS/WARNING if builder in cfg.buildbot.pr_builders: if pending: description = 'Auto build in progress on builder %s' % builder elif success: description = 'Build succeeded on builder %s' % builder else: description = 'Build failed on builder %s' % builder evt = events.BuildStatus(repo, headrev, shortrev, builder, pr_id, success, pending, evt.url, description) events.dispatcher.dispatch('buildbot', evt) elif pr_id and builder in cfg.buildbot.fifoci_builders and success: evt = events.PullRequestFifoCIStatus(repo, headrev, builder, pr_id) events.dispatcher.dispatch('buildbot', evt)
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))
"""Configuration system for Dolphin Central. Loads a single configuration file at initialization time and provides access to the configuration as a global 'cfg' object. """ import utils import yaml cfg = utils.ObjectLike({}) def load(fp): """Loads the configuration from a file-like object.""" cfg.reset(yaml.load(fp))