Skip to content

Commit 566f39f

Browse files
authored
[ci] Add deploy batch link for merged PRs (#15325)
## Change Description Updates our PR pages with a "deploy batch" record for already-merged PRs. Example from a recent merged PR: <img width="960" height="339" alt="image" src="https://github.com/user-attachments/assets/5c73b31a-57e2-4e9e-a8e7-1ac67be36c8b" /> ## Security Assessment - This change potentially impacts the Hail Batch instance as deployed by Broad Institute in GCP ### Impact Rating - This change has a low security impact ### Impact Description Readonly change to a UI element to make historical deployment tracking easier ### Appsec Review - [ ] Required: The impact has been assessed and approved by appsec
1 parent 292a689 commit 566f39f

2 files changed

Lines changed: 69 additions & 25 deletions

File tree

ci/ci/ci.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ async def _populate_historical_pr_context(
248248
'number': gh_pr['number'],
249249
'labels': [label['name'] for label in gh_pr.get('labels', [])],
250250
'merged': gh_pr['merged'],
251+
'merge_commit_sha': gh_pr.get('merge_commit_sha') if gh_pr['merged'] else None,
251252
}
252253
except gidgethub.HTTPException as e:
253254
if e.status_code == 404:
@@ -293,6 +294,27 @@ async def get_pr(request: web.Request, userdata: UserData) -> web.Response:
293294
await _populate_batch_context(page_context, batches[0])
294295
page_context['history'] = [await b.last_known_status() for b in batches]
295296

297+
deploy_batches = []
298+
pr_data = page_context.get('pr')
299+
if (
300+
not page_context['active_pr']
301+
and isinstance(pr_data, dict)
302+
and pr_data.get('merged')
303+
and pr_data.get('merge_commit_sha')
304+
):
305+
merge_commit_sha = pr_data['merge_commit_sha']
306+
deploy_batches = sorted(
307+
[
308+
b
309+
async for b in batch_client.list_batches(
310+
f'deploy=1 target_branch={wb.branch.short_str()} sha={merge_commit_sha} user:ci'
311+
)
312+
],
313+
key=lambda b: b.id,
314+
reverse=True,
315+
)
316+
page_context['deploy_batches'] = [await b.last_known_status() for b in deploy_batches]
317+
296318
return await render_template('ci', request, userdata, 'pr.html', page_context)
297319

298320

ci/ci/templates/pr.html

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@
44
{% block head %}
55
<script defer src="{{ base_path }}/common_static/focus_on_keyup.js"></script>
66
{% endblock %}
7+
8+
{% macro batch_state_icon(state) %}
9+
{% if state == 'success' %}
10+
<span class="material-symbols-outlined" style="color: green; vertical-align: middle; font-size: 1.3rem; font-variation-settings: 'FILL' 1, 'wght' 700;">check_circle</span>
11+
{% elif state in ('failure', 'error') %}
12+
<span class="material-symbols-outlined" style="color: red; vertical-align: middle; font-size: 1.3rem; font-variation-settings: 'FILL' 1, 'wght' 700;">cancel</span>
13+
{% elif state == 'cancelled' %}
14+
<span class="material-symbols-outlined" style="color: grey; vertical-align: middle; font-size: 1.3rem; font-variation-settings: 'FILL' 1, 'wght' 700;">block</span>
15+
{% endif %}
16+
{% endmacro %}
17+
18+
{% macro batch_history_table(batches) %}
19+
<table class="data-table">
20+
<thead>
21+
<tr>
22+
<th>id</th>
23+
<th>state</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
{% for batch in batches %}
28+
<tr>
29+
<td class="numeric-cell">
30+
<a rel="noopener" href="{{ batch_base_url }}/batches/{{ batch['id'] }}">{{ batch['id'] }}</a>
31+
</td>
32+
<td>
33+
{% if 'state' in batch and batch['state'] %}
34+
{{ batch_state_icon(batch['state']) }} {{ batch['state'] }}
35+
{% endif %}
36+
</td>
37+
</tr>
38+
{% endfor %}
39+
</tbody>
40+
</table>
41+
{% endmacro %}
42+
743
{% block content %}
844
<h1>{{ pr.title }} <a rel="noopener" href="https://github.com/{{ repo }}/pull/{{ pr.number }}"><span class="gh-number">#{{ pr.number }}</span></a></h1>
945
<div class="attributes">
@@ -93,6 +129,7 @@ <h2>Merge Queue</h2>
93129
</div>
94130
{% endif %}
95131

132+
{% if active_pr %}
96133
<h2>Current Build</h2>
97134
{% if batch is defined %}
98135
<div class="attributes">
@@ -131,7 +168,6 @@ <h3>Jobs</h3>
131168
{{ exception }}
132169
</pre>
133170
{% else %}
134-
{% if active_pr %}
135171
{% if pr_authorized %}
136172
<p>Build queued - waiting for a build slot. <a href="{{ ci_base_url }}">View CI dashboard</a>.</p>
137173
{% else %}
@@ -142,35 +178,21 @@ <h3>Jobs</h3>
142178
<button type="submit">Authorize now</button>
143179
</form>
144180
{% endif %}
181+
{% endif %}
182+
{% endif %}
183+
184+
{% if not active_pr and pr.merged %}
185+
<h2>Deploy Batch History</h2>
186+
{% if deploy_batches %}
187+
{{ batch_history_table(deploy_batches) }}
145188
{% else %}
146-
<p>No builds found.</p>
189+
<p>No deploy batch found.</p>
147190
{% endif %}
148191
{% endif %}
149192

150-
<h2>Build History</h2>
193+
<h2>Build Batch History</h2>
151194
{% if history %}
152-
<table class="data-table">
153-
<thead>
154-
<tr>
155-
<th>id</th>
156-
<th>state</th>
157-
</tr>
158-
</thead>
159-
<tbody>
160-
{% for batch in history %}
161-
<tr>
162-
<td class="numeric-cell">
163-
<a rel="noopener" href="{{ batch_base_url }}/batches/{{ batch['id'] }}">{{ batch['id'] }}</a>
164-
</td>
165-
<td>
166-
{% if 'state' in batch and batch['state'] %}
167-
{{ batch['state'] }}
168-
{% endif %}
169-
</td>
170-
</tr>
171-
{% endfor %}
172-
</tbody>
173-
</table>
195+
{{ batch_history_table(history) }}
174196
{% else %}
175197
No builds.
176198
{% endif %}

0 commit comments

Comments
 (0)