@app-vitals/agent-admin 1.35.1 → 1.36.1
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 +55 -295
- package/package.json +2 -2
- package/src/admin-boot.ts +3 -3
- package/src/admin-extension.ts +1 -1
- package/src/admin-ui-github-identity.smoke.test.ts +24 -2
- package/src/admin-ui-installation-repos-pages.ts +198 -231
- package/src/admin-ui-installation-repos-pages.unit.test.ts +199 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +166 -172
- package/src/admin-ui-pages.ts +2 -2
- package/src/admin-ui.ts +103 -89
- package/src/agents-api.smoke.test.ts +193 -290
- package/src/agents-api.ts +83 -210
- package/src/fixtures/enterprise-org-installations.json +26 -0
- package/src/github-enterprise-api.ts +1 -3
- package/src/github-enterprise-client.ts +9 -4
- package/src/github-installation-wiring.ts +10 -12
- package/src/github-installation-wiring.unit.test.ts +13 -9
- package/src/github-installation.fixtures.ts +1 -1
- package/src/github-sync.ts +414 -0
- package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +214 -109
- package/src/installation-ports-fixture.integration.test.ts +78 -0
- package/src/installation-ports.ts +84 -13
- package/src/installation-ports.unit.test.ts +66 -14
- package/src/installation-repos-service.ts +25 -102
- package/src/installation-repos-service.unit.test.ts +5 -90
- package/src/reconcile-open-work.ts +1 -1
- package/src/repo-access-rules.ts +1 -1
- package/src/lost-access-removal.ts +0 -333
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-installation-repos-pages.ts
|
|
3
|
-
* Pure renderers for the agent detail page's
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
3
|
+
* Pure renderers for the agent detail page's GitHub Sync card (IRM-3.2): one
|
|
4
|
+
* Sync button, the read-only list of repos on the agent App's installation per
|
|
5
|
+
* org (with the user-can-push hint), and the single confirm step that lists
|
|
6
|
+
* installation adds, installation removes, agent-repo removes and the open work
|
|
7
|
+
* that would be blocked. It also renders the open-work lists shown for the
|
|
8
|
+
* agent-repo removal (IRM-1.7) and the coverage warning on the agent's repos
|
|
9
|
+
* list. Platform-admin only; the caller decides visibility, and only renders
|
|
10
|
+
* the card when the installer and lookup Apps are both configured. Every
|
|
11
|
+
* dynamic value is escaped. Inputs carry repo names and ids only.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
14
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
MAX_UNCONFIRMED_REMOVALS,
|
|
17
|
+
MISSING_APP_ID_REASON,
|
|
18
|
+
} from "./installation-ports.ts";
|
|
15
19
|
|
|
16
20
|
export interface OpenWorkView {
|
|
17
21
|
id: string;
|
|
@@ -28,31 +32,6 @@ export interface InstallationReposView {
|
|
|
28
32
|
}[];
|
|
29
33
|
}
|
|
30
34
|
|
|
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
35
|
/** JSON body of GET /agents/:id/repos/:owner/:name/removal-preview. */
|
|
57
36
|
export interface RepoRemovalPreviewView {
|
|
58
37
|
repo: string;
|
|
@@ -60,8 +39,6 @@ export interface RepoRemovalPreviewView {
|
|
|
60
39
|
warnings: string[];
|
|
61
40
|
}
|
|
62
41
|
|
|
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
42
|
export const INSTALLER_UNCONFIGURED_REASON =
|
|
66
43
|
"The installer GitHub App is not configured, so the agent App's installation repos cannot be listed or changed.";
|
|
67
44
|
|
|
@@ -107,133 +84,145 @@ function warningsHtml(warnings: readonly string[] | undefined): string {
|
|
|
107
84
|
: `<div class="alert alert-warning" data-warnings="1">${(warnings ?? []).map((w) => `<div>${escapeHtml(w)}</div>`).join("")}</div>`;
|
|
108
85
|
}
|
|
109
86
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
export const NO_USERNAME_REASON =
|
|
88
|
+
"No GitHub username is bound to this agent, so there is nothing to sync against. Bind one under Owner and identities.";
|
|
89
|
+
|
|
90
|
+
export const APP_ID_MISMATCH_MESSAGE =
|
|
91
|
+
"No installation matches the GH_APP_ID of this agent, although the Installations card matches an installation by App slug. GH_APP_ID is probably set to the wrong numeric App id; correct it in the agent env.";
|
|
92
|
+
|
|
93
|
+
/** JSON body of GET /agents/:id/github-sync/preview. */
|
|
94
|
+
export interface GithubSyncPreviewView {
|
|
95
|
+
status: "previewed" | "skipped";
|
|
96
|
+
reason?: string;
|
|
97
|
+
appAdds?: string[];
|
|
98
|
+
appRemoves?: string[];
|
|
99
|
+
agentRemoves?: string[];
|
|
100
|
+
skippedOrgs?: { org: string; reason: string }[];
|
|
101
|
+
openWork?: OpenWorkView[];
|
|
102
|
+
warnings?: string[];
|
|
116
103
|
}
|
|
117
104
|
|
|
118
|
-
/**
|
|
119
|
-
export
|
|
120
|
-
|
|
105
|
+
/** JSON body of POST /agents/:id/github-sync/apply. */
|
|
106
|
+
export interface GithubSyncApplyView {
|
|
107
|
+
status: "applied" | "noop" | "skipped";
|
|
108
|
+
reason?: string;
|
|
109
|
+
appAdds?: string[];
|
|
110
|
+
appRemoves?: string[];
|
|
111
|
+
agentRemoves?: string[];
|
|
112
|
+
notApplied?: { repo: string; reason: string }[];
|
|
113
|
+
skippedOrgs?: { org: string; reason: string }[];
|
|
114
|
+
warnings?: string[];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface GithubSyncCardState {
|
|
118
|
+
/** The agent has a GH_APP_ID in its env. */
|
|
119
|
+
hasAppId: boolean;
|
|
120
|
+
githubUsername?: string | null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The Sync card shell; it loads its repos body from the UI route on page load.
|
|
125
|
+
* Without a GH_APP_ID or a bound username the button is replaced by the
|
|
126
|
+
* reason (missing App id first).
|
|
127
|
+
*/
|
|
128
|
+
export function renderGithubSyncCard(
|
|
129
|
+
agentId: string,
|
|
130
|
+
state: GithubSyncCardState,
|
|
131
|
+
): string {
|
|
132
|
+
const id = escapeHtml(agentId);
|
|
133
|
+
const base = `/admin/agents/${id}/github-installation`;
|
|
134
|
+
let action: string;
|
|
135
|
+
if (!state.hasAppId) {
|
|
136
|
+
action = `<div class="alert alert-warning" data-reason="missing-app-id">${escapeHtml(MISSING_APP_ID_REASON)}</div>`;
|
|
137
|
+
} else if (!state.githubUsername?.trim()) {
|
|
138
|
+
action = `<div class="alert alert-warning" data-reason="no-username">${escapeHtml(NO_USERNAME_REASON)}</div>`;
|
|
139
|
+
} else {
|
|
140
|
+
action = `<button type="button" class="btn btn-primary" id="github-sync-btn" data-url="/admin/agents/${id}/github-sync/confirm">Sync</button><div id="github-sync-confirm" style="margin-top:12px"></div>`;
|
|
141
|
+
}
|
|
142
|
+
const loader = state.hasAppId
|
|
143
|
+
? `<div id="github-installation-body">Loading...</div>`
|
|
144
|
+
: "";
|
|
121
145
|
return `<div class="card" id="github-installation-card" data-base-url="${base}">
|
|
122
|
-
<div class="card-title">
|
|
123
|
-
<p style="color:#6b7280;font-size:12px;margin:0 0 12px">
|
|
124
|
-
|
|
125
|
-
|
|
146
|
+
<div class="card-title">GitHub sync</div>
|
|
147
|
+
<p style="color:#6b7280;font-size:12px;margin:0 0 12px">Brings this agent's App installation and its repos in line with what the bound GitHub user can push to.</p>
|
|
148
|
+
${action}
|
|
149
|
+
${loader}
|
|
126
150
|
<script>
|
|
127
151
|
(function() {
|
|
128
152
|
var card = document.getElementById('github-installation-card');
|
|
129
153
|
var body = document.getElementById('github-installation-body');
|
|
130
|
-
var out = document.getElementById('github-
|
|
131
|
-
if (!card
|
|
132
|
-
|
|
133
|
-
function text(r) { return r.text(); }
|
|
154
|
+
var out = document.getElementById('github-sync-confirm');
|
|
155
|
+
if (!card) return;
|
|
156
|
+
function show(r) { return r.text().then(function(t) { out.innerHTML = t; }); }
|
|
134
157
|
function fail() { out.textContent = 'The request failed.'; }
|
|
135
|
-
|
|
136
|
-
|
|
158
|
+
if (body) {
|
|
159
|
+
fetch(card.getAttribute('data-base-url'), { credentials: 'same-origin' })
|
|
160
|
+
.then(function(r) { return r.text(); })
|
|
137
161
|
.then(function(t) { body.innerHTML = t; })
|
|
138
162
|
.catch(function() { body.textContent = 'The request failed.'; });
|
|
139
163
|
}
|
|
140
|
-
|
|
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
|
-
}
|
|
164
|
+
if (!out) return;
|
|
148
165
|
card.addEventListener('click', function(e) {
|
|
149
166
|
var t = e.target;
|
|
150
|
-
if (!t || !t.
|
|
151
|
-
|
|
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;
|
|
167
|
+
if (!t || !t.id) return;
|
|
168
|
+
if (t.id === 'github-sync-btn') {
|
|
170
169
|
out.textContent = 'Loading...';
|
|
171
|
-
fetch('
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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;
|
|
170
|
+
fetch(t.getAttribute('data-url'), { credentials: 'same-origin' }).then(show).catch(fail);
|
|
171
|
+
} else if (t.id === 'github-sync-confirm-btn') {
|
|
172
|
+
var payload = JSON.parse(t.getAttribute('data-body') || '{}');
|
|
173
|
+
var cb = document.getElementById('github-sync-confirm-removals');
|
|
174
|
+
if (cb) payload.confirmRemovals = cb.checked;
|
|
179
175
|
t.disabled = true;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.
|
|
176
|
+
fetch(t.getAttribute('data-url'), {
|
|
177
|
+
method: 'POST',
|
|
178
|
+
credentials: 'same-origin',
|
|
179
|
+
headers: { 'content-type': 'application/json' },
|
|
180
|
+
body: JSON.stringify(payload)
|
|
181
|
+
}).then(show).catch(fail);
|
|
185
182
|
}
|
|
186
183
|
});
|
|
187
|
-
|
|
188
|
-
var
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
card.addEventListener('change', function(e) {
|
|
185
|
+
var t = e.target;
|
|
186
|
+
if (t && t.id === 'github-sync-confirm-removals') {
|
|
187
|
+
var btn = document.getElementById('github-sync-confirm-btn');
|
|
188
|
+
if (btn) btn.disabled = !t.checked;
|
|
189
|
+
}
|
|
192
190
|
});
|
|
193
|
-
load();
|
|
194
191
|
})();
|
|
195
192
|
</script>
|
|
196
193
|
</div>`;
|
|
197
194
|
}
|
|
198
195
|
|
|
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
|
-
*/
|
|
196
|
+
/** The card body: read-only repos per org with the user-can-push hint (only when known). */
|
|
203
197
|
export function renderInstallationReposBody(
|
|
204
198
|
view: InstallationReposView,
|
|
205
|
-
|
|
199
|
+
opts: { appIdMismatch?: boolean } = {},
|
|
206
200
|
): string {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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>`;
|
|
201
|
+
if (view.orgs.length === 0) {
|
|
202
|
+
if (opts.appIdMismatch) {
|
|
203
|
+
return `<div class="alert alert-warning" data-reason="app-id-mismatch">${escapeHtml(APP_ID_MISMATCH_MESSAGE)}</div>`;
|
|
204
|
+
}
|
|
205
|
+
return `<p class="empty-state">The agent App is not installed on any organization the installer can reach.</p>`;
|
|
206
|
+
}
|
|
207
|
+
return view.orgs
|
|
208
|
+
.map((o) => {
|
|
209
|
+
const rows =
|
|
210
|
+
o.repos.length === 0
|
|
211
|
+
? `<tr><td colspan="2" class="empty-state">No repos.</td></tr>`
|
|
212
|
+
: o.repos
|
|
213
|
+
.map((r) => {
|
|
214
|
+
const hint =
|
|
215
|
+
r.userCanPush === undefined
|
|
216
|
+
? ""
|
|
217
|
+
: r.userCanPush
|
|
218
|
+
? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
|
|
219
|
+
: '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
|
|
220
|
+
return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}</td></tr>`;
|
|
221
|
+
})
|
|
222
|
+
.join("");
|
|
223
|
+
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></tr></thead><tbody>${rows}</tbody></table></div>`;
|
|
224
|
+
})
|
|
225
|
+
.join("");
|
|
237
226
|
}
|
|
238
227
|
|
|
239
228
|
/** Why the card body could not be shown, distinct per cause. */
|
|
@@ -247,72 +236,6 @@ export function renderInstallationReposError(
|
|
|
247
236
|
return `<div class="alert alert-error" data-reason="error">${escapeHtml(message)}</div>`;
|
|
248
237
|
}
|
|
249
238
|
|
|
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
239
|
/**
|
|
317
240
|
* The work that was actually blocked: the open work seen at confirmation on
|
|
318
241
|
* the repos that were removed, minus repos whose blocking the API warned about.
|
|
@@ -332,34 +255,6 @@ export function actuallyBlockedWork(
|
|
|
332
255
|
);
|
|
333
256
|
}
|
|
334
257
|
|
|
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
258
|
/**
|
|
364
259
|
* Confirm step for removing one repo from the agent's own repos: the open work
|
|
365
260
|
* it would block, per repo, linked. Confirming posts to the removal route.
|
|
@@ -402,3 +297,75 @@ export function uncoveredRepos(
|
|
|
402
297
|
export function renderUncoveredBadge(): string {
|
|
403
298
|
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
299
|
}
|
|
300
|
+
|
|
301
|
+
const repoList = (kind: string, title: string, repos: readonly string[]) =>
|
|
302
|
+
repos.length === 0
|
|
303
|
+
? ""
|
|
304
|
+
: `<div data-list="${kind}" style="margin-top:8px"><div style="font-weight:600">${escapeHtml(title)} (${repos.length})</div><ul style="margin:4px 0 0 18px">${repos.map((r) => `<li class="mono">${escapeHtml(r)}</li>`).join("")}</ul></div>`;
|
|
305
|
+
|
|
306
|
+
const skippedOrgsHtml = (
|
|
307
|
+
skipped: readonly { org: string; reason: string }[],
|
|
308
|
+
) =>
|
|
309
|
+
skipped.length === 0
|
|
310
|
+
? ""
|
|
311
|
+
: `<div class="alert alert-warning" data-skipped-orgs="1"><div style="font-weight:600">Skipped orgs (nothing added or removed there)</div>${skipped.map((s) => `<div><span class="mono">${escapeHtml(s.org)}</span>: ${escapeHtml(s.reason)}</div>`).join("")}</div>`;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* The single confirm step of Sync: the installation adds, installation
|
|
315
|
+
* removes, agent-repo removes and the open work the removals would block. One
|
|
316
|
+
* confirmation applies them all; more than the removal cap needs the extra
|
|
317
|
+
* checkbox (confirmRemovals).
|
|
318
|
+
*/
|
|
319
|
+
export function renderSyncConfirm(
|
|
320
|
+
agentId: string,
|
|
321
|
+
preview: GithubSyncPreviewView,
|
|
322
|
+
): string {
|
|
323
|
+
if (preview.status === "skipped") {
|
|
324
|
+
return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(preview.reason ?? "unknown reason")}</div>`;
|
|
325
|
+
}
|
|
326
|
+
const appAdds = preview.appAdds ?? [];
|
|
327
|
+
const appRemoves = preview.appRemoves ?? [];
|
|
328
|
+
const agentRemoves = preview.agentRemoves ?? [];
|
|
329
|
+
const skipped = skippedOrgsHtml(preview.skippedOrgs ?? []);
|
|
330
|
+
const warnings = warningsHtml(preview.warnings);
|
|
331
|
+
if (appAdds.length + appRemoves.length + agentRemoves.length === 0) {
|
|
332
|
+
return `<div class="alert alert-success" data-sync="in-sync">Already in sync: nothing to add or remove.</div>${skipped}${warnings}`;
|
|
333
|
+
}
|
|
334
|
+
const removals = new Set([...appRemoves, ...agentRemoves].map(lc)).size;
|
|
335
|
+
const overCap = removals > MAX_UNCONFIRMED_REMOVALS;
|
|
336
|
+
const body = escapeHtml(
|
|
337
|
+
JSON.stringify({ appAdds, appRemoves, agentRemoves }),
|
|
338
|
+
);
|
|
339
|
+
const url = `/admin/agents/${escapeHtml(agentId)}/github-sync/apply-confirmed`;
|
|
340
|
+
const capBox = overCap
|
|
341
|
+
? `<label style="display:block;margin:12px 0"><input type="checkbox" id="github-sync-confirm-removals" /> I confirm removing ${removals} repos (more than ${MAX_UNCONFIRMED_REMOVALS}).</label>`
|
|
342
|
+
: "";
|
|
343
|
+
return `<div class="alert alert-warning" data-sync="confirm">Apply these changes?</div>${repoList("app-adds", "Add to the agent App installation", appAdds)}${repoList("app-removes", "Remove from the agent App installation", appRemoves)}${repoList("agent-removes", "Remove from the agent's repos", agentRemoves)}${renderOpenWorkByRepo(
|
|
344
|
+
preview.openWork ?? [],
|
|
345
|
+
"Open tasks and PRs that will be blocked",
|
|
346
|
+
"No open tasks or PRs would be blocked.",
|
|
347
|
+
)}${skipped}${warnings}${capBox}<button type="button" class="btn btn-danger" id="github-sync-confirm-btn" data-url="${url}" data-body="${body}"${overCap ? " disabled" : ""}>Confirm sync</button>`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Result of applying a sync, with the open work that was blocked. */
|
|
351
|
+
export function renderSyncResult(
|
|
352
|
+
result: GithubSyncApplyView,
|
|
353
|
+
blocked: readonly OpenWorkView[],
|
|
354
|
+
): string {
|
|
355
|
+
if (result.status === "skipped") {
|
|
356
|
+
return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(result.reason ?? "unknown reason")}</div>`;
|
|
357
|
+
}
|
|
358
|
+
if (result.status === "noop") {
|
|
359
|
+
return `<div class="alert alert-success" data-sync="noop">Nothing was changed.</div>${warningsHtml(result.warnings)}`;
|
|
360
|
+
}
|
|
361
|
+
const notApplied = result.notApplied ?? [];
|
|
362
|
+
return `<div class="alert alert-success" data-sync="applied">Sync applied. Reload the page to refresh the lists.</div>${repoList("app-adds", "Added to the agent App installation", result.appAdds ?? [])}${repoList("app-removes", "Removed from the agent App installation", result.appRemoves ?? [])}${repoList("agent-removes", "Removed from the agent's repos", result.agentRemoves ?? [])}${
|
|
363
|
+
notApplied.length === 0
|
|
364
|
+
? ""
|
|
365
|
+
: `<div class="alert alert-warning" data-not-applied="1"><div style="font-weight:600">Left alone</div>${notApplied.map((n) => `<div><span class="mono">${escapeHtml(n.repo)}</span>: ${escapeHtml(n.reason)}</div>`).join("")}</div>`
|
|
366
|
+
}${skippedOrgsHtml(result.skippedOrgs ?? [])}${renderOpenWorkByRepo(
|
|
367
|
+
blocked,
|
|
368
|
+
"Open tasks and PRs that were blocked",
|
|
369
|
+
"No open tasks or PRs were blocked.",
|
|
370
|
+
)}${warningsHtml(result.warnings)}`;
|
|
371
|
+
}
|