async def get_batches(request, userdata): # pylint: disable=unused-argument batch_client = request.app['batch_client'] batches = await batch_client.list_batches() statuses = [await b.status() for b in batches] context = base_context(deploy_config, userdata, 'ci') context['batches'] = statuses return context
async def html_get_user(request, userdata): context = base_context(deploy_config, userdata, 'scorecard') user = request.match_info['user'] user_data, updated = get_user(user) context['user'] = user context['user_data'] = user_data context['updated'] = updated return context
async def get_job_log(request, userdata): # pylint: disable=unused-argument batch_id = int(request.match_info['batch_id']) job_id = int(request.match_info['job_id']) batch_client = request.app['batch_client'] job = await batch_client.get_job(batch_id, job_id) context = base_context(deploy_config, userdata, 'ci') context['batch_id'] = batch_id context['job_id'] = job_id context['job_log'] = await job.log() return context
async def index(request, userdata): # pylint: disable=unused-argument context = base_context(deploy_config, userdata, 'scorecard') user_data, unassigned, urgent_issues, updated = get_users() component_random_user = {c: random.choice(us) for c, us in component_users.items()} context['unassigned'] = unassigned context['user_data'] = user_data context['urgent_issues'] = urgent_issues context['component_user'] = component_random_user context['updated'] = updated return context
async def get_job_pod_status(request, userdata): # pylint: disable=unused-argument batch_id = int(request.match_info['batch_id']) job_id = int(request.match_info['job_id']) batch_client = request.app['batch_client'] job = await batch_client.get_job(batch_id, job_id) context = base_context(deploy_config, userdata, 'ci') context['batch_id'] = batch_id context['job_id'] = job_id context['job_pod_status'] = json.dumps(json.loads(await job.pod_status()), indent=2) return context
async def get_batch(request, userdata): # pylint: disable=unused-argument batch_id = int(request.match_info['batch_id']) batch_client = request.app['batch_client'] b = await batch_client.get_batch(batch_id) status = await b.status() for j in status['jobs']: j['duration'] = humanize.naturaldelta(Job.total_duration(j)) j['exit_code'] = Job.exit_code(j) context = base_context(deploy_config, userdata, 'ci') context['batch'] = status return context
async def get_pr(request, userdata): # pylint: disable=unused-argument watched_branch_index = int(request.match_info['watched_branch_index']) pr_number = int(request.match_info['pr_number']) if watched_branch_index < 0 or watched_branch_index >= len( watched_branches): raise web.HTTPNotFound() wb = watched_branches[watched_branch_index] if not wb.prs or pr_number not in wb.prs: raise web.HTTPNotFound() pr = wb.prs[pr_number] config = base_context(deploy_config, userdata, 'ci') config['repo'] = wb.branch.repo.short_str() config['number'] = pr.number # FIXME if pr.batch: if hasattr(pr.batch, 'id'): status = await pr.batch.status() for j in status['jobs']: j['duration'] = humanize.naturaldelta(Job.total_duration(j)) j['exit_code'] = Job.exit_code(j) attrs = j['attributes'] if 'link' in attrs: attrs['link'] = attrs['link'].split(',') config['batch'] = status config[ 'artifacts'] = f'{BUCKET}/build/{pr.batch.attributes["token"]}' else: config['exception'] = '\n'.join( traceback.format_exception(None, pr.batch.exception, pr.batch.exception.__traceback__)) batch_client = request.app['batch_client'] batches = await batch_client.list_batches(attributes={ 'test': '1', 'pr': pr_number }) batches = sorted(batches, key=lambda b: b.id, reverse=True) config['history'] = [await b.status() for b in batches] return config
async def index(request, userdata): # pylint: disable=unused-argument app = request.app dbpool = app['dbpool'] wb_configs = [] for i, wb in enumerate(watched_branches): if wb.prs: pr_configs = [] for pr in wb.prs.values(): batch_id = pr.batch.id if pr.batch and hasattr(pr.batch, 'id') else None build_state = pr.build_state if await pr.authorized( dbpool) else 'unauthorized' if build_state is None and batch_id is not None: build_state = 'building' pr_config = { 'number': pr.number, 'title': pr.title, # FIXME generate links to the merge log 'batch_id': pr.batch.id if pr.batch and hasattr(pr.batch, 'id') else None, 'build_state': build_state, 'review_state': pr.review_state, 'author': pr.author, 'out_of_date': pr.build_state in ['failure', 'success', None] and not pr.is_up_to_date(), } pr_configs.append(pr_config) else: pr_configs = None # FIXME recent deploy history wb_config = { 'index': i, 'branch': wb.branch.short_str(), 'sha': wb.sha, # FIXME generate links to the merge log 'deploy_batch_id': wb.deploy_batch.id if wb.deploy_batch and hasattr(wb.deploy_batch, 'id') else None, 'deploy_state': wb.deploy_state, 'repo': wb.branch.repo.short_str(), 'prs': pr_configs, } wb_configs.append(wb_config) token = new_csrf_token() context = base_context(deploy_config, userdata, 'ci') context['watched_branches'] = wb_configs context['age'] = humanize.naturaldelta(datetime.datetime.now() - start_time) context['token'] = token response = aiohttp_jinja2.render_template('index.html', request, context) response.set_cookie('_csrf', token, secure=True, httponly=True) return response