@staff0rd/assist 0.733.0 → 0.734.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/README.md +2 -2
- package/dist/commands/sessions/web/bundle.js +3 -3
- package/dist/index.js +83 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.734.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -861,7 +861,12 @@ var assistConfigShape = {
|
|
|
861
861
|
next: z3.strictObject({
|
|
862
862
|
peers: z3.array(z3.string()).optional(),
|
|
863
863
|
repos: z3.array(z3.string()).optional(),
|
|
864
|
-
|
|
864
|
+
projects: z3.array(
|
|
865
|
+
z3.string().regex(
|
|
866
|
+
/^[^/\s]+\/\d+$/,
|
|
867
|
+
"Use <owner>/<project number>, e.g. my-org/3"
|
|
868
|
+
)
|
|
869
|
+
).optional(),
|
|
865
870
|
pickStatuses: z3.array(z3.string()).optional()
|
|
866
871
|
}).optional(),
|
|
867
872
|
deny: z3.array(
|
|
@@ -12580,9 +12585,9 @@ var nextConfigHelp = [
|
|
|
12580
12585
|
note: "GitHub repos the web /next view reads peer PRs and issues assigned to you from: owner/name for one repo, or a bare owner (org or user) for all its unarchived repos (default: the selected repo)"
|
|
12581
12586
|
},
|
|
12582
12587
|
{
|
|
12583
|
-
key: "next.
|
|
12584
|
-
setter: "assist config set next.
|
|
12585
|
-
note: "GitHub
|
|
12588
|
+
key: "next.projects",
|
|
12589
|
+
setter: "assist config set next.projects my-org/3,my-org/5 -g --repo",
|
|
12590
|
+
note: "GitHub Projects (owner/number, from each URL) the web /next view suggests unassigned issues to pick up from; needs the gh project scope"
|
|
12586
12591
|
},
|
|
12587
12592
|
{
|
|
12588
12593
|
key: "next.pickStatuses",
|
|
@@ -13943,6 +13948,11 @@ async function fetchPeerPrs(cwd, repo, peers) {
|
|
|
13943
13948
|
return selectPeerPrs(nodes, viewer, peers).map((pr) => ({ ...pr, repo }));
|
|
13944
13949
|
}
|
|
13945
13950
|
|
|
13951
|
+
// src/commands/sessions/web/next/comparePickups.ts
|
|
13952
|
+
function comparePickups(a, b) {
|
|
13953
|
+
return a.priorityRank - b.priorityRank || a.createdAt.localeCompare(b.createdAt);
|
|
13954
|
+
}
|
|
13955
|
+
|
|
13946
13956
|
// src/commands/sessions/web/next/ghErrorText.ts
|
|
13947
13957
|
function ghErrorText(error) {
|
|
13948
13958
|
const stderr = error.stderr;
|
|
@@ -13950,12 +13960,12 @@ function ghErrorText(error) {
|
|
|
13950
13960
|
return error instanceof Error ? error.message : String(error);
|
|
13951
13961
|
}
|
|
13952
13962
|
|
|
13953
|
-
// src/commands/sessions/web/next/
|
|
13954
|
-
function
|
|
13963
|
+
// src/commands/sessions/web/next/projectErrorText.ts
|
|
13964
|
+
function projectErrorText(error) {
|
|
13955
13965
|
const text18 = ghErrorText(error);
|
|
13956
13966
|
if (/read:project|required scopes/i.test(text18))
|
|
13957
|
-
return
|
|
13958
|
-
return
|
|
13967
|
+
return "The gh token has no project scope, so the project cannot be read. Run: gh auth refresh -h github.com -s project";
|
|
13968
|
+
return text18;
|
|
13959
13969
|
}
|
|
13960
13970
|
|
|
13961
13971
|
// src/commands/sessions/web/next/pickupsQuery.ts
|
|
@@ -13963,6 +13973,7 @@ var pickupsQuery = `query($owner: String!, $number: Int!, $after: String) {
|
|
|
13963
13973
|
repositoryOwner(login: $owner) {
|
|
13964
13974
|
... on ProjectV2Owner {
|
|
13965
13975
|
projectV2(number: $number) {
|
|
13976
|
+
title
|
|
13966
13977
|
priorityField: field(name: "Priority") {
|
|
13967
13978
|
... on ProjectV2SingleSelectField { options { name } }
|
|
13968
13979
|
}
|
|
@@ -14016,7 +14027,7 @@ var MAX_PAGES = 10;
|
|
|
14016
14027
|
async function readProjectItems(cwd, project) {
|
|
14017
14028
|
const [owner, number] = project.split("/");
|
|
14018
14029
|
const nodes = [];
|
|
14019
|
-
|
|
14030
|
+
const board = { project, title: project, priorityOrder: [] };
|
|
14020
14031
|
let after = null;
|
|
14021
14032
|
for (let page = 0; page < MAX_PAGES; page++) {
|
|
14022
14033
|
const response = await readProjectPage(cwd, owner, number, after);
|
|
@@ -14025,7 +14036,8 @@ async function readProjectItems(cwd, project) {
|
|
|
14025
14036
|
const reason4 = response.errors?.[0]?.message;
|
|
14026
14037
|
throw new Error(reason4 ?? `No project ${number} owned by ${owner}`);
|
|
14027
14038
|
}
|
|
14028
|
-
|
|
14039
|
+
board.title = projectV2.title ?? project;
|
|
14040
|
+
board.priorityOrder = (projectV2.priorityField?.options ?? []).map(
|
|
14029
14041
|
(option) => option.name
|
|
14030
14042
|
);
|
|
14031
14043
|
for (const node of projectV2.items.nodes ?? []) if (node) nodes.push(node);
|
|
@@ -14033,15 +14045,41 @@ async function readProjectItems(cwd, project) {
|
|
|
14033
14045
|
if (!hasNextPage2 || !endCursor) break;
|
|
14034
14046
|
after = endCursor;
|
|
14035
14047
|
}
|
|
14036
|
-
return { nodes,
|
|
14048
|
+
return { nodes, board };
|
|
14049
|
+
}
|
|
14050
|
+
|
|
14051
|
+
// src/commands/sessions/web/next/sectionAcross.ts
|
|
14052
|
+
async function sectionAcross(repos2, load3, compare) {
|
|
14053
|
+
if (repos2.length === 0)
|
|
14054
|
+
return {
|
|
14055
|
+
items: [],
|
|
14056
|
+
error: "No GitHub repo to read: set next.repos or select a repo with a GitHub origin."
|
|
14057
|
+
};
|
|
14058
|
+
const results = await Promise.allSettled(repos2.map((repo) => load3(repo)));
|
|
14059
|
+
const items2 = /* @__PURE__ */ new Map();
|
|
14060
|
+
const errors = [];
|
|
14061
|
+
results.forEach((result, index3) => {
|
|
14062
|
+
if (result.status === "fulfilled")
|
|
14063
|
+
for (const item of result.value) items2.set(item.url, item);
|
|
14064
|
+
else errors.push(`${repos2[index3]}: ${ghErrorText(result.reason)}`);
|
|
14065
|
+
});
|
|
14066
|
+
return {
|
|
14067
|
+
items: [...items2.values()].sort(compare),
|
|
14068
|
+
error: errors.length > 0 ? errors.join("\n") : null
|
|
14069
|
+
};
|
|
14037
14070
|
}
|
|
14038
14071
|
|
|
14039
14072
|
// src/commands/sessions/web/next/selectPickups.ts
|
|
14040
|
-
function
|
|
14073
|
+
function priorityRank(priority, order) {
|
|
14074
|
+
const index3 = priority ? order.indexOf(priority) : -1;
|
|
14075
|
+
return index3 === -1 ? order.length : index3;
|
|
14076
|
+
}
|
|
14077
|
+
function toPickup(node, board) {
|
|
14041
14078
|
const issue = node.content;
|
|
14042
14079
|
const repo = issue?.repository?.nameWithOwner;
|
|
14043
14080
|
const status3 = node.status?.name;
|
|
14044
14081
|
if (!issue?.number || !issue.url || !repo || !status3) return null;
|
|
14082
|
+
const priority = node.priority?.name ?? null;
|
|
14045
14083
|
return {
|
|
14046
14084
|
repo,
|
|
14047
14085
|
number: issue.number,
|
|
@@ -14052,37 +14090,38 @@ function toPickup(node) {
|
|
|
14052
14090
|
labels: (issue.labels?.nodes ?? []).flatMap(
|
|
14053
14091
|
(label2) => label2?.name ? [label2.name] : []
|
|
14054
14092
|
),
|
|
14093
|
+
project: board.project,
|
|
14094
|
+
projectTitle: board.title,
|
|
14055
14095
|
itemId: node.id,
|
|
14056
14096
|
status: status3,
|
|
14057
|
-
priority
|
|
14097
|
+
priority,
|
|
14098
|
+
priorityRank: priorityRank(priority, board.priorityOrder)
|
|
14058
14099
|
};
|
|
14059
14100
|
}
|
|
14060
|
-
function selectPickups(nodes, pickStatuses,
|
|
14101
|
+
function selectPickups(nodes, pickStatuses, board) {
|
|
14061
14102
|
const statuses = new Set(pickStatuses.map((status3) => status3.toLowerCase()));
|
|
14062
|
-
const rank = (pickup) => {
|
|
14063
|
-
const index3 = pickup.priority ? priorityOrder.indexOf(pickup.priority) : -1;
|
|
14064
|
-
return index3 === -1 ? priorityOrder.length : index3;
|
|
14065
|
-
};
|
|
14066
14103
|
return nodes.filter(
|
|
14067
14104
|
(node) => node.content?.state === "OPEN" && node.content.assignees?.totalCount === 0
|
|
14068
|
-
).flatMap((node) => toPickup(node) ?? []).filter((pickup) => statuses.has(pickup.status.toLowerCase())).sort(
|
|
14069
|
-
(a, b) => rank(a) - rank(b) || a.createdAt.localeCompare(b.createdAt)
|
|
14070
|
-
);
|
|
14105
|
+
).flatMap((node) => toPickup(node, board) ?? []).filter((pickup) => statuses.has(pickup.status.toLowerCase())).sort(comparePickups);
|
|
14071
14106
|
}
|
|
14072
14107
|
|
|
14073
14108
|
// src/commands/sessions/web/next/fetchPickups.ts
|
|
14074
|
-
async function
|
|
14075
|
-
if (!project) return { items: [], error: null };
|
|
14109
|
+
async function loadPickups(cwd, project, pickStatuses) {
|
|
14076
14110
|
try {
|
|
14077
|
-
const { nodes,
|
|
14078
|
-
return
|
|
14079
|
-
items: selectPickups(nodes, pickStatuses, priorityOrder),
|
|
14080
|
-
error: null
|
|
14081
|
-
};
|
|
14111
|
+
const { nodes, board } = await readProjectItems(cwd, project);
|
|
14112
|
+
return selectPickups(nodes, pickStatuses, board);
|
|
14082
14113
|
} catch (error) {
|
|
14083
|
-
|
|
14114
|
+
throw new Error(projectErrorText(error));
|
|
14084
14115
|
}
|
|
14085
14116
|
}
|
|
14117
|
+
async function fetchPickups(cwd, projects, pickStatuses) {
|
|
14118
|
+
if (projects.length === 0) return { items: [], error: null };
|
|
14119
|
+
return sectionAcross(
|
|
14120
|
+
projects,
|
|
14121
|
+
(project) => loadPickups(cwd, project, pickStatuses),
|
|
14122
|
+
comparePickups
|
|
14123
|
+
);
|
|
14124
|
+
}
|
|
14086
14125
|
|
|
14087
14126
|
// src/commands/sessions/web/next/nextScope.ts
|
|
14088
14127
|
var GITHUB = "github.com/";
|
|
@@ -14097,7 +14136,7 @@ function nextScope(cwd) {
|
|
|
14097
14136
|
selfRepo: githubRepo(cwd),
|
|
14098
14137
|
peers: next3?.peers ?? [],
|
|
14099
14138
|
repos: next3?.repos ?? null,
|
|
14100
|
-
|
|
14139
|
+
projects: next3?.projects ?? [],
|
|
14101
14140
|
pickStatuses: next3?.pickStatuses ?? DEFAULT_PICK_STATUSES
|
|
14102
14141
|
};
|
|
14103
14142
|
}
|
|
@@ -14108,27 +14147,6 @@ function scopeRepos(configured, selfRepo) {
|
|
|
14108
14147
|
return selfRepo ? [selfRepo] : [];
|
|
14109
14148
|
}
|
|
14110
14149
|
|
|
14111
|
-
// src/commands/sessions/web/next/sectionAcross.ts
|
|
14112
|
-
async function sectionAcross(repos2, load3, compare) {
|
|
14113
|
-
if (repos2.length === 0)
|
|
14114
|
-
return {
|
|
14115
|
-
items: [],
|
|
14116
|
-
error: "No GitHub repo to read: set next.repos or select a repo with a GitHub origin."
|
|
14117
|
-
};
|
|
14118
|
-
const results = await Promise.allSettled(repos2.map((repo) => load3(repo)));
|
|
14119
|
-
const items2 = /* @__PURE__ */ new Map();
|
|
14120
|
-
const errors = [];
|
|
14121
|
-
results.forEach((result, index3) => {
|
|
14122
|
-
if (result.status === "fulfilled")
|
|
14123
|
-
for (const item of result.value) items2.set(item.url, item);
|
|
14124
|
-
else errors.push(`${repos2[index3]}: ${ghErrorText(result.reason)}`);
|
|
14125
|
-
});
|
|
14126
|
-
return {
|
|
14127
|
-
items: [...items2.values()].sort(compare),
|
|
14128
|
-
error: errors.length > 0 ? errors.join("\n") : null
|
|
14129
|
-
};
|
|
14130
|
-
}
|
|
14131
|
-
|
|
14132
14150
|
// src/commands/sessions/web/next/nextItems.ts
|
|
14133
14151
|
async function nextItems(req, res) {
|
|
14134
14152
|
const cwd = getCwdParam(req, res);
|
|
@@ -14146,7 +14164,7 @@ async function nextItems(req, res) {
|
|
|
14146
14164
|
(repo) => fetchAssignedIssues(cwd, repo),
|
|
14147
14165
|
(a, b) => a.createdAt.localeCompare(b.createdAt)
|
|
14148
14166
|
),
|
|
14149
|
-
fetchPickups(cwd, scope.
|
|
14167
|
+
fetchPickups(cwd, scope.projects, scope.pickStatuses)
|
|
14150
14168
|
]);
|
|
14151
14169
|
const body = { scope, peerPrs, assignedIssues, pickups };
|
|
14152
14170
|
respondJson(res, 200, body);
|
|
@@ -14306,16 +14324,16 @@ function setProjectItemStatus(input) {
|
|
|
14306
14324
|
|
|
14307
14325
|
// src/commands/sessions/web/next/pickUpItem.ts
|
|
14308
14326
|
var IN_PROGRESS = "in progress";
|
|
14309
|
-
function pickUpItem(
|
|
14327
|
+
function pickUpItem(target) {
|
|
14310
14328
|
assertProjectScope();
|
|
14311
|
-
const [owner, number] = project.split("/");
|
|
14329
|
+
const [owner, number] = target.project.split("/");
|
|
14312
14330
|
const board = fetchProjectV2(owner, Number(number));
|
|
14313
14331
|
const option = board.statusField?.options.find(
|
|
14314
14332
|
(candidate) => candidate.name.toLowerCase() === IN_PROGRESS
|
|
14315
14333
|
);
|
|
14316
14334
|
if (!board.statusField || !option)
|
|
14317
14335
|
throw new Error(
|
|
14318
|
-
`Project ${project} (${board.title}) has no In Progress status to move ${target.repo}#${target.number} to`
|
|
14336
|
+
`Project ${target.project} (${board.title}) has no In Progress status to move ${target.repo}#${target.number} to`
|
|
14319
14337
|
);
|
|
14320
14338
|
assignIssueToSelf(target.number, target.repo);
|
|
14321
14339
|
setProjectItemStatus({
|
|
@@ -14328,11 +14346,12 @@ function pickUpItem(project, target) {
|
|
|
14328
14346
|
|
|
14329
14347
|
// src/commands/sessions/web/next/nextPickup.ts
|
|
14330
14348
|
function parseTarget(body) {
|
|
14331
|
-
const { repo, number, itemId: itemId2 } = body ?? {};
|
|
14349
|
+
const { project, repo, number, itemId: itemId2 } = body ?? {};
|
|
14350
|
+
if (typeof project !== "string") return null;
|
|
14332
14351
|
if (typeof repo !== "string" || !repo.includes("/")) return null;
|
|
14333
14352
|
if (typeof number !== "number" || !Number.isInteger(number)) return null;
|
|
14334
14353
|
if (typeof itemId2 !== "string" || !itemId2) return null;
|
|
14335
|
-
return { repo, number, itemId: itemId2 };
|
|
14354
|
+
return { project, repo, number, itemId: itemId2 };
|
|
14336
14355
|
}
|
|
14337
14356
|
async function nextPickup(req, res) {
|
|
14338
14357
|
const cwd = getCwdParam(req, res);
|
|
@@ -14345,16 +14364,17 @@ async function nextPickup(req, res) {
|
|
|
14345
14364
|
return;
|
|
14346
14365
|
}
|
|
14347
14366
|
if (!target) {
|
|
14348
|
-
respondJson(res, 400, { error: "Missing repo, number or itemId" });
|
|
14367
|
+
respondJson(res, 400, { error: "Missing project, repo, number or itemId" });
|
|
14349
14368
|
return;
|
|
14350
14369
|
}
|
|
14351
|
-
|
|
14352
|
-
|
|
14353
|
-
|
|
14370
|
+
if (!nextScope(cwd).projects.includes(target.project)) {
|
|
14371
|
+
respondJson(res, 400, {
|
|
14372
|
+
error: `${target.project} is not in next.projects for this repo`
|
|
14373
|
+
});
|
|
14354
14374
|
return;
|
|
14355
14375
|
}
|
|
14356
14376
|
try {
|
|
14357
|
-
pickUpItem(
|
|
14377
|
+
pickUpItem(target);
|
|
14358
14378
|
respondJson(res, 200, { ok: true });
|
|
14359
14379
|
} catch (error) {
|
|
14360
14380
|
respondJson(res, 500, { error: ghErrorText(error) });
|