@staff0rd/assist 0.733.0 → 0.735.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 +4 -2
- package/dist/commands/sessions/web/bundle.js +59 -59
- package/dist/index.js +119 -68
- 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.735.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -861,8 +861,15 @@ var assistConfigShape = {
|
|
|
861
861
|
next: z3.strictObject({
|
|
862
862
|
peers: z3.array(z3.string()).optional(),
|
|
863
863
|
repos: z3.array(z3.string()).optional(),
|
|
864
|
-
|
|
865
|
-
|
|
864
|
+
projects: z3.array(
|
|
865
|
+
z3.string().regex(
|
|
866
|
+
/^[^/\s]+\/\d+$/,
|
|
867
|
+
"Use <owner>/<project number>, e.g. my-org/3"
|
|
868
|
+
)
|
|
869
|
+
).optional(),
|
|
870
|
+
pickStatuses: z3.array(z3.string()).optional(),
|
|
871
|
+
excludeLabels: z3.array(z3.string()).optional(),
|
|
872
|
+
excludeTypes: z3.array(z3.string()).optional()
|
|
866
873
|
}).optional(),
|
|
867
874
|
deny: z3.array(
|
|
868
875
|
z3.strictObject({
|
|
@@ -12580,14 +12587,24 @@ var nextConfigHelp = [
|
|
|
12580
12587
|
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
12588
|
},
|
|
12582
12589
|
{
|
|
12583
|
-
key: "next.
|
|
12584
|
-
setter: "assist config set next.
|
|
12585
|
-
note: "GitHub
|
|
12590
|
+
key: "next.projects",
|
|
12591
|
+
setter: "assist config set next.projects my-org/3,my-org/5 -g --repo",
|
|
12592
|
+
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
12593
|
},
|
|
12587
12594
|
{
|
|
12588
12595
|
key: "next.pickStatuses",
|
|
12589
12596
|
setter: "assist config set next.pickStatuses Ready,Todo -g --repo",
|
|
12590
12597
|
note: "Project Status values whose unassigned items the web /next view offers to pick up (default: Ready, Todo)"
|
|
12598
|
+
},
|
|
12599
|
+
{
|
|
12600
|
+
key: "next.excludeLabels",
|
|
12601
|
+
setter: "assist config set next.excludeLabels blocked,spike -g --repo",
|
|
12602
|
+
note: "Labels whose project items the web /next view never offers to pick up (case-insensitive)"
|
|
12603
|
+
},
|
|
12604
|
+
{
|
|
12605
|
+
key: "next.excludeTypes",
|
|
12606
|
+
setter: "assist config set next.excludeTypes Epic -g --repo",
|
|
12607
|
+
note: "GitHub issue types whose project items the web /next view never offers to pick up (case-insensitive)"
|
|
12591
12608
|
}
|
|
12592
12609
|
];
|
|
12593
12610
|
|
|
@@ -13943,6 +13960,11 @@ async function fetchPeerPrs(cwd, repo, peers) {
|
|
|
13943
13960
|
return selectPeerPrs(nodes, viewer, peers).map((pr) => ({ ...pr, repo }));
|
|
13944
13961
|
}
|
|
13945
13962
|
|
|
13963
|
+
// src/commands/sessions/web/next/comparePickups.ts
|
|
13964
|
+
function comparePickups(a, b) {
|
|
13965
|
+
return a.priorityRank - b.priorityRank || a.createdAt.localeCompare(b.createdAt);
|
|
13966
|
+
}
|
|
13967
|
+
|
|
13946
13968
|
// src/commands/sessions/web/next/ghErrorText.ts
|
|
13947
13969
|
function ghErrorText(error) {
|
|
13948
13970
|
const stderr = error.stderr;
|
|
@@ -13950,12 +13972,12 @@ function ghErrorText(error) {
|
|
|
13950
13972
|
return error instanceof Error ? error.message : String(error);
|
|
13951
13973
|
}
|
|
13952
13974
|
|
|
13953
|
-
// src/commands/sessions/web/next/
|
|
13954
|
-
function
|
|
13975
|
+
// src/commands/sessions/web/next/projectErrorText.ts
|
|
13976
|
+
function projectErrorText(error) {
|
|
13955
13977
|
const text18 = ghErrorText(error);
|
|
13956
13978
|
if (/read:project|required scopes/i.test(text18))
|
|
13957
|
-
return
|
|
13958
|
-
return
|
|
13979
|
+
return "The gh token has no project scope, so the project cannot be read. Run: gh auth refresh -h github.com -s project";
|
|
13980
|
+
return text18;
|
|
13959
13981
|
}
|
|
13960
13982
|
|
|
13961
13983
|
// src/commands/sessions/web/next/pickupsQuery.ts
|
|
@@ -13963,6 +13985,7 @@ var pickupsQuery = `query($owner: String!, $number: Int!, $after: String) {
|
|
|
13963
13985
|
repositoryOwner(login: $owner) {
|
|
13964
13986
|
... on ProjectV2Owner {
|
|
13965
13987
|
projectV2(number: $number) {
|
|
13988
|
+
title
|
|
13966
13989
|
priorityField: field(name: "Priority") {
|
|
13967
13990
|
... on ProjectV2SingleSelectField { options { name } }
|
|
13968
13991
|
}
|
|
@@ -13986,6 +14009,7 @@ var pickupsQuery = `query($owner: String!, $number: Int!, $after: String) {
|
|
|
13986
14009
|
author { login }
|
|
13987
14010
|
repository { nameWithOwner }
|
|
13988
14011
|
assignees(first: 1) { totalCount }
|
|
14012
|
+
issueType { name }
|
|
13989
14013
|
labels(first: 20) { nodes { name } }
|
|
13990
14014
|
}
|
|
13991
14015
|
}
|
|
@@ -14016,7 +14040,7 @@ var MAX_PAGES = 10;
|
|
|
14016
14040
|
async function readProjectItems(cwd, project) {
|
|
14017
14041
|
const [owner, number] = project.split("/");
|
|
14018
14042
|
const nodes = [];
|
|
14019
|
-
|
|
14043
|
+
const board = { project, title: project, priorityOrder: [] };
|
|
14020
14044
|
let after = null;
|
|
14021
14045
|
for (let page = 0; page < MAX_PAGES; page++) {
|
|
14022
14046
|
const response = await readProjectPage(cwd, owner, number, after);
|
|
@@ -14025,7 +14049,8 @@ async function readProjectItems(cwd, project) {
|
|
|
14025
14049
|
const reason4 = response.errors?.[0]?.message;
|
|
14026
14050
|
throw new Error(reason4 ?? `No project ${number} owned by ${owner}`);
|
|
14027
14051
|
}
|
|
14028
|
-
|
|
14052
|
+
board.title = projectV2.title ?? project;
|
|
14053
|
+
board.priorityOrder = (projectV2.priorityField?.options ?? []).map(
|
|
14029
14054
|
(option) => option.name
|
|
14030
14055
|
);
|
|
14031
14056
|
for (const node of projectV2.items.nodes ?? []) if (node) nodes.push(node);
|
|
@@ -14033,15 +14058,60 @@ async function readProjectItems(cwd, project) {
|
|
|
14033
14058
|
if (!hasNextPage2 || !endCursor) break;
|
|
14034
14059
|
after = endCursor;
|
|
14035
14060
|
}
|
|
14036
|
-
return { nodes,
|
|
14061
|
+
return { nodes, board };
|
|
14062
|
+
}
|
|
14063
|
+
|
|
14064
|
+
// src/commands/sessions/web/next/sectionAcross.ts
|
|
14065
|
+
async function sectionAcross(repos2, load3, compare) {
|
|
14066
|
+
if (repos2.length === 0)
|
|
14067
|
+
return {
|
|
14068
|
+
items: [],
|
|
14069
|
+
error: "No GitHub repo to read: set next.repos or select a repo with a GitHub origin."
|
|
14070
|
+
};
|
|
14071
|
+
const results = await Promise.allSettled(repos2.map((repo) => load3(repo)));
|
|
14072
|
+
const items2 = /* @__PURE__ */ new Map();
|
|
14073
|
+
const errors = [];
|
|
14074
|
+
results.forEach((result, index3) => {
|
|
14075
|
+
if (result.status === "fulfilled")
|
|
14076
|
+
for (const item of result.value) items2.set(item.url, item);
|
|
14077
|
+
else errors.push(`${repos2[index3]}: ${ghErrorText(result.reason)}`);
|
|
14078
|
+
});
|
|
14079
|
+
return {
|
|
14080
|
+
items: [...items2.values()].sort(compare),
|
|
14081
|
+
error: errors.length > 0 ? errors.join("\n") : null
|
|
14082
|
+
};
|
|
14083
|
+
}
|
|
14084
|
+
|
|
14085
|
+
// src/commands/sessions/web/next/isPickable.ts
|
|
14086
|
+
var lowered = (values) => new Set(values.map((value) => value.toLowerCase()));
|
|
14087
|
+
function isPickable(filter) {
|
|
14088
|
+
const statuses = lowered(filter.pickStatuses);
|
|
14089
|
+
const excludedLabels = lowered(filter.excludeLabels);
|
|
14090
|
+
const excludedTypes = lowered(filter.excludeTypes);
|
|
14091
|
+
return (node) => {
|
|
14092
|
+
const issue = node.content;
|
|
14093
|
+
if (issue?.state !== "OPEN" || issue.assignees?.totalCount !== 0)
|
|
14094
|
+
return false;
|
|
14095
|
+
if (!statuses.has(node.status?.name?.toLowerCase() ?? "")) return false;
|
|
14096
|
+
const type = issue.issueType?.name?.toLowerCase();
|
|
14097
|
+
if (type && excludedTypes.has(type)) return false;
|
|
14098
|
+
return !(issue.labels?.nodes ?? []).some(
|
|
14099
|
+
(label2) => label2?.name && excludedLabels.has(label2.name.toLowerCase())
|
|
14100
|
+
);
|
|
14101
|
+
};
|
|
14037
14102
|
}
|
|
14038
14103
|
|
|
14039
14104
|
// src/commands/sessions/web/next/selectPickups.ts
|
|
14040
|
-
function
|
|
14105
|
+
function priorityRank(priority, order) {
|
|
14106
|
+
const index3 = priority ? order.indexOf(priority) : -1;
|
|
14107
|
+
return index3 === -1 ? order.length : index3;
|
|
14108
|
+
}
|
|
14109
|
+
function toPickup(node, board) {
|
|
14041
14110
|
const issue = node.content;
|
|
14042
14111
|
const repo = issue?.repository?.nameWithOwner;
|
|
14043
14112
|
const status3 = node.status?.name;
|
|
14044
14113
|
if (!issue?.number || !issue.url || !repo || !status3) return null;
|
|
14114
|
+
const priority = node.priority?.name ?? null;
|
|
14045
14115
|
return {
|
|
14046
14116
|
repo,
|
|
14047
14117
|
number: issue.number,
|
|
@@ -14052,37 +14122,35 @@ function toPickup(node) {
|
|
|
14052
14122
|
labels: (issue.labels?.nodes ?? []).flatMap(
|
|
14053
14123
|
(label2) => label2?.name ? [label2.name] : []
|
|
14054
14124
|
),
|
|
14125
|
+
project: board.project,
|
|
14126
|
+
projectTitle: board.title,
|
|
14055
14127
|
itemId: node.id,
|
|
14056
14128
|
status: status3,
|
|
14057
|
-
priority
|
|
14129
|
+
priority,
|
|
14130
|
+
priorityRank: priorityRank(priority, board.priorityOrder)
|
|
14058
14131
|
};
|
|
14059
14132
|
}
|
|
14060
|
-
function selectPickups(nodes,
|
|
14061
|
-
|
|
14062
|
-
const rank = (pickup) => {
|
|
14063
|
-
const index3 = pickup.priority ? priorityOrder.indexOf(pickup.priority) : -1;
|
|
14064
|
-
return index3 === -1 ? priorityOrder.length : index3;
|
|
14065
|
-
};
|
|
14066
|
-
return nodes.filter(
|
|
14067
|
-
(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
|
-
);
|
|
14133
|
+
function selectPickups(nodes, filter, board) {
|
|
14134
|
+
return nodes.filter(isPickable(filter)).flatMap((node) => toPickup(node, board) ?? []).sort(comparePickups);
|
|
14071
14135
|
}
|
|
14072
14136
|
|
|
14073
14137
|
// src/commands/sessions/web/next/fetchPickups.ts
|
|
14074
|
-
async function
|
|
14075
|
-
if (!project) return { items: [], error: null };
|
|
14138
|
+
async function loadPickups(cwd, project, filter) {
|
|
14076
14139
|
try {
|
|
14077
|
-
const { nodes,
|
|
14078
|
-
return
|
|
14079
|
-
items: selectPickups(nodes, pickStatuses, priorityOrder),
|
|
14080
|
-
error: null
|
|
14081
|
-
};
|
|
14140
|
+
const { nodes, board } = await readProjectItems(cwd, project);
|
|
14141
|
+
return selectPickups(nodes, filter, board);
|
|
14082
14142
|
} catch (error) {
|
|
14083
|
-
|
|
14143
|
+
throw new Error(projectErrorText(error));
|
|
14084
14144
|
}
|
|
14085
14145
|
}
|
|
14146
|
+
async function fetchPickups(cwd, projects, filter) {
|
|
14147
|
+
if (projects.length === 0) return { items: [], error: null };
|
|
14148
|
+
return sectionAcross(
|
|
14149
|
+
projects,
|
|
14150
|
+
(project) => loadPickups(cwd, project, filter),
|
|
14151
|
+
comparePickups
|
|
14152
|
+
);
|
|
14153
|
+
}
|
|
14086
14154
|
|
|
14087
14155
|
// src/commands/sessions/web/next/nextScope.ts
|
|
14088
14156
|
var GITHUB = "github.com/";
|
|
@@ -14097,8 +14165,10 @@ function nextScope(cwd) {
|
|
|
14097
14165
|
selfRepo: githubRepo(cwd),
|
|
14098
14166
|
peers: next3?.peers ?? [],
|
|
14099
14167
|
repos: next3?.repos ?? null,
|
|
14100
|
-
|
|
14101
|
-
pickStatuses: next3?.pickStatuses ?? DEFAULT_PICK_STATUSES
|
|
14168
|
+
projects: next3?.projects ?? [],
|
|
14169
|
+
pickStatuses: next3?.pickStatuses ?? DEFAULT_PICK_STATUSES,
|
|
14170
|
+
excludeLabels: next3?.excludeLabels ?? [],
|
|
14171
|
+
excludeTypes: next3?.excludeTypes ?? []
|
|
14102
14172
|
};
|
|
14103
14173
|
}
|
|
14104
14174
|
|
|
@@ -14108,27 +14178,6 @@ function scopeRepos(configured, selfRepo) {
|
|
|
14108
14178
|
return selfRepo ? [selfRepo] : [];
|
|
14109
14179
|
}
|
|
14110
14180
|
|
|
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
14181
|
// src/commands/sessions/web/next/nextItems.ts
|
|
14133
14182
|
async function nextItems(req, res) {
|
|
14134
14183
|
const cwd = getCwdParam(req, res);
|
|
@@ -14146,7 +14195,7 @@ async function nextItems(req, res) {
|
|
|
14146
14195
|
(repo) => fetchAssignedIssues(cwd, repo),
|
|
14147
14196
|
(a, b) => a.createdAt.localeCompare(b.createdAt)
|
|
14148
14197
|
),
|
|
14149
|
-
fetchPickups(cwd, scope.
|
|
14198
|
+
fetchPickups(cwd, scope.projects, scope)
|
|
14150
14199
|
]);
|
|
14151
14200
|
const body = { scope, peerPrs, assignedIssues, pickups };
|
|
14152
14201
|
respondJson(res, 200, body);
|
|
@@ -14306,16 +14355,16 @@ function setProjectItemStatus(input) {
|
|
|
14306
14355
|
|
|
14307
14356
|
// src/commands/sessions/web/next/pickUpItem.ts
|
|
14308
14357
|
var IN_PROGRESS = "in progress";
|
|
14309
|
-
function pickUpItem(
|
|
14358
|
+
function pickUpItem(target) {
|
|
14310
14359
|
assertProjectScope();
|
|
14311
|
-
const [owner, number] = project.split("/");
|
|
14360
|
+
const [owner, number] = target.project.split("/");
|
|
14312
14361
|
const board = fetchProjectV2(owner, Number(number));
|
|
14313
14362
|
const option = board.statusField?.options.find(
|
|
14314
14363
|
(candidate) => candidate.name.toLowerCase() === IN_PROGRESS
|
|
14315
14364
|
);
|
|
14316
14365
|
if (!board.statusField || !option)
|
|
14317
14366
|
throw new Error(
|
|
14318
|
-
`Project ${project} (${board.title}) has no In Progress status to move ${target.repo}#${target.number} to`
|
|
14367
|
+
`Project ${target.project} (${board.title}) has no In Progress status to move ${target.repo}#${target.number} to`
|
|
14319
14368
|
);
|
|
14320
14369
|
assignIssueToSelf(target.number, target.repo);
|
|
14321
14370
|
setProjectItemStatus({
|
|
@@ -14328,11 +14377,12 @@ function pickUpItem(project, target) {
|
|
|
14328
14377
|
|
|
14329
14378
|
// src/commands/sessions/web/next/nextPickup.ts
|
|
14330
14379
|
function parseTarget(body) {
|
|
14331
|
-
const { repo, number, itemId: itemId2 } = body ?? {};
|
|
14380
|
+
const { project, repo, number, itemId: itemId2 } = body ?? {};
|
|
14381
|
+
if (typeof project !== "string") return null;
|
|
14332
14382
|
if (typeof repo !== "string" || !repo.includes("/")) return null;
|
|
14333
14383
|
if (typeof number !== "number" || !Number.isInteger(number)) return null;
|
|
14334
14384
|
if (typeof itemId2 !== "string" || !itemId2) return null;
|
|
14335
|
-
return { repo, number, itemId: itemId2 };
|
|
14385
|
+
return { project, repo, number, itemId: itemId2 };
|
|
14336
14386
|
}
|
|
14337
14387
|
async function nextPickup(req, res) {
|
|
14338
14388
|
const cwd = getCwdParam(req, res);
|
|
@@ -14345,16 +14395,17 @@ async function nextPickup(req, res) {
|
|
|
14345
14395
|
return;
|
|
14346
14396
|
}
|
|
14347
14397
|
if (!target) {
|
|
14348
|
-
respondJson(res, 400, { error: "Missing repo, number or itemId" });
|
|
14398
|
+
respondJson(res, 400, { error: "Missing project, repo, number or itemId" });
|
|
14349
14399
|
return;
|
|
14350
14400
|
}
|
|
14351
|
-
|
|
14352
|
-
|
|
14353
|
-
|
|
14401
|
+
if (!nextScope(cwd).projects.includes(target.project)) {
|
|
14402
|
+
respondJson(res, 400, {
|
|
14403
|
+
error: `${target.project} is not in next.projects for this repo`
|
|
14404
|
+
});
|
|
14354
14405
|
return;
|
|
14355
14406
|
}
|
|
14356
14407
|
try {
|
|
14357
|
-
pickUpItem(
|
|
14408
|
+
pickUpItem(target);
|
|
14358
14409
|
respondJson(res, 200, { ok: true });
|
|
14359
14410
|
} catch (error) {
|
|
14360
14411
|
respondJson(res, 500, { error: ghErrorText(error) });
|