@app-vitals/agent-admin 1.33.0 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/openapi.platform.json +368 -0
- package/package.json +2 -2
- package/src/admin-boot.ts +9 -0
- package/src/admin-ui-github-identity.smoke.test.ts +2 -2
- package/src/admin-ui-github-reconcile-pages.unit.test.ts +6 -2
- package/src/admin-ui-installation-repos-pages.ts +404 -0
- package/src/admin-ui-installation-repos-pages.unit.test.ts +57 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +497 -0
- package/src/admin-ui-pages.ts +57 -9
- package/src/admin-ui.ts +269 -1
- package/src/agents-api.smoke.test.ts +277 -1
- package/src/agents-api.ts +226 -0
- package/src/github-reconcile-wiring.ts +22 -0
- package/src/lost-access-removal.ts +333 -0
- package/src/lost-access-removal.unit.test.ts +467 -0
- package/src/reconcile-planner.ts +26 -11
- package/src/repo-removal-open-work.ts +11 -6
- package/src/repo-removal-open-work.unit.test.ts +24 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-installation-repos-pages.ts
|
|
3
|
+
* Pure renderers for the agent detail page's "Installation repos" card
|
|
4
|
+
* (IRM-1.4), which replaces the plan-first Reconcile card: the repos on the
|
|
5
|
+
* agent App's installation per org with add/remove, the user-can-push hint,
|
|
6
|
+
* and a button that removes repos the bound user can no longer push to (IRM-1.3)
|
|
7
|
+
* after an explicit confirmation. It also renders the open-work lists shown
|
|
8
|
+
* before and after a removal (IRM-1.7) and the coverage warning on the agent's
|
|
9
|
+
* repos list. Platform-admin only; the caller decides visibility. Every dynamic
|
|
10
|
+
* value is escaped. Inputs carry repo names and ids only.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
14
|
+
import { MAX_UNCONFIRMED_REMOVALS } from "./reconcile-apply-service.ts";
|
|
15
|
+
|
|
16
|
+
export interface OpenWorkView {
|
|
17
|
+
id: string;
|
|
18
|
+
repo: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** JSON body of GET /agents/:id/github-installation/repos. */
|
|
23
|
+
export interface InstallationReposView {
|
|
24
|
+
appId?: number;
|
|
25
|
+
orgs: {
|
|
26
|
+
org: string;
|
|
27
|
+
repos: { fullName: string; userCanPush?: boolean }[];
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** JSON body of GET /agents/:id/github-lost-access/preview. */
|
|
32
|
+
export interface LostAccessPreviewView {
|
|
33
|
+
status: "previewed" | "skipped";
|
|
34
|
+
reason?: string;
|
|
35
|
+
repos?: string[];
|
|
36
|
+
installationRemoves?: string[];
|
|
37
|
+
configRemoves?: string[];
|
|
38
|
+
skippedOrgs?: { org: string; reason: string }[];
|
|
39
|
+
openWork?: OpenWorkView[];
|
|
40
|
+
warnings?: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** JSON body of POST /agents/:id/github-lost-access/remove. */
|
|
44
|
+
export interface LostAccessRemoveView {
|
|
45
|
+
status: "applied" | "noop" | "skipped";
|
|
46
|
+
reason?: string;
|
|
47
|
+
auditId?: string;
|
|
48
|
+
repos?: string[];
|
|
49
|
+
installationRemoves?: string[];
|
|
50
|
+
configRemoves?: string[];
|
|
51
|
+
notRemoved?: { repo: string; reason: string }[];
|
|
52
|
+
skippedOrgs?: { org: string; reason: string }[];
|
|
53
|
+
warnings?: string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** JSON body of GET /agents/:id/repos/:owner/:name/removal-preview. */
|
|
57
|
+
export interface RepoRemovalPreviewView {
|
|
58
|
+
repo: string;
|
|
59
|
+
openWork: OpenWorkView[];
|
|
60
|
+
warnings: string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const NO_USERNAME_REASON =
|
|
64
|
+
"No GitHub username is bound to this agent, so repos the user can no longer push to cannot be found. Bind a username above to enable this.";
|
|
65
|
+
export const INSTALLER_UNCONFIGURED_REASON =
|
|
66
|
+
"The installer GitHub App is not configured, so the agent App's installation repos cannot be listed or changed.";
|
|
67
|
+
|
|
68
|
+
const lc = (s: string): string => s.toLowerCase();
|
|
69
|
+
|
|
70
|
+
/** Link for an open-work item: a `owner/repo#N` id is a PR on GitHub. */
|
|
71
|
+
function workLabel(item: OpenWorkView): string {
|
|
72
|
+
const pr = /^([\w.-]+\/[\w.-]+)#(\d+)$/.exec(item.id);
|
|
73
|
+
const id = escapeHtml(item.id);
|
|
74
|
+
if (!pr) return `<span class="mono">${id}</span>`;
|
|
75
|
+
const url = `https://github.com/${pr[1]}/pull/${pr[2]}`;
|
|
76
|
+
return `<a class="mono" href="${escapeHtml(url)}" target="_blank" rel="noopener noreferrer">${id}</a>`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Open work grouped per repo, linked. Empty input renders a plain note. */
|
|
80
|
+
export function renderOpenWorkByRepo(
|
|
81
|
+
work: readonly OpenWorkView[],
|
|
82
|
+
heading: string,
|
|
83
|
+
emptyNote: string,
|
|
84
|
+
): string {
|
|
85
|
+
if (work.length === 0) {
|
|
86
|
+
return `<p class="empty-state" data-open-work="none">${escapeHtml(emptyNote)}</p>`;
|
|
87
|
+
}
|
|
88
|
+
const byRepo = new Map<string, OpenWorkView[]>();
|
|
89
|
+
for (const w of work) byRepo.set(w.repo, [...(byRepo.get(w.repo) ?? []), w]);
|
|
90
|
+
const groups = [...byRepo]
|
|
91
|
+
.map(
|
|
92
|
+
([repo, items]) =>
|
|
93
|
+
`<div style="margin-top:6px"><span class="mono" style="font-weight:600">${escapeHtml(repo)}</span><ul style="margin:4px 0 0 18px">${items
|
|
94
|
+
.map(
|
|
95
|
+
(w) =>
|
|
96
|
+
`<li>${workLabel(w)}${w.title ? ` ${escapeHtml(w.title)}` : ""}</li>`,
|
|
97
|
+
)
|
|
98
|
+
.join("")}</ul></div>`,
|
|
99
|
+
)
|
|
100
|
+
.join("");
|
|
101
|
+
return `<div class="alert alert-warning" data-open-work="list"><div style="font-weight:600">${escapeHtml(heading)}</div>${groups}</div>`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function warningsHtml(warnings: readonly string[] | undefined): string {
|
|
105
|
+
return (warnings ?? []).length === 0
|
|
106
|
+
? ""
|
|
107
|
+
: `<div class="alert alert-warning" data-warnings="1">${(warnings ?? []).map((w) => `<div>${escapeHtml(w)}</div>`).join("")}</div>`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function skippedOrgsHtml(
|
|
111
|
+
skipped: readonly { org: string; reason: string }[] | undefined,
|
|
112
|
+
): string {
|
|
113
|
+
return (skipped ?? []).length === 0
|
|
114
|
+
? ""
|
|
115
|
+
: `<div class="alert alert-warning" data-skipped-orgs="1">Skipped organizations (nothing was removed there):<ul style="margin:6px 0 0 18px">${(skipped ?? []).map((o) => `<li><span class="mono">${escapeHtml(o.org)}</span>: ${escapeHtml(o.reason)}</li>`).join("")}</ul></div>`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The card shell; it loads its body fragment from the UI route on page load. */
|
|
119
|
+
export function renderInstallationReposCard(agentId: string): string {
|
|
120
|
+
const base = `/admin/agents/${escapeHtml(agentId)}/github-installation`;
|
|
121
|
+
return `<div class="card" id="github-installation-card" data-base-url="${base}">
|
|
122
|
+
<div class="card-title">Installation repos</div>
|
|
123
|
+
<p style="color:#6b7280;font-size:12px;margin:0 0 12px">The repos on this agent's own GitHub App installation, per organization. Changes apply immediately and are audited; the agent's configured repos are not changed here.</p>
|
|
124
|
+
<div id="github-installation-body">Loading...</div>
|
|
125
|
+
<div id="github-installation-result" style="margin-top:12px"></div>
|
|
126
|
+
<script>
|
|
127
|
+
(function() {
|
|
128
|
+
var card = document.getElementById('github-installation-card');
|
|
129
|
+
var body = document.getElementById('github-installation-body');
|
|
130
|
+
var out = document.getElementById('github-installation-result');
|
|
131
|
+
if (!card || !body || !out) return;
|
|
132
|
+
var base = card.getAttribute('data-base-url');
|
|
133
|
+
function text(r) { return r.text(); }
|
|
134
|
+
function fail() { out.textContent = 'The request failed.'; }
|
|
135
|
+
function load() {
|
|
136
|
+
return fetch(base, { credentials: 'same-origin' }).then(text)
|
|
137
|
+
.then(function(t) { body.innerHTML = t; })
|
|
138
|
+
.catch(function() { body.textContent = 'The request failed.'; });
|
|
139
|
+
}
|
|
140
|
+
function post(url, payload) {
|
|
141
|
+
return fetch(url, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
credentials: 'same-origin',
|
|
144
|
+
headers: { 'content-type': 'application/json' },
|
|
145
|
+
body: JSON.stringify(payload)
|
|
146
|
+
}).then(text);
|
|
147
|
+
}
|
|
148
|
+
card.addEventListener('click', function(e) {
|
|
149
|
+
var t = e.target;
|
|
150
|
+
if (!t || !t.getAttribute) return;
|
|
151
|
+
var act = t.getAttribute('data-action');
|
|
152
|
+
if (!act) return;
|
|
153
|
+
if (act === 'add') {
|
|
154
|
+
var input = document.getElementById('github-installation-add');
|
|
155
|
+
var repos = input.value.split(/[\\s,]+/).filter(function(s) { return s; });
|
|
156
|
+
if (!repos.length) return;
|
|
157
|
+
t.disabled = true;
|
|
158
|
+
post(base + '/repos/add', { repos: repos })
|
|
159
|
+
.then(function(h) { out.innerHTML = h; return load(); })
|
|
160
|
+
.catch(fail).then(function() { t.disabled = false; });
|
|
161
|
+
} else if (act === 'remove') {
|
|
162
|
+
var repo = t.getAttribute('data-repo');
|
|
163
|
+
if (!window.confirm('Remove ' + repo + ' from the installation?')) return;
|
|
164
|
+
t.disabled = true;
|
|
165
|
+
post(base + '/repos/remove', { repos: [repo] })
|
|
166
|
+
.then(function(h) { out.innerHTML = h; return load(); })
|
|
167
|
+
.catch(fail).then(function() { t.disabled = false; });
|
|
168
|
+
} else if (act === 'lost-access-preview') {
|
|
169
|
+
t.disabled = true;
|
|
170
|
+
out.textContent = 'Loading...';
|
|
171
|
+
fetch('/admin/agents/${escapeHtml(agentId)}/github-lost-access/preview', { credentials: 'same-origin' })
|
|
172
|
+
.then(text).then(function(h) { out.innerHTML = h; })
|
|
173
|
+
.catch(fail).then(function() { t.disabled = false; });
|
|
174
|
+
} else if (act === 'lost-access-apply') {
|
|
175
|
+
var box = document.getElementById('github-lost-access-confirm');
|
|
176
|
+
var cap = document.getElementById('github-lost-access-confirm-cap');
|
|
177
|
+
var holder = document.getElementById('github-lost-access-plan');
|
|
178
|
+
if (!box || !box.checked || (cap && !cap.checked) || !holder) return;
|
|
179
|
+
t.disabled = true;
|
|
180
|
+
post('/admin/agents/${escapeHtml(agentId)}/github-lost-access/remove', {
|
|
181
|
+
repos: JSON.parse(holder.getAttribute('data-repos') || '[]'),
|
|
182
|
+
confirmRemovals: !!(cap && cap.checked)
|
|
183
|
+
}).then(function(h) { out.innerHTML = h; return load(); })
|
|
184
|
+
.catch(fail);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
out.addEventListener('change', function() {
|
|
188
|
+
var box = document.getElementById('github-lost-access-confirm');
|
|
189
|
+
var cap = document.getElementById('github-lost-access-confirm-cap');
|
|
190
|
+
var apply = document.getElementById('github-lost-access-apply-btn');
|
|
191
|
+
if (box && apply) apply.disabled = !(box.checked && (!cap || cap.checked));
|
|
192
|
+
});
|
|
193
|
+
load();
|
|
194
|
+
})();
|
|
195
|
+
</script>
|
|
196
|
+
</div>`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The card body: repos per org with the user-can-push hint (only when known),
|
|
201
|
+
* add and remove, and the lost-access button (or why it is unavailable).
|
|
202
|
+
*/
|
|
203
|
+
export function renderInstallationReposBody(
|
|
204
|
+
view: InstallationReposView,
|
|
205
|
+
githubUsername: string | null | undefined,
|
|
206
|
+
): string {
|
|
207
|
+
const orgs =
|
|
208
|
+
view.orgs.length === 0
|
|
209
|
+
? `<p class="empty-state">The agent App is not installed on any organization the installer can reach.</p>`
|
|
210
|
+
: view.orgs
|
|
211
|
+
.map((o) => {
|
|
212
|
+
const rows =
|
|
213
|
+
o.repos.length === 0
|
|
214
|
+
? `<tr><td colspan="3" class="empty-state">No repos.</td></tr>`
|
|
215
|
+
: o.repos
|
|
216
|
+
.map((r) => {
|
|
217
|
+
const hint =
|
|
218
|
+
r.userCanPush === undefined
|
|
219
|
+
? ""
|
|
220
|
+
: r.userCanPush
|
|
221
|
+
? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
|
|
222
|
+
: '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
|
|
223
|
+
return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}</td><td><button type="button" class="btn btn-danger" style="font-size:11px;padding:3px 8px" data-action="remove" data-repo="${escapeHtml(r.fullName)}">Remove</button></td></tr>`;
|
|
224
|
+
})
|
|
225
|
+
.join("");
|
|
226
|
+
return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div><table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th><th></th></tr></thead><tbody>${rows}</tbody></table></div>`;
|
|
227
|
+
})
|
|
228
|
+
.join("");
|
|
229
|
+
const add = `<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:12px">
|
|
230
|
+
<input id="github-installation-add" type="text" class="form-input mono" placeholder="Repos to add (owner/repo, comma separated)" style="min-width:320px" />
|
|
231
|
+
<button type="button" class="btn btn-primary" data-action="add">Add</button>
|
|
232
|
+
</div>`;
|
|
233
|
+
const lost = githubUsername
|
|
234
|
+
? `<button type="button" class="btn btn-danger" id="github-lost-access-btn" data-action="lost-access-preview">Remove repos the user can no longer push to</button>`
|
|
235
|
+
: `<div class="alert alert-warning" data-reason="no-username">${escapeHtml(NO_USERNAME_REASON)}</div>`;
|
|
236
|
+
return `${add}${orgs}<div style="margin-top:12px">${lost}</div>`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Why the card body could not be shown, distinct per cause. */
|
|
240
|
+
export function renderInstallationReposError(
|
|
241
|
+
status: number,
|
|
242
|
+
message: string,
|
|
243
|
+
): string {
|
|
244
|
+
if (status === 503) {
|
|
245
|
+
return `<div class="alert alert-warning" data-reason="installer-unconfigured">${escapeHtml(INSTALLER_UNCONFIGURED_REASON)}</div>`;
|
|
246
|
+
}
|
|
247
|
+
return `<div class="alert alert-error" data-reason="error">${escapeHtml(message)}</div>`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Fragment for add/remove on the installation. */
|
|
251
|
+
export function renderInstallationChangeResult(
|
|
252
|
+
kind: "add" | "remove",
|
|
253
|
+
res: { auditId?: string; repos?: string[] },
|
|
254
|
+
): string {
|
|
255
|
+
const repos = (res.repos ?? [])
|
|
256
|
+
.map((r) => `<span class="mono">${escapeHtml(r)}</span>`)
|
|
257
|
+
.join(", ");
|
|
258
|
+
const audit = res.auditId
|
|
259
|
+
? ` Audit id: <span class="mono">${escapeHtml(res.auditId)}</span>.`
|
|
260
|
+
: "";
|
|
261
|
+
return `<div class="alert alert-success">${kind === "add" ? "Added to" : "Removed from"} the installation: ${repos}.${audit}</div>`;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Confirm step for lost-access removal: lists exactly what will be removed,
|
|
266
|
+
* the skipped orgs, the open work that would be blocked (per repo, linked),
|
|
267
|
+
* and the extra confirmation over the cap.
|
|
268
|
+
*/
|
|
269
|
+
export function renderLostAccessPreview(view: LostAccessPreviewView): string {
|
|
270
|
+
if (view.status === "skipped") {
|
|
271
|
+
return `<div class="alert alert-warning" data-reason="skipped">Nothing to remove: ${escapeHtml(view.reason ?? "the preview was skipped")}.</div>`;
|
|
272
|
+
}
|
|
273
|
+
const repos = view.repos ?? [];
|
|
274
|
+
const parts = [
|
|
275
|
+
skippedOrgsHtml(view.skippedOrgs),
|
|
276
|
+
warningsHtml(view.warnings),
|
|
277
|
+
];
|
|
278
|
+
if (repos.length === 0) {
|
|
279
|
+
parts.push(
|
|
280
|
+
`<p class="empty-state">No repos to remove: the bound user can still push to everything that could be checked.</p>`,
|
|
281
|
+
);
|
|
282
|
+
return parts.join("");
|
|
283
|
+
}
|
|
284
|
+
const inInstall = new Set((view.installationRemoves ?? []).map(lc));
|
|
285
|
+
const inConfig = new Set((view.configRemoves ?? []).map(lc));
|
|
286
|
+
const rows = repos
|
|
287
|
+
.map(
|
|
288
|
+
(r) =>
|
|
289
|
+
`<tr><td class="mono">${escapeHtml(r)}</td><td>${inInstall.has(lc(r)) ? "installation" : ""}</td><td>${inConfig.has(lc(r)) ? "agent repos" : ""}</td></tr>`,
|
|
290
|
+
)
|
|
291
|
+
.join("");
|
|
292
|
+
parts.push(
|
|
293
|
+
`<div style="font-weight:600;margin:8px 0 6px">These ${repos.length} repos will be removed</div><table class="detail-table"><thead><tr><th>Repo</th><th>Removed from</th><th></th></tr></thead><tbody>${rows}</tbody></table>`,
|
|
294
|
+
);
|
|
295
|
+
parts.push(
|
|
296
|
+
renderOpenWorkByRepo(
|
|
297
|
+
view.openWork ?? [],
|
|
298
|
+
"Open tasks and PRs that will be blocked",
|
|
299
|
+
"No open tasks or PRs would be blocked.",
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
const overCap = repos.length > MAX_UNCONFIRMED_REMOVALS;
|
|
303
|
+
const capConfirm = overCap
|
|
304
|
+
? `<label style="display:block;margin-bottom:8px"><input type="checkbox" id="github-lost-access-confirm-cap" /> This removes ${repos.length} repos (more than ${MAX_UNCONFIRMED_REMOVALS}). I confirm the removals.</label>`
|
|
305
|
+
: "";
|
|
306
|
+
parts.push(
|
|
307
|
+
`<div id="github-lost-access-plan" style="margin-top:12px" data-repos="${escapeHtml(JSON.stringify(repos))}" data-over-cap="${overCap}">
|
|
308
|
+
<label style="display:block;margin-bottom:8px"><input type="checkbox" id="github-lost-access-confirm" /> I have reviewed this list and want to remove these repos.</label>
|
|
309
|
+
${capConfirm}
|
|
310
|
+
<button type="button" class="btn btn-danger" id="github-lost-access-apply-btn" data-action="lost-access-apply" disabled>Remove</button>
|
|
311
|
+
</div>`,
|
|
312
|
+
);
|
|
313
|
+
return parts.join("");
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* The work that was actually blocked: the open work seen at confirmation on
|
|
318
|
+
* the repos that were removed, minus repos whose blocking the API warned about.
|
|
319
|
+
*/
|
|
320
|
+
export function actuallyBlockedWork(
|
|
321
|
+
seen: readonly OpenWorkView[],
|
|
322
|
+
removedRepos: readonly string[],
|
|
323
|
+
warnings: readonly string[],
|
|
324
|
+
): OpenWorkView[] {
|
|
325
|
+
const removed = new Set(removedRepos.map(lc));
|
|
326
|
+
return seen.filter(
|
|
327
|
+
(w) =>
|
|
328
|
+
removed.has(lc(w.repo)) &&
|
|
329
|
+
!warnings.some((x) =>
|
|
330
|
+
x.includes(`open work for ${w.repo} was not blocked`),
|
|
331
|
+
),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Result of the lost-access removal: audit, outcome per repo, blocked work. */
|
|
336
|
+
export function renderLostAccessResult(
|
|
337
|
+
res: LostAccessRemoveView,
|
|
338
|
+
blocked: readonly OpenWorkView[],
|
|
339
|
+
): string {
|
|
340
|
+
if (res.status === "skipped") {
|
|
341
|
+
return `<div class="alert alert-warning" data-reason="skipped">Nothing was removed: ${escapeHtml(res.reason ?? "skipped")}.</div>`;
|
|
342
|
+
}
|
|
343
|
+
const notRemoved = (res.notRemoved ?? []).length
|
|
344
|
+
? `<div class="alert alert-warning">Left alone:<ul style="margin:6px 0 0 18px">${(res.notRemoved ?? []).map((n) => `<li><span class="mono">${escapeHtml(n.repo)}</span>: ${escapeHtml(n.reason)}</li>`).join("")}</ul></div>`
|
|
345
|
+
: "";
|
|
346
|
+
const tail = `${notRemoved}${skippedOrgsHtml(res.skippedOrgs)}${warningsHtml(res.warnings)}`;
|
|
347
|
+
if (res.status === "noop") {
|
|
348
|
+
return `<div class="alert alert-warning">Nothing to remove: none of the named repos still lacks push access.</div>${tail}`;
|
|
349
|
+
}
|
|
350
|
+
const repos = (res.repos ?? [])
|
|
351
|
+
.map((r) => `<span class="mono">${escapeHtml(r)}</span>`)
|
|
352
|
+
.join(", ");
|
|
353
|
+
const audit = res.auditId
|
|
354
|
+
? ` Audit id: <span class="mono">${escapeHtml(res.auditId)}</span>.`
|
|
355
|
+
: "";
|
|
356
|
+
return `<div class="alert alert-success">Removed ${(res.repos ?? []).length} repos: ${repos}.${audit}</div>${renderOpenWorkByRepo(
|
|
357
|
+
blocked,
|
|
358
|
+
"Open tasks and PRs that were blocked",
|
|
359
|
+
"No open tasks or PRs were blocked.",
|
|
360
|
+
)}${tail}`;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Confirm step for removing one repo from the agent's own repos: the open work
|
|
365
|
+
* it would block, per repo, linked. Confirming posts to the removal route.
|
|
366
|
+
*/
|
|
367
|
+
export function renderRepoRemovalConfirm(
|
|
368
|
+
agentId: string,
|
|
369
|
+
preview: RepoRemovalPreviewView,
|
|
370
|
+
): string {
|
|
371
|
+
const url = `/admin/agents/${escapeHtml(agentId)}/repos/remove-confirmed`;
|
|
372
|
+
return `<div class="alert alert-warning" id="repo-removal-confirm-panel" data-repo="${escapeHtml(preview.repo)}">Remove <span class="mono">${escapeHtml(preview.repo)}</span> from this agent's repos?</div>${renderOpenWorkByRepo(
|
|
373
|
+
preview.openWork,
|
|
374
|
+
"Open tasks and PRs that will be blocked",
|
|
375
|
+
"No open tasks or PRs would be blocked.",
|
|
376
|
+
)}${warningsHtml(preview.warnings)}<button type="button" class="btn btn-danger" id="repo-removal-confirm-btn" data-url="${url}" data-repo="${escapeHtml(preview.repo)}">Confirm removal</button>`;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Result of removing a repo from the agent's repos, with what was blocked. */
|
|
380
|
+
export function renderRepoRemovalResult(
|
|
381
|
+
repo: string,
|
|
382
|
+
blocked: readonly OpenWorkView[],
|
|
383
|
+
warnings: readonly string[],
|
|
384
|
+
): string {
|
|
385
|
+
return `<div class="alert alert-success">Removed <span class="mono">${escapeHtml(repo)}</span> from the agent's repos. Reload the page to refresh the list.</div>${renderOpenWorkByRepo(
|
|
386
|
+
blocked,
|
|
387
|
+
"Open tasks and PRs that were blocked",
|
|
388
|
+
"No open tasks or PRs were blocked.",
|
|
389
|
+
)}${warningsHtml(warnings)}`;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Agent repos the installation does not cover (warning only; case-insensitive). */
|
|
393
|
+
export function uncoveredRepos(
|
|
394
|
+
agentRepos: readonly string[],
|
|
395
|
+
installationRepos: readonly string[],
|
|
396
|
+
): string[] {
|
|
397
|
+
const covered = new Set(installationRepos.map(lc));
|
|
398
|
+
return agentRepos.filter((r) => !covered.has(lc(r)));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** The badge shown on an uncovered repo row of the agent's repos list. */
|
|
402
|
+
export function renderUncoveredBadge(): string {
|
|
403
|
+
return ` <span class="badge badge-warning" data-uncovered="1" title="The agent App's installation does not cover this repo. Nothing is changed automatically.">not on installation</span>`;
|
|
404
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-installation-repos-pages.unit.test.ts
|
|
3
|
+
* Unit tests for the pure IRM-1.4 helpers and escaping.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from "bun:test";
|
|
7
|
+
import {
|
|
8
|
+
actuallyBlockedWork,
|
|
9
|
+
renderOpenWorkByRepo,
|
|
10
|
+
uncoveredRepos,
|
|
11
|
+
} from "./admin-ui-installation-repos-pages.ts";
|
|
12
|
+
|
|
13
|
+
describe("uncoveredRepos", () => {
|
|
14
|
+
it("returns agent repos missing from the installation, case-insensitively", () => {
|
|
15
|
+
expect(
|
|
16
|
+
uncoveredRepos(["Acme/Api", "acme/web", "x/y"], ["acme/api", "acme/web"]),
|
|
17
|
+
).toEqual(["x/y"]);
|
|
18
|
+
});
|
|
19
|
+
it("returns nothing when all are covered", () => {
|
|
20
|
+
expect(uncoveredRepos(["a/b"], ["a/b"])).toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("actuallyBlockedWork", () => {
|
|
25
|
+
const seen = [
|
|
26
|
+
{ id: "a/b#1", repo: "a/b" },
|
|
27
|
+
{ id: "t1", repo: "c/d" },
|
|
28
|
+
{ id: "t2", repo: "e/f" },
|
|
29
|
+
];
|
|
30
|
+
it("keeps only work on removed repos whose blocking did not warn", () => {
|
|
31
|
+
expect(
|
|
32
|
+
actuallyBlockedWork(
|
|
33
|
+
seen,
|
|
34
|
+
["a/b", "c/d"],
|
|
35
|
+
["open work for c/d was not blocked: boom"],
|
|
36
|
+
).map((w) => w.id),
|
|
37
|
+
).toEqual(["a/b#1"]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("renderOpenWorkByRepo", () => {
|
|
42
|
+
it("groups per repo, links PR ids and escapes titles and ids", () => {
|
|
43
|
+
const html = renderOpenWorkByRepo(
|
|
44
|
+
[
|
|
45
|
+
{ id: "a/b#1", repo: "a/b", title: "<script>" },
|
|
46
|
+
{ id: "<id>", repo: "a/b" },
|
|
47
|
+
],
|
|
48
|
+
"H",
|
|
49
|
+
"none",
|
|
50
|
+
);
|
|
51
|
+
expect(html.match(/font-weight:600">a\/b</g)?.length).toBe(1);
|
|
52
|
+
expect(html).toContain('href="https://github.com/a/b/pull/1"');
|
|
53
|
+
expect(html).toContain("<script>");
|
|
54
|
+
expect(html).toContain("<id>");
|
|
55
|
+
expect(html).not.toContain("<script>");
|
|
56
|
+
});
|
|
57
|
+
});
|