@nanocollective/roster 0.1.0-beta.17 → 0.1.0-beta.19
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/dist/cli.js +172 -7
- package/dist/worker/assets/assets/css/brain.css +20 -0
- package/dist/worker/assets/assets/css/home.css +7 -3
- package/dist/worker/assets/assets/js/homesort.js +7 -3
- package/dist/worker/assets/assets/js/views/home.js +4 -2
- package/dist/worker/assets/assets/js/views/org.js +2 -0
- package/dist/worker/assets/assets/js/views/people.js +103 -0
- package/dist/worker/index.js +145 -9
- package/docs/doctor-codes.md +2 -0
- package/docs/export.md +2 -1
- package/docs/org-yaml.md +13 -7
- package/package.json +1 -1
- package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +4 -4
- package/templates/portal/css/brain.css +20 -0
- package/templates/portal/css/home.css +7 -3
- package/templates/portal/js/homesort.js +7 -3
- package/templates/portal/js/views/home.js +4 -2
- package/templates/portal/js/views/org.js +2 -0
- package/templates/portal/js/views/people.js +103 -0
package/dist/cli.js
CHANGED
|
@@ -1117,14 +1117,14 @@ function searchDocs(query2, snippets = 3) {
|
|
|
1117
1117
|
return out.sort((a, b) => b.score - a.score);
|
|
1118
1118
|
}
|
|
1119
1119
|
function snippet(line, terms, width = 150) {
|
|
1120
|
-
const
|
|
1121
|
-
if (
|
|
1120
|
+
const clean2 = line.replace(/^#+\s*/, "").replace(/^[-*|]\s*/, "");
|
|
1121
|
+
if (clean2.length <= width) return clean2;
|
|
1122
1122
|
const at = Math.min(
|
|
1123
|
-
...terms.map((t) =>
|
|
1124
|
-
|
|
1123
|
+
...terms.map((t) => clean2.toLowerCase().indexOf(t)).filter((n) => n >= 0),
|
|
1124
|
+
clean2.length
|
|
1125
1125
|
);
|
|
1126
1126
|
const from = Math.max(0, at - 40);
|
|
1127
|
-
return (from ? "\u2026" : "") +
|
|
1127
|
+
return (from ? "\u2026" : "") + clean2.slice(from, from + width).trim() + "\u2026";
|
|
1128
1128
|
}
|
|
1129
1129
|
function titleOf(path) {
|
|
1130
1130
|
const first = readFileSync2(path, "utf8").split("\n").find((l) => l.startsWith("# "));
|
|
@@ -1252,6 +1252,87 @@ function humanLogins(org) {
|
|
|
1252
1252
|
function defaultMarker(name) {
|
|
1253
1253
|
return String(name).trim().split(/[\s-]+/)[0].toLowerCase().replace(/[^a-z0-9]/g, "") || "human";
|
|
1254
1254
|
}
|
|
1255
|
+
var clean = (v) => String(v ?? "").replace(/[,{}[\]#"'\n\r]/g, " ").replace(/\s+/g, " ").trim();
|
|
1256
|
+
var LOGIN_RE = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i;
|
|
1257
|
+
function tidyPeople(input) {
|
|
1258
|
+
const people = [];
|
|
1259
|
+
for (const p of input) {
|
|
1260
|
+
const github = clean(p.github).replace(/^@/, "");
|
|
1261
|
+
const name = clean(p.name) || github;
|
|
1262
|
+
if (!github && !name) continue;
|
|
1263
|
+
if (!LOGIN_RE.test(github))
|
|
1264
|
+
return { people, error: `"${github || name}" is not a GitHub login` };
|
|
1265
|
+
if (people.some((h) => h.github.toLowerCase() === github.toLowerCase())) {
|
|
1266
|
+
return { people, error: `@${github} is in the list twice` };
|
|
1267
|
+
}
|
|
1268
|
+
const marker = (clean(p.marker) || defaultMarker(name || github)).toLowerCase().replace(/[^a-z0-9-]/g, "");
|
|
1269
|
+
if (people.some((h) => h.marker === marker)) {
|
|
1270
|
+
return {
|
|
1271
|
+
people,
|
|
1272
|
+
error: `two people would share the label "${marker}"; give one a different label`
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
const handles = (Array.isArray(p.handles) ? p.handles : String(p.handles ?? "").split(",")).map(clean).filter(Boolean);
|
|
1276
|
+
people.push({
|
|
1277
|
+
github,
|
|
1278
|
+
name,
|
|
1279
|
+
marker,
|
|
1280
|
+
...clean(p.role) ? { role: clean(p.role) } : {},
|
|
1281
|
+
...handles.length ? { handles } : {},
|
|
1282
|
+
...p.view_only === true ? { viewOnly: true } : {}
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
if (!people.some((h) => !h.viewOnly)) {
|
|
1286
|
+
return {
|
|
1287
|
+
people,
|
|
1288
|
+
error: "someone has to be able to wake the staff: one person cannot be read-only"
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
return { people };
|
|
1292
|
+
}
|
|
1293
|
+
function writeHumans(text2, people) {
|
|
1294
|
+
const lines = text2.split("\n");
|
|
1295
|
+
const block = [
|
|
1296
|
+
"humans:",
|
|
1297
|
+
...people.map((h) => {
|
|
1298
|
+
const parts = [`name: ${h.name}`, `github: ${h.github}`, `marker: ${h.marker}`];
|
|
1299
|
+
if (h.role) parts.push(`role: ${h.role}`);
|
|
1300
|
+
if (h.handles?.length) parts.push(`handles: [${h.handles.join(", ")}]`);
|
|
1301
|
+
if (h.viewOnly) parts.push("view_only: true");
|
|
1302
|
+
return ` - { ${parts.join(", ")} }`;
|
|
1303
|
+
})
|
|
1304
|
+
];
|
|
1305
|
+
const out = [];
|
|
1306
|
+
let at = -1;
|
|
1307
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1308
|
+
if (/^humans?:/.test(lines[i])) {
|
|
1309
|
+
if (at < 0) at = out.length;
|
|
1310
|
+
while (i + 1 < lines.length) {
|
|
1311
|
+
const next = lines[i + 1];
|
|
1312
|
+
const more = /^\s+\S/.test(next) || /^\s*$/.test(next) && nextIsIndented(lines, i + 1);
|
|
1313
|
+
if (!more) break;
|
|
1314
|
+
i++;
|
|
1315
|
+
}
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
out.push(lines[i]);
|
|
1319
|
+
}
|
|
1320
|
+
if (at < 0) {
|
|
1321
|
+
const name = out.findIndex((l) => /^name:/.test(l));
|
|
1322
|
+
at = name >= 0 ? name + 1 : out.length;
|
|
1323
|
+
out.splice(at, 0, "");
|
|
1324
|
+
at++;
|
|
1325
|
+
}
|
|
1326
|
+
out.splice(at, 0, ...block);
|
|
1327
|
+
return out.join("\n");
|
|
1328
|
+
}
|
|
1329
|
+
function nextIsIndented(lines, from) {
|
|
1330
|
+
for (let j = from; j < lines.length; j++) {
|
|
1331
|
+
if (/^\s*$/.test(lines[j])) continue;
|
|
1332
|
+
return /^\s+\S/.test(lines[j]);
|
|
1333
|
+
}
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1255
1336
|
|
|
1256
1337
|
// src/lib/prompt.ts
|
|
1257
1338
|
import { execFileSync } from "child_process";
|
|
@@ -2685,7 +2766,9 @@ function buildPlan(ws, org, handle, opts, parseYaml3) {
|
|
|
2685
2766
|
}));
|
|
2686
2767
|
const labels = [
|
|
2687
2768
|
.../* @__PURE__ */ new Set([
|
|
2769
|
+
// Every person's label, not only the first's: staff send each ask to whoever's area it is.
|
|
2688
2770
|
orgSpec2.humanMarker,
|
|
2771
|
+
...humans.map((h) => h.marker).filter(Boolean),
|
|
2689
2772
|
handle,
|
|
2690
2773
|
...ASK_KINDS,
|
|
2691
2774
|
"keep-open",
|
|
@@ -5351,7 +5434,8 @@ async function checkStaff(ws, org, entry, composer, online) {
|
|
|
5351
5434
|
if (online && manifest.brain) {
|
|
5352
5435
|
const logins = humanLogins(org);
|
|
5353
5436
|
const keys = declared2(org).filter((c) => c.staff.includes(entry.handle) && !c.problem && c.auth === "key").map((c) => ({ name: c.name, secrets: c.secrets.map((x) => x.name) }));
|
|
5354
|
-
|
|
5437
|
+
const markers = staffHumans(org).map((h) => h.marker).filter(Boolean);
|
|
5438
|
+
out.push(...await checkStaffOnline(scope, manifest, callers, logins, keys, markers));
|
|
5355
5439
|
}
|
|
5356
5440
|
return out;
|
|
5357
5441
|
}
|
|
@@ -5478,7 +5562,7 @@ async function checkReviewGates(ws, org, composer) {
|
|
|
5478
5562
|
const readings = await Promise.all([...repos].map((r) => readGate(r, [...apps])));
|
|
5479
5563
|
return readings.map((r) => ({ scope: "workspace", id: "review-gate", ...judgeGate(r) }));
|
|
5480
5564
|
}
|
|
5481
|
-
async function checkStaffOnline(scope, manifest, callers, humans = [], connectors = []) {
|
|
5565
|
+
async function checkStaffOnline(scope, manifest, callers, humans = [], connectors = [], markers = []) {
|
|
5482
5566
|
const out = [];
|
|
5483
5567
|
const repo = manifest.brain;
|
|
5484
5568
|
const needed = /* @__PURE__ */ new Set();
|
|
@@ -5588,8 +5672,11 @@ async function checkStaffOnline(scope, manifest, callers, humans = [], connector
|
|
|
5588
5672
|
} : { scope, level: "ok", id: "labels", title: "every declared label exists" }
|
|
5589
5673
|
);
|
|
5590
5674
|
out.push(ownedLabels(scope, repo, have));
|
|
5675
|
+
out.push(personLabels(scope, repo, have, markers));
|
|
5591
5676
|
}
|
|
5592
5677
|
if (open2.ok) out.push(...unkindedAsks(scope, repo, open2.data, humans));
|
|
5678
|
+
const variable = await api(`repos/${repo}/actions/variables/ROSTER_HUMANS`);
|
|
5679
|
+
if (variable.ok) out.push(humansVariable(scope, repo, variable.data.value, humans));
|
|
5593
5680
|
const peers = (manifest.peers ?? []).filter((p) => p.label && p.brain);
|
|
5594
5681
|
const peerLabels = await Promise.all(
|
|
5595
5682
|
peers.map(
|
|
@@ -5915,6 +6002,32 @@ function ownedLabels(scope, repo, have) {
|
|
|
5915
6002
|
fix: gone.map((l) => `gh label create ${l} --repo ${repo} --force`).join("\n")
|
|
5916
6003
|
} : { scope, level: "ok", id: "owned-labels", title: "roster's own labels exist" };
|
|
5917
6004
|
}
|
|
6005
|
+
function humansVariable(scope, repo, value, humans) {
|
|
6006
|
+
let set = [];
|
|
6007
|
+
try {
|
|
6008
|
+
set = JSON.parse(value).map((x) => String(x).toLowerCase());
|
|
6009
|
+
} catch {
|
|
6010
|
+
}
|
|
6011
|
+
const want = humans.map((h) => h.toLowerCase());
|
|
6012
|
+
const same = set.length === want.length && want.every((h) => set.includes(h));
|
|
6013
|
+
return same ? { scope, level: "ok", id: "humans-variable", title: "ROSTER_HUMANS matches org.yaml" } : {
|
|
6014
|
+
scope,
|
|
6015
|
+
level: "fail",
|
|
6016
|
+
id: "humans-variable",
|
|
6017
|
+
title: `ROSTER_HUMANS on ${repo} is ${value}, but org.yaml says ${JSON.stringify(humans)}`,
|
|
6018
|
+
fix: `gh variable set ROSTER_HUMANS --repo ${repo} --body '${JSON.stringify(humans)}'`
|
|
6019
|
+
};
|
|
6020
|
+
}
|
|
6021
|
+
function personLabels(scope, repo, have, markers) {
|
|
6022
|
+
const gone = [...new Set(markers)].filter((l) => !have.has(l));
|
|
6023
|
+
return gone.length ? {
|
|
6024
|
+
scope,
|
|
6025
|
+
level: "warn",
|
|
6026
|
+
id: "person-labels",
|
|
6027
|
+
title: `a person's label is missing from ${repo}: ${gone.join(", ")}`,
|
|
6028
|
+
fix: gone.map((l) => `gh label create ${l} --repo ${repo} --force`).join("\n")
|
|
6029
|
+
} : { scope, level: "ok", id: "person-labels", title: "every person's label exists" };
|
|
6030
|
+
}
|
|
5918
6031
|
function unkindedAsks(scope, repo, issues, humans) {
|
|
5919
6032
|
const on = new Set(humans.map((h) => h.toLowerCase()));
|
|
5920
6033
|
const bad2 = issues.filter(
|
|
@@ -6040,6 +6153,7 @@ function buildExport(ws, org, parseYaml3, opts = {}) {
|
|
|
6040
6153
|
opsName: ws.opsName,
|
|
6041
6154
|
human: humans[0] ?? org.human ?? {},
|
|
6042
6155
|
humans,
|
|
6156
|
+
people: readHumans(org),
|
|
6043
6157
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6044
6158
|
staff
|
|
6045
6159
|
};
|
|
@@ -8866,6 +8980,57 @@ var ROUTES = {
|
|
|
8866
8980
|
await commitFile(portal, actor.gh, dir, rest.join("/"), payload.text, message2, base2)
|
|
8867
8981
|
);
|
|
8868
8982
|
},
|
|
8983
|
+
/* Who the staff answer to, from the Org screen. One commit to org.yaml, then each person's
|
|
8984
|
+
label on every tracker (an ask is sent by labelling it for someone, and GitHub refuses a
|
|
8985
|
+
label that does not exist) and the ROSTER_HUMANS variable the mention callers gate on, so
|
|
8986
|
+
somebody added here can wake a staff member straight away rather than after an upgrade. */
|
|
8987
|
+
"/api/people": async (c) => {
|
|
8988
|
+
const { req, portal, actor } = c;
|
|
8989
|
+
if (!actor.canWrite) return refuse();
|
|
8990
|
+
const { org, brains } = await ready(c, { force: true });
|
|
8991
|
+
if (isViewOnly(org, actor.id))
|
|
8992
|
+
return json({ error: "Read-only people cannot change this." }, 403);
|
|
8993
|
+
const payload = await body(req);
|
|
8994
|
+
const { people, error } = tidyPeople(Array.isArray(payload.people) ? payload.people : []);
|
|
8995
|
+
if (error) return json({ error }, 400);
|
|
8996
|
+
const text2 = portal.snapshots.get(`${portal.org}/${portal.opsName}`)?.files.get("org.yaml")?.text;
|
|
8997
|
+
if (text2 === void 0) return json({ error: "could not read org.yaml" }, 502);
|
|
8998
|
+
const next = writeHumans(text2, people);
|
|
8999
|
+
const wrong = validateOrgYaml(next, parseYaml2);
|
|
9000
|
+
if (wrong) return json({ error: wrong }, 400);
|
|
9001
|
+
const saved = await commitFile(
|
|
9002
|
+
portal,
|
|
9003
|
+
actor.gh,
|
|
9004
|
+
portal.opsName,
|
|
9005
|
+
"org.yaml",
|
|
9006
|
+
next,
|
|
9007
|
+
"portal: who the staff answer to",
|
|
9008
|
+
payload.base
|
|
9009
|
+
);
|
|
9010
|
+
const warnings = [];
|
|
9011
|
+
const logins = JSON.stringify(people.filter((h) => !h.viewOnly).map((h) => h.github));
|
|
9012
|
+
await Promise.all(
|
|
9013
|
+
brains.map(async (dir) => {
|
|
9014
|
+
const repo = `${portal.org}/${dir}`;
|
|
9015
|
+
for (const h of people) {
|
|
9016
|
+
const made = await actor.gh.request("POST", `repos/${repo}/labels`, {
|
|
9017
|
+
body: { name: h.marker, color: "1d76db", description: `An ask for ${h.name}` }
|
|
9018
|
+
});
|
|
9019
|
+
if (!made.ok && made.status !== 422)
|
|
9020
|
+
warnings.push(`label "${h.marker}" on ${dir}: ${made.error}`);
|
|
9021
|
+
}
|
|
9022
|
+
const v = { name: "ROSTER_HUMANS", value: logins };
|
|
9023
|
+
let set = await actor.gh.request("PATCH", `repos/${repo}/actions/variables/ROSTER_HUMANS`, {
|
|
9024
|
+
body: v
|
|
9025
|
+
});
|
|
9026
|
+
if (!set.ok && set.status === 404) {
|
|
9027
|
+
set = await actor.gh.request("POST", `repos/${repo}/actions/variables`, { body: v });
|
|
9028
|
+
}
|
|
9029
|
+
if (!set.ok) warnings.push(`who can wake ${dir}: ${set.error}`);
|
|
9030
|
+
})
|
|
9031
|
+
);
|
|
9032
|
+
return json({ ...saved, warnings });
|
|
9033
|
+
},
|
|
8869
9034
|
/* Connectors: what is offered, what this org has, and whether each one's keys are stored. */
|
|
8870
9035
|
"/api/connectors": async (c) => {
|
|
8871
9036
|
const { portal, actor } = c;
|
|
@@ -114,3 +114,23 @@
|
|
|
114
114
|
.effect{border:1px solid color-mix(in srgb,var(--accent) 35%,transparent);
|
|
115
115
|
background:color-mix(in srgb,var(--accent) 7%,transparent);
|
|
116
116
|
border-radius:var(--r);padding:11px 13px;margin-bottom:14px}
|
|
117
|
+
|
|
118
|
+
/* People on the Org screen: one row per person, edited in place. */
|
|
119
|
+
.peoplecard{margin-bottom:18px;display:flex;flex-direction:column;gap:12px}
|
|
120
|
+
.peoplecard h2{margin:0;font:600 15px var(--sans);color:var(--ink);text-transform:none;letter-spacing:-.01em}
|
|
121
|
+
.peoplelist{display:flex;flex-direction:column;gap:8px}
|
|
122
|
+
.peoplerow{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1.6fr) 72px auto;
|
|
123
|
+
gap:8px;align-items:center}
|
|
124
|
+
.peoplerow input[type=text]{width:100%;box-sizing:border-box;font:13px var(--sans);color:var(--ink);
|
|
125
|
+
background:var(--surface-2);border:1px solid transparent;border-radius:8px;padding:7px 9px}
|
|
126
|
+
.peoplerow input[type=text]:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
|
|
127
|
+
.peoplehead span{font:600 11.5px var(--sans);color:var(--ink-dim)}
|
|
128
|
+
.peopleonly{display:flex;justify-content:center}
|
|
129
|
+
.peoplerow .ghbtn{min-height:30px;padding:3px 12px;font-size:12.5px}
|
|
130
|
+
@media (max-width:720px){
|
|
131
|
+
.peoplehead{display:none}
|
|
132
|
+
.peoplerow{grid-template-columns:1fr 1fr;padding-bottom:10px;border-bottom:1px solid var(--line)}
|
|
133
|
+
.peoplerow > :nth-child(3){grid-column:1 / -1}
|
|
134
|
+
.peopleonly::after{content:"Read only";font:12.5px var(--sans);color:var(--ink-dim);margin-left:6px}
|
|
135
|
+
.peopleonly{justify-content:flex-start;align-items:center}
|
|
136
|
+
}
|
|
@@ -145,9 +145,13 @@
|
|
|
145
145
|
.orbcard.busy .orbglow{animation:orbbreathe 2.6s ease-in-out infinite}
|
|
146
146
|
.orbcard.busy .orbswirl{opacity:1;animation:orbspin 5s linear infinite}
|
|
147
147
|
.orbcard.busy .orbbody{animation:orbfloat 3.2s ease-in-out infinite}
|
|
148
|
-
|
|
149
|
-
.
|
|
150
|
-
.orbcard.queued
|
|
148
|
+
/* Waiting to start: yellow whoever it is, lit but slow, so it reads as "about to" rather than
|
|
149
|
+
"at work". GitHub has the run queued and no runner has picked it up yet. */
|
|
150
|
+
.orbcard.queued{--hue:#ffd60a!important;border-color:color-mix(in srgb,#ffd60a 35%,var(--line))}
|
|
151
|
+
.orbcard.queued .orbglow{animation:orbbreathe 2.2s ease-in-out infinite}
|
|
152
|
+
.orbcard.queued .orbswirl{opacity:.45;animation:orbspin 14s linear infinite}
|
|
153
|
+
.orbcard.queued .orbicon{color:#5c4a00;filter:none}
|
|
154
|
+
.orbcard.queued .orbstate{color:color-mix(in srgb,#ffd60a 70%,var(--ink))}
|
|
151
155
|
/* Free: the same orb, still and drained of colour. */
|
|
152
156
|
.orbcard.idle .orbbody,.orbcard.failed .orbbody,.orbcard.wait .orbbody{filter:saturate(.12) brightness(.95);opacity:.6}
|
|
153
157
|
.orbcard.failed .orb::after{content:"";position:absolute;top:4px;right:4px;width:12px;height:12px;border-radius:50%;
|
|
@@ -80,7 +80,12 @@ export function sortHome(items, staff, humans, live = [], now = new Date()) {
|
|
|
80
80
|
? "answered"
|
|
81
81
|
: "waiting";
|
|
82
82
|
}
|
|
83
|
-
if (place.place === "needs")
|
|
83
|
+
if (place.place === "needs") {
|
|
84
|
+
/* On nobody in particular, such as a pull request nobody was assigned: the first person's,
|
|
85
|
+
as the staff are told "something that fits nobody's area goes to" them. */
|
|
86
|
+
entry.for = whoFor(item, humans);
|
|
87
|
+
if (!entry.for.length && humans[0]?.github) entry.for = [humans[0].github];
|
|
88
|
+
}
|
|
84
89
|
out[place.place].push(entry);
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -129,8 +134,7 @@ export function placeOf(item, owner, people, markers) {
|
|
|
129
134
|
|
|
130
135
|
/**
|
|
131
136
|
* The people an ask is on, by login: whoever it is assigned to, and whoever's label it carries.
|
|
132
|
-
* Empty means nobody in particular, such as a pull request nobody was asked to look at
|
|
133
|
-
* it is everybody's.
|
|
137
|
+
* Empty means nobody in particular, such as a pull request nobody was asked to look at.
|
|
134
138
|
*/
|
|
135
139
|
export function whoFor(item, humans) {
|
|
136
140
|
const labels = new Set((item.labels ?? []).map(lower));
|
|
@@ -532,8 +532,10 @@ function team(staff) {
|
|
|
532
532
|
line = "Could not check on them";
|
|
533
533
|
} else if (busy || queued) {
|
|
534
534
|
const r = { ...runs[0], handle: s.handle };
|
|
535
|
-
word = busy ? "Working" : "
|
|
536
|
-
line = busy
|
|
535
|
+
word = busy ? "Working" : "Waiting to start";
|
|
536
|
+
line = busy
|
|
537
|
+
? `${whatRun(r)} · ${minutes(r.createdAt)} so far`
|
|
538
|
+
: `${whatRun(r)} · queued ${minutes(r.createdAt)} ago`;
|
|
537
539
|
} else if (failed) {
|
|
538
540
|
word = "Free";
|
|
539
541
|
line = `Their last session stopped with a problem, ${ago(last.updatedAt)}`;
|
|
@@ -20,6 +20,7 @@ import { mdlite } from "../md.js";
|
|
|
20
20
|
import { humansOf, S, writeHash } from "../state.js";
|
|
21
21
|
import { yamlPre } from "../yaml.js";
|
|
22
22
|
import { businessForm, fileModes, prioritiesForm } from "./orgedit.js";
|
|
23
|
+
import { peopleCard } from "./people.js";
|
|
23
24
|
import { repoPicker } from "./repos.js";
|
|
24
25
|
|
|
25
26
|
/* What the files roster itself ships are for, in one line each. A filename says nothing about
|
|
@@ -72,6 +73,7 @@ export function viewOrg(m) {
|
|
|
72
73
|
kv("Staff", String(org.staff.length), org.staff.map((s) => s.handle).join(", ")),
|
|
73
74
|
);
|
|
74
75
|
m.append(facts);
|
|
76
|
+
m.append(peopleCard());
|
|
75
77
|
|
|
76
78
|
/* Marking a product repo after setup. The picker only lived on the setup screen, so a repo
|
|
77
79
|
created later meant typing `role: product` into org.yaml by hand. Folded, because it asks
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* People: who the staff answer to, and what each of them looks after. On the Org screen.
|
|
2
|
+
*
|
|
3
|
+
* Saving writes the humans list in org.yaml, and the server then puts each person's label on
|
|
4
|
+
* every tracker and tells the mention callers who may wake a staff member, so somebody added
|
|
5
|
+
* here can send work straight away. */
|
|
6
|
+
|
|
7
|
+
import { post } from "../api.js";
|
|
8
|
+
import { el } from "../dom.js";
|
|
9
|
+
import { refreshAll } from "../refresh.js";
|
|
10
|
+
import { S } from "../state.js";
|
|
11
|
+
|
|
12
|
+
export function peopleCard() {
|
|
13
|
+
const start = (S.data?.people?.length ? S.data.people : (S.data?.humans ?? [])).map((h) => ({
|
|
14
|
+
name: h.name ?? "",
|
|
15
|
+
github: h.github ?? "",
|
|
16
|
+
marker: h.marker ?? "",
|
|
17
|
+
role: h.role ?? "",
|
|
18
|
+
handles: (h.handles ?? []).join(", "),
|
|
19
|
+
view_only: Boolean(h.viewOnly),
|
|
20
|
+
}));
|
|
21
|
+
const rows = start.map((p) => ({ ...p }));
|
|
22
|
+
|
|
23
|
+
const list = el("div", { className: "peoplelist" });
|
|
24
|
+
const note = el("span", { className: "meta" });
|
|
25
|
+
const save = el("button", { className: "ghbtn primary", textContent: "Save" });
|
|
26
|
+
const add = el("button", { className: "ghbtn", textContent: "Add a person" });
|
|
27
|
+
|
|
28
|
+
const changed = () => JSON.stringify(rows) !== JSON.stringify(start);
|
|
29
|
+
const stamp = () => {
|
|
30
|
+
save.disabled = !changed();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function paint() {
|
|
34
|
+
list.replaceChildren(
|
|
35
|
+
el("div", { className: "peoplerow peoplehead", ariaHidden: "true" }, [
|
|
36
|
+
el("span", { textContent: "Name" }),
|
|
37
|
+
el("span", { textContent: "GitHub login" }),
|
|
38
|
+
el("span", { textContent: "Looks after" }),
|
|
39
|
+
el("span", { textContent: "Read only" }),
|
|
40
|
+
el("span"),
|
|
41
|
+
]),
|
|
42
|
+
...rows.map((p, i) => row(p, i)),
|
|
43
|
+
);
|
|
44
|
+
stamp();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function row(p, i) {
|
|
48
|
+
const input = (key, placeholder, label) => {
|
|
49
|
+
const box = el("input", { type: "text", value: p[key], placeholder, ariaLabel: label });
|
|
50
|
+
box.oninput = () => {
|
|
51
|
+
p[key] = box.value;
|
|
52
|
+
stamp();
|
|
53
|
+
};
|
|
54
|
+
return box;
|
|
55
|
+
};
|
|
56
|
+
const only = el("input", { type: "checkbox", checked: p.view_only, ariaLabel: "Read only" });
|
|
57
|
+
only.onchange = () => {
|
|
58
|
+
p.view_only = only.checked;
|
|
59
|
+
stamp();
|
|
60
|
+
};
|
|
61
|
+
const remove = el("button", { className: "ghbtn danger", textContent: "Remove" });
|
|
62
|
+
remove.onclick = () => {
|
|
63
|
+
rows.splice(i, 1);
|
|
64
|
+
paint();
|
|
65
|
+
};
|
|
66
|
+
return el("div", { className: "peoplerow" }, [
|
|
67
|
+
input("name", "Name", "Name"),
|
|
68
|
+
input("github", "login", "GitHub login"),
|
|
69
|
+
input("handles", "e.g. marketing, content", "Looks after"),
|
|
70
|
+
el("label", { className: "peopleonly" }, [only]),
|
|
71
|
+
remove,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
add.onclick = () => {
|
|
76
|
+
rows.push({ name: "", github: "", marker: "", role: "", handles: "", view_only: false });
|
|
77
|
+
paint();
|
|
78
|
+
list.querySelector(".peoplerow:last-child input")?.focus();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
save.onclick = async () => {
|
|
82
|
+
save.disabled = true;
|
|
83
|
+
note.className = "meta";
|
|
84
|
+
note.textContent = "Saving…";
|
|
85
|
+
try {
|
|
86
|
+
const r = await post({ people: rows.filter((p) => p.github.trim() || p.name.trim()) }, "/api/people");
|
|
87
|
+
note.textContent = r.warnings?.length ? "Saved, but: " + r.warnings.join("; ") : "Saved.";
|
|
88
|
+
if (r.warnings?.length) note.className = "meta warn";
|
|
89
|
+
await refreshAll(false);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
note.textContent = String(e.message || e);
|
|
92
|
+
note.className = "meta err";
|
|
93
|
+
stamp();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
paint();
|
|
98
|
+
return el("div", { className: "card peoplecard" }, [
|
|
99
|
+
el("h2", { textContent: "People" }),
|
|
100
|
+
list,
|
|
101
|
+
el("div", { className: "row" }, [add, save, note]),
|
|
102
|
+
]);
|
|
103
|
+
}
|