opencode-forgekeeper 5.2.0 → 6.0.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 +12 -11
- package/dist/gui-experimental.cjs +74 -53
- package/dist/index.js +580 -191
- package/dist/tui.js +225 -29
- package/package.json +1 -1
package/dist/tui.js
CHANGED
|
@@ -35,6 +35,14 @@ var exec2 = execWithTimeout(30000);
|
|
|
35
35
|
|
|
36
36
|
// packages/forgekeeper/src/forge.ts
|
|
37
37
|
var FINISHED = new Set(["SUCCESS", "FAILED", "CANCELED", "CANCELLED", "SKIPPED", "MANUAL"]);
|
|
38
|
+
function approversOf(request) {
|
|
39
|
+
if (request.approvers)
|
|
40
|
+
return request.approvers;
|
|
41
|
+
if (request.forge === "gitlab" && request.duoReviewState === "APPROVED") {
|
|
42
|
+
return [{ username: "GitLabDuo", bot: true, automated: true }];
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
38
46
|
var ownedBy = (kind) => (request) => request.forge === kind;
|
|
39
47
|
var titlePrefix = (title) => title?.match(/^\[[^\]]*\]/)?.[0] ?? "";
|
|
40
48
|
function prefixReferences(title, sigil) {
|
|
@@ -61,6 +69,11 @@ function parseWebUrl(kind, value, pattern) {
|
|
|
61
69
|
}
|
|
62
70
|
var yesNo = (value) => value ? "yes" : "no";
|
|
63
71
|
var humanize = (value) => value.toLowerCase().replace(/_/g, " ");
|
|
72
|
+
function awaitingText(reviewers) {
|
|
73
|
+
if (reviewers.length > 2)
|
|
74
|
+
return `awaiting ${reviewers.length} reviewers`;
|
|
75
|
+
return `awaiting ${reviewers.map((username) => `@${username}`).join(", ")}`;
|
|
76
|
+
}
|
|
64
77
|
|
|
65
78
|
class ForgeError extends Error {
|
|
66
79
|
kind;
|
|
@@ -137,10 +150,12 @@ var LIFECYCLE_SYSTEM = [
|
|
|
137
150
|
"the change was detected, as given. Then say in a few sentences what happened, with its",
|
|
138
151
|
"link: for a conflict, that the merge request cannot merge until its conflicts with its",
|
|
139
152
|
"target branch are resolved; for a failed job, which jobs failed in its pipeline, and",
|
|
140
|
-
"whether the pipeline is still running; for
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
"
|
|
153
|
+
"whether the pipeline is still running; for requested changes, that a reviewer asked for",
|
|
154
|
+
"changes; for a merge, that it merged; for an approval, who",
|
|
155
|
+
"approved it; for an outdated issue, which of its fields look wrong. Then list each",
|
|
156
|
+
"<mr-detail> line, keeping what it says Forgekeeper did or proposes. Do not claim anything",
|
|
157
|
+
"the request does not state, do not guess why a job failed, do not propose code changes,",
|
|
158
|
+
"and do not say that you will take any action."
|
|
144
159
|
].join(`
|
|
145
160
|
`);
|
|
146
161
|
var RELAY_SYSTEM = [
|
|
@@ -918,6 +933,55 @@ async function subscribeToNotes(run, directory, request, events, signal, socket
|
|
|
918
933
|
});
|
|
919
934
|
}
|
|
920
935
|
|
|
936
|
+
// packages/forgekeeper/src/adapters/gitlab/approval-status.ts
|
|
937
|
+
function approvalCount(request) {
|
|
938
|
+
const left = request.approvalsLeft ?? 0;
|
|
939
|
+
if (left <= 0 || request.approvalRequirementsSatisfied === true)
|
|
940
|
+
return;
|
|
941
|
+
const given = approversOf(request).filter((approver) => !approver.bot).length;
|
|
942
|
+
return {
|
|
943
|
+
text: given ? `${given} approval${given === 1 ? "" : "s"} \xB7 ${left} more needed` : `${left} approval${left === 1 ? "" : "s"} needed`,
|
|
944
|
+
compact: given ? `${given} \u2713 +${left}` : `+${left}`,
|
|
945
|
+
tone: "muted",
|
|
946
|
+
optional: true
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function waitingOn(request) {
|
|
950
|
+
if (request.awaitingReviewers.length)
|
|
951
|
+
return { text: awaitingText(request.awaitingReviewers), tone: "muted" };
|
|
952
|
+
if (request.draft)
|
|
953
|
+
return;
|
|
954
|
+
const missingRules = request.missingRules ?? [];
|
|
955
|
+
const needsApproval = missingRules.length > 0 || (request.approvalsLeft ?? 0) > 0 || request.mergeStatus === "NOT_APPROVED";
|
|
956
|
+
if (!request.conflicts && request.pipeline?.status !== "FAILED") {
|
|
957
|
+
if (request.mergeTrainIndex != null)
|
|
958
|
+
return { text: `merge train #${request.mergeTrainIndex + 1}`, tone: "muted", optional: true };
|
|
959
|
+
if (request.autoMergeEnabled && (request.approvalRequirementsSatisfied === true || request.mergeStatus === "MERGEABLE" && !needsApproval))
|
|
960
|
+
return { text: "auto-merge set", tone: "success", optional: true };
|
|
961
|
+
}
|
|
962
|
+
if (request.approved || request.approvalRequirementsSatisfied === true)
|
|
963
|
+
return;
|
|
964
|
+
const rule = missingRules.find((rule) => rule.type === "CODE_OWNER" || rule.type === "REGULAR");
|
|
965
|
+
if (rule)
|
|
966
|
+
return {
|
|
967
|
+
text: rule.type === "CODE_OWNER" ? "needs a code owner" : "needs an approver",
|
|
968
|
+
tone: "warning",
|
|
969
|
+
optional: true
|
|
970
|
+
};
|
|
971
|
+
if (request.reviewersComplete && needsApproval)
|
|
972
|
+
return { text: "needs a reviewer", tone: "muted", optional: true };
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
function reviewIndicators(request) {
|
|
976
|
+
const count = approvalCount(request);
|
|
977
|
+
const next = waitingOn(request);
|
|
978
|
+
return [
|
|
979
|
+
...count ? [count] : [],
|
|
980
|
+
...request.approved && !request.awaitingReviewers.length ? [{ text: "approved", tone: "success" }] : [],
|
|
981
|
+
...next ? [next] : []
|
|
982
|
+
];
|
|
983
|
+
}
|
|
984
|
+
|
|
921
985
|
// packages/forgekeeper/src/adapters/gitlab/adapter.ts
|
|
922
986
|
var DISCUSSIONS = "pageInfo { hasNextPage endCursor } nodes { resolvable resolved }";
|
|
923
987
|
var PAGE_SIZE4 = 100;
|
|
@@ -928,8 +992,13 @@ var RECHECKING = new Set(["CHECKING", "UNCHECKED", "PREPARING"]);
|
|
|
928
992
|
var CONFLICT_RECHECK = "CANNOT_BE_MERGED_RECHECK";
|
|
929
993
|
var REVIEWER_FIELDS = (includeApprovedAt) => `pageInfo { hasNextPage endCursor } nodes { id type username bot mergeRequestInteraction { reviewState approved${includeApprovedAt ? " approvedAt" : ""} } }`;
|
|
930
994
|
var APPROVED_BY_FIELDS = "pageInfo { hasNextPage endCursor } nodes { id username bot }";
|
|
931
|
-
var mergeRequestFields = (includeApprovedAt) => `
|
|
995
|
+
var mergeRequestFields = (includeApprovedAt, includeExtendedStatus) => `
|
|
932
996
|
iid title webUrl state draft conflicts approved mergeStatusEnum detailedMergeStatus diffHeadSha updatedAt targetBranch sourceBranch
|
|
997
|
+
autoMergeEnabled
|
|
998
|
+
${includeExtendedStatus ? `
|
|
999
|
+
approvalsRequired approvalsLeft mergeTrainCar { index }
|
|
1000
|
+
approvalState { rules { name type approvalsRequired approved eligibleApprovers { username type bot } } }
|
|
1001
|
+
` : ""}
|
|
933
1002
|
approvedBy(first: ${PAGE_SIZE4}) { ${APPROVED_BY_FIELDS} }
|
|
934
1003
|
sourceProject { fullPath }
|
|
935
1004
|
targetProject { fullPath }
|
|
@@ -941,8 +1010,8 @@ var mergeRequestFields = (includeApprovedAt) => `
|
|
|
941
1010
|
reviewers(first: ${PAGE_SIZE4}) { ${REVIEWER_FIELDS(includeApprovedAt)} }
|
|
942
1011
|
discussions(first: ${PAGE_SIZE4}) { ${DISCUSSIONS} }
|
|
943
1012
|
`;
|
|
944
|
-
function mergeRequestsQuery(projectCount, includeApprovedAt = true) {
|
|
945
|
-
const fields = mergeRequestFields(includeApprovedAt);
|
|
1013
|
+
function mergeRequestsQuery(projectCount, includeApprovedAt = true, includeExtendedStatus = true) {
|
|
1014
|
+
const fields = mergeRequestFields(includeApprovedAt, includeExtendedStatus);
|
|
946
1015
|
const variables = Array.from({ length: projectCount }, (_, index) => `$p${index}: ID!`).join(", ");
|
|
947
1016
|
const projects = Array.from({ length: projectCount }, (_, index) => `p${index}: project(fullPath: $p${index}) {
|
|
948
1017
|
mergeRequests(sourceBranches: [$branch], state: opened, first: 20) { nodes { ${fields} } }
|
|
@@ -952,8 +1021,8 @@ function mergeRequestsQuery(projectCount, includeApprovedAt = true) {
|
|
|
952
1021
|
${projects}
|
|
953
1022
|
}`);
|
|
954
1023
|
}
|
|
955
|
-
function mergeRequestQuery(projectCount, includeApprovedAt = true) {
|
|
956
|
-
const fields = mergeRequestFields(includeApprovedAt);
|
|
1024
|
+
function mergeRequestQuery(projectCount, includeApprovedAt = true, includeExtendedStatus = true) {
|
|
1025
|
+
const fields = mergeRequestFields(includeApprovedAt, includeExtendedStatus);
|
|
957
1026
|
const variables = Array.from({ length: projectCount }, (_, index) => `$p${index}: ID!`).join(", ");
|
|
958
1027
|
const projects = Array.from({ length: projectCount }, (_, index) => `p${index}: project(fullPath: $p${index}) { mergeRequest(iid: $iid) { ${fields} } }`).join(`
|
|
959
1028
|
`);
|
|
@@ -974,6 +1043,21 @@ ${projects}
|
|
|
974
1043
|
var SOURCE_BRANCH_QUERY = query(`query($project: ID!, $iid: String!) {
|
|
975
1044
|
project(fullPath: $project) { mergeRequest(iid: $iid) { sourceBranch } }
|
|
976
1045
|
}`);
|
|
1046
|
+
var ISSUE_QUERY = query(`query($project: ID!, $iid: String!) {
|
|
1047
|
+
project(fullPath: $project) {
|
|
1048
|
+
workItems(iid: $iid, first: 1) {
|
|
1049
|
+
nodes {
|
|
1050
|
+
state
|
|
1051
|
+
widgets {
|
|
1052
|
+
... on WorkItemWidgetStatus { status { name } }
|
|
1053
|
+
... on WorkItemWidgetAssignees { assignees { nodes { username } } }
|
|
1054
|
+
... on WorkItemWidgetLabels { labels { nodes { title } } }
|
|
1055
|
+
... on WorkItemWidgetMilestone { milestone { title } }
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}`);
|
|
977
1061
|
var DISCUSSIONS_QUERY = query(`query($project: ID!, $iid: String!, $after: String) {
|
|
978
1062
|
project(fullPath: $project) {
|
|
979
1063
|
mergeRequest(iid: $iid) { discussions(first: ${PAGE_SIZE4}, after: $after) { ${DISCUSSIONS} } }
|
|
@@ -996,6 +1080,8 @@ var MARK_READY_MUTATION = query(`mutation($project: ID!, $iid: String!) {
|
|
|
996
1080
|
}
|
|
997
1081
|
}`);
|
|
998
1082
|
var unsupportedApprovedAtHosts = new Set;
|
|
1083
|
+
var unsupportedExtendedStatusHosts = new Set;
|
|
1084
|
+
var isMissingExtendedStatus = (error) => /(?:approvalsRequired|approvalsLeft|mergeTrainCar|approvalState).*?(?:doesn't exist|not defined|unknown)|(?:undefinedField|unknown field).*?(?:approvalsRequired|approvalsLeft|mergeTrainCar|approvalState)|Field ['"]index['"] doesn't exist on type ['"]MergeTrainCar['"]/i.test(error instanceof Error ? error.message : String(error));
|
|
999
1085
|
var isMissingApprovedAt = (error) => /approvedAt.*(?:doesn't exist|not defined|unknown)|(?:undefinedField|unknown field).*approvedAt/i.test(error instanceof Error ? error.message : String(error));
|
|
1000
1086
|
function classifyError(message, code) {
|
|
1001
1087
|
const text = message.trim().replace(/^glab:\s*/, "") || `glab exited with code ${code}`;
|
|
@@ -1039,7 +1125,7 @@ var gitlabTraits = {
|
|
|
1039
1125
|
noun: "MR",
|
|
1040
1126
|
ci: "pipeline",
|
|
1041
1127
|
recognizes: (host) => /(^|\.)gitlab\./.test(host),
|
|
1042
|
-
open: (run, directory) => new GitLabForge(glabGraphQL(run, directory), unsupportedApprovedAtHosts),
|
|
1128
|
+
open: (run, directory) => new GitLabForge(glabGraphQL(run, directory), unsupportedApprovedAtHosts, unsupportedExtendedStatusHosts),
|
|
1043
1129
|
owns: ownedBy("gitlab"),
|
|
1044
1130
|
parseUrl: (url) => parseWebUrl("gitlab", url, /^\/(.+)\/-\/merge_requests\/([1-9]\d*)\/?$/),
|
|
1045
1131
|
parseIssueUrl: (url) => parseWebUrl("gitlab", url, /^\/(.+)\/-\/(?:issues|work_items)\/([1-9]\d*)\/?$/),
|
|
@@ -1047,11 +1133,24 @@ var gitlabTraits = {
|
|
|
1047
1133
|
issueReference: (iid) => `#${iid}`,
|
|
1048
1134
|
titleReferences: (title) => prefixReferences(title, "!"),
|
|
1049
1135
|
indicators: () => [],
|
|
1136
|
+
reviewIndicators,
|
|
1050
1137
|
details(request) {
|
|
1051
1138
|
const requirements = request.approvalRequirementsSatisfied === null ? "unknown" : yesNo(request.approvalRequirementsSatisfied);
|
|
1052
1139
|
const lines = [
|
|
1053
1140
|
`Human approvals: ${yesNo(request.hasApprovals)} \xB7 Approval requirements satisfied: ${requirements}`
|
|
1054
1141
|
];
|
|
1142
|
+
const missing = request.approvalRequirementsSatisfied === true ? [] : request.missingRules ?? [];
|
|
1143
|
+
for (const rule of missing.slice(0, 2)) {
|
|
1144
|
+
const others = (rule.eligibleCount ?? rule.eligible.length) - rule.eligible.length;
|
|
1145
|
+
const who = rule.eligibleReviewers.length ? `, @${rule.eligibleReviewers[0]} can approve` : rule.eligible.length ? `, ${request.awaitingReviewers.length ? "ask an eligible approver: " : "ask "}@${rule.eligible.join(", @")}${others > 0 ? ` or ${others} ${others === 1 ? "other" : "others"}` : ""}` : "";
|
|
1146
|
+
lines.push(`Still needed: ${rule.name} (${rule.required} required in total${who})`);
|
|
1147
|
+
}
|
|
1148
|
+
if (missing.length > 2)
|
|
1149
|
+
lines.push(`+${missing.length - 2} more rules`);
|
|
1150
|
+
if (request.autoMergeEnabled)
|
|
1151
|
+
lines.push("Auto-merge: set");
|
|
1152
|
+
if (request.mergeTrainIndex != null)
|
|
1153
|
+
lines.push(`Merge train: position ${request.mergeTrainIndex + 1}`);
|
|
1055
1154
|
if (request.mergeStatus)
|
|
1056
1155
|
lines.push(`Merge status: ${humanize(request.mergeStatus)}`);
|
|
1057
1156
|
return lines;
|
|
@@ -1195,10 +1294,12 @@ function normalizeApprovers(reviewers, approvedBy) {
|
|
|
1195
1294
|
|
|
1196
1295
|
class GitLabForge {
|
|
1197
1296
|
unsupportedApprovedAt;
|
|
1297
|
+
unsupportedExtendedStatus;
|
|
1198
1298
|
traits = gitlabTraits;
|
|
1199
1299
|
graphql;
|
|
1200
|
-
constructor(graphql, unsupportedApprovedAt = new Set) {
|
|
1300
|
+
constructor(graphql, unsupportedApprovedAt = new Set, unsupportedExtendedStatus = new Set) {
|
|
1201
1301
|
this.unsupportedApprovedAt = unsupportedApprovedAt;
|
|
1302
|
+
this.unsupportedExtendedStatus = unsupportedExtendedStatus;
|
|
1202
1303
|
this.graphql = typed(graphql);
|
|
1203
1304
|
}
|
|
1204
1305
|
async queryWithApprovedAt(host, build, variables) {
|
|
@@ -1214,11 +1315,24 @@ class GitLabForge {
|
|
|
1214
1315
|
return this.graphql(host, build(false), variables);
|
|
1215
1316
|
}
|
|
1216
1317
|
}
|
|
1318
|
+
async queryStatus(host, build, variables) {
|
|
1319
|
+
const run = (extended) => this.queryWithApprovedAt(host, (approvedAt) => build(approvedAt, extended), variables);
|
|
1320
|
+
if (this.unsupportedExtendedStatus.has(host))
|
|
1321
|
+
return run(false);
|
|
1322
|
+
try {
|
|
1323
|
+
return await run(true);
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
if (!isMissingExtendedStatus(error))
|
|
1326
|
+
throw error;
|
|
1327
|
+
this.unsupportedExtendedStatus.add(host);
|
|
1328
|
+
return run(false);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1217
1331
|
async findByBranch(repository) {
|
|
1218
1332
|
const { source, targets, sourceBranch } = repository;
|
|
1219
1333
|
const variables = { branch: sourceBranch };
|
|
1220
1334
|
targets.forEach((target, index) => variables[`p${index}`] = target.path);
|
|
1221
|
-
const data = await this.
|
|
1335
|
+
const data = await this.queryStatus(source.host, (approvedAt, extended) => mergeRequestsQuery(targets.length, approvedAt, extended), variables);
|
|
1222
1336
|
const sourcePath = source.path.toLowerCase();
|
|
1223
1337
|
const seen = new Set;
|
|
1224
1338
|
const nodes = [];
|
|
@@ -1253,6 +1367,26 @@ class GitLabForge {
|
|
|
1253
1367
|
const branch = data.project?.mergeRequest?.sourceBranch;
|
|
1254
1368
|
return typeof branch === "string" && branch ? branch : undefined;
|
|
1255
1369
|
}
|
|
1370
|
+
async issue(ref) {
|
|
1371
|
+
const data = await this.graphql(ref.host, ISSUE_QUERY, {
|
|
1372
|
+
project: ref.project,
|
|
1373
|
+
iid: ref.iid
|
|
1374
|
+
});
|
|
1375
|
+
const node = data.project?.workItems?.nodes[0];
|
|
1376
|
+
if (!node)
|
|
1377
|
+
return;
|
|
1378
|
+
const widgets = node.widgets;
|
|
1379
|
+
const milestone = widgets.find((widget) => widget.milestone)?.milestone?.title;
|
|
1380
|
+
const status = widgets.find((widget) => widget.status)?.status?.name;
|
|
1381
|
+
return {
|
|
1382
|
+
forge: "gitlab",
|
|
1383
|
+
open: node.state === "OPEN",
|
|
1384
|
+
...status ? { status } : {},
|
|
1385
|
+
assignees: widgets.flatMap((widget) => widget.assignees?.nodes ?? []).map((u) => u.username),
|
|
1386
|
+
labels: widgets.flatMap((widget) => widget.labels?.nodes ?? []).map((l) => l.title),
|
|
1387
|
+
...milestone ? { milestone } : {}
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1256
1390
|
async markReady(ref, options) {
|
|
1257
1391
|
await options?.beforeMutate?.();
|
|
1258
1392
|
const data = await this.graphql(ref.host, MARK_READY_MUTATION, {
|
|
@@ -1271,7 +1405,7 @@ class GitLabForge {
|
|
|
1271
1405
|
const host = projects[0].host;
|
|
1272
1406
|
const variables = { iid };
|
|
1273
1407
|
projects.forEach((project, index) => variables[`p${index}`] = project.path);
|
|
1274
|
-
const data = await this.
|
|
1408
|
+
const data = await this.queryStatus(host, (approvedAt, extended) => mergeRequestQuery(projects.length, approvedAt, extended), variables);
|
|
1275
1409
|
for (let index = 0;index < projects.length; index++) {
|
|
1276
1410
|
const node = data[`p${index}`]?.mergeRequest;
|
|
1277
1411
|
if (node)
|
|
@@ -1349,6 +1483,28 @@ class GitLabForge {
|
|
|
1349
1483
|
const pipeline = node.headPipeline;
|
|
1350
1484
|
const hasApprovals = approvedByPage.nodes.some((approver) => approver.bot !== true);
|
|
1351
1485
|
const awaitingReviewers = reviewersPage.nodes.filter((reviewer) => reviewer.bot !== true && reviewer.username && reviewer.mergeRequestInteraction?.approved !== true).map((reviewer) => reviewer.username);
|
|
1486
|
+
const approvers = normalizeApprovers(reviewersPage.nodes, approvedByPage.nodes);
|
|
1487
|
+
const approvedNames = new Set([...approvedByPage.nodes, ...approvers].flatMap(({ username }) => username ? [username.toLowerCase()] : []));
|
|
1488
|
+
const missingRules = (node.approvalState?.rules ?? []).flatMap((rule) => {
|
|
1489
|
+
if (rule.approvalsRequired == null || rule.approvalsRequired <= 0 || rule.approved !== false)
|
|
1490
|
+
return [];
|
|
1491
|
+
const eligible = (rule.eligibleApprovers ?? []).filter(({ username, bot }) => !bot && !approvedNames.has(username.toLowerCase()));
|
|
1492
|
+
const eligibleNames = new Set(eligible.map(({ username }) => username.toLowerCase()));
|
|
1493
|
+
const humans = eligible.filter(({ type }) => type === "HUMAN");
|
|
1494
|
+
const humanNames = new Set(humans.map(({ username }) => username.toLowerCase()));
|
|
1495
|
+
const eligibleReviewers = awaitingReviewers.filter((username) => eligibleNames.has(username.toLowerCase())).sort((a, b) => Number(humanNames.has(b.toLowerCase())) - Number(humanNames.has(a.toLowerCase())));
|
|
1496
|
+
const candidates = humans.length ? humans : eligible;
|
|
1497
|
+
return [
|
|
1498
|
+
{
|
|
1499
|
+
name: rule.name ?? "Unnamed approval rule",
|
|
1500
|
+
type: rule.type ?? undefined,
|
|
1501
|
+
required: rule.approvalsRequired,
|
|
1502
|
+
eligibleReviewers,
|
|
1503
|
+
eligible: candidates.slice(0, 2).map(({ username }) => username),
|
|
1504
|
+
eligibleCount: candidates.length
|
|
1505
|
+
}
|
|
1506
|
+
];
|
|
1507
|
+
});
|
|
1352
1508
|
return {
|
|
1353
1509
|
forge: "gitlab",
|
|
1354
1510
|
iid: node.iid,
|
|
@@ -1361,11 +1517,17 @@ class GitLabForge {
|
|
|
1361
1517
|
approved: node.approved === true && hasApprovals && awaitingReviewers.length === 0,
|
|
1362
1518
|
hasApprovals,
|
|
1363
1519
|
approvalRequirementsSatisfied: node.approved,
|
|
1520
|
+
approvalsRequired: node.approvalsRequired ?? undefined,
|
|
1521
|
+
approvalsLeft: node.approvalsLeft ?? undefined,
|
|
1522
|
+
missingRules,
|
|
1523
|
+
autoMergeEnabled: node.autoMergeEnabled,
|
|
1524
|
+
mergeTrainIndex: node.mergeTrainCar?.index,
|
|
1364
1525
|
awaitingReviewers,
|
|
1365
1526
|
reviewersComplete: reviewersPage.complete,
|
|
1527
|
+
changesRequested: reviewersPage.nodes.some((reviewer) => reviewer.mergeRequestInteraction?.reviewState === "REQUESTED_CHANGES") ? true : reviewersPage.complete && reviewersPage.nodes.every((reviewer) => reviewer.mergeRequestInteraction?.reviewState) ? false : undefined,
|
|
1366
1528
|
approvalsComplete: reviewersPage.complete && approvedByPage.complete,
|
|
1367
1529
|
reviewerIDs: reviewersPage.nodes.flatMap((reviewer) => reviewer.id ?? []),
|
|
1368
|
-
approvers
|
|
1530
|
+
approvers,
|
|
1369
1531
|
mergeStatus: node.detailedMergeStatus ?? undefined,
|
|
1370
1532
|
targetProject: node.targetProject.fullPath,
|
|
1371
1533
|
targetBranch: node.targetBranch,
|
|
@@ -1590,7 +1752,7 @@ function copilotReview(node) {
|
|
|
1590
1752
|
function botUsername(login, typename) {
|
|
1591
1753
|
return typename === "Bot" && !login.endsWith("[bot]") ? `${login}[bot]` : login;
|
|
1592
1754
|
}
|
|
1593
|
-
function
|
|
1755
|
+
function pendingReviewer(reviewers) {
|
|
1594
1756
|
const pendingIDs = new Set;
|
|
1595
1757
|
const pendingWithoutID = new Set;
|
|
1596
1758
|
const pendingTypedLogins = new Set;
|
|
@@ -1606,12 +1768,15 @@ function normalizeApprovers2(node, reviewers, opinionated) {
|
|
|
1606
1768
|
pendingWithoutID.add(key);
|
|
1607
1769
|
}
|
|
1608
1770
|
}
|
|
1609
|
-
|
|
1771
|
+
return (id, typename, login) => {
|
|
1610
1772
|
const key = typedLoginKey(typename, login);
|
|
1611
1773
|
if (id)
|
|
1612
1774
|
return pendingIDs.has(id) || pendingWithoutID.has(key);
|
|
1613
1775
|
return pendingTypedLogins.has(key);
|
|
1614
1776
|
};
|
|
1777
|
+
}
|
|
1778
|
+
function normalizeApprovers2(node, reviewers, opinionated) {
|
|
1779
|
+
const isPending = pendingReviewer(reviewers);
|
|
1615
1780
|
const found = new Map;
|
|
1616
1781
|
const add = (entry) => {
|
|
1617
1782
|
const key = `${entry.bot ? "bot" : "user"}:${entry.username.toLowerCase()}`;
|
|
@@ -1659,6 +1824,27 @@ function normalizeApprovers2(node, reviewers, opinionated) {
|
|
|
1659
1824
|
}
|
|
1660
1825
|
return [...found.values()];
|
|
1661
1826
|
}
|
|
1827
|
+
function changeRequests(reviewers, opinionated) {
|
|
1828
|
+
if (!reviewers.pageInfo || reviewers.pageInfo.hasNextPage)
|
|
1829
|
+
return {};
|
|
1830
|
+
const pending = pendingReviewer(reviewers);
|
|
1831
|
+
const ids = [];
|
|
1832
|
+
let complete = opinionated.complete;
|
|
1833
|
+
for (const review of opinionated.nodes) {
|
|
1834
|
+
if (review?.state !== "CHANGES_REQUESTED")
|
|
1835
|
+
continue;
|
|
1836
|
+
const author = review.author;
|
|
1837
|
+
if (!author?.login || !review.id) {
|
|
1838
|
+
complete = false;
|
|
1839
|
+
continue;
|
|
1840
|
+
}
|
|
1841
|
+
if (!pending(author.id, author.__typename, author.login))
|
|
1842
|
+
ids.push(review.id);
|
|
1843
|
+
}
|
|
1844
|
+
if (ids.length)
|
|
1845
|
+
return { changesRequested: true, changeReviewIDs: ids };
|
|
1846
|
+
return complete ? { changesRequested: false } : {};
|
|
1847
|
+
}
|
|
1662
1848
|
|
|
1663
1849
|
class GitHubForge {
|
|
1664
1850
|
traits = githubTraits;
|
|
@@ -1703,6 +1889,19 @@ class GitHubForge {
|
|
|
1703
1889
|
}`), { owner, repo, number: Number(ref.iid) });
|
|
1704
1890
|
return data.repository?.pullRequest?.headRefName || undefined;
|
|
1705
1891
|
}
|
|
1892
|
+
async issue(ref) {
|
|
1893
|
+
const [owner, repo] = ref.project.split("/");
|
|
1894
|
+
const number = Number(ref.iid);
|
|
1895
|
+
if (!owner || !repo || !Number.isInteger(number) || number < 1)
|
|
1896
|
+
return;
|
|
1897
|
+
const data = await this.graphql(ref.host, query(`query($owner:String!,$repo:String!,$number:Int!) {
|
|
1898
|
+
repository(owner:$owner,name:$repo) { issue(number:$number) { state url } }
|
|
1899
|
+
}`), { owner, repo, number });
|
|
1900
|
+
const node = data.repository?.issue;
|
|
1901
|
+
if (!node || !node.url || node.state !== "OPEN" && node.state !== "CLOSED")
|
|
1902
|
+
return;
|
|
1903
|
+
return { forge: "github", open: node.state === "OPEN", url: node.url };
|
|
1904
|
+
}
|
|
1706
1905
|
async markReady(ref, options) {
|
|
1707
1906
|
const [owner, repo] = ref.project.split("/");
|
|
1708
1907
|
const lookup = await this.graphql(ref.host, query(`query($owner:String!,$repo:String!,$number:Int!) {
|
|
@@ -1860,6 +2059,7 @@ class GitHubForge {
|
|
|
1860
2059
|
conflictsKnown: node.mergeable !== "UNKNOWN",
|
|
1861
2060
|
approved: node.reviewDecision === "APPROVED",
|
|
1862
2061
|
reviewDecision: node.reviewDecision ?? undefined,
|
|
2062
|
+
...changeRequests(reviewers, opinionated),
|
|
1863
2063
|
copilotReview: copilotReview({ ...node, reviewRequests: reviewers }),
|
|
1864
2064
|
awaitingReviewers: reviewers.nodes.flatMap((request) => {
|
|
1865
2065
|
const reviewer = request.requestedReviewer;
|
|
@@ -1934,11 +2134,6 @@ var COMPACT_CI = {
|
|
|
1934
2134
|
error: "CI \u2717",
|
|
1935
2135
|
warning: "CI \u2026"
|
|
1936
2136
|
};
|
|
1937
|
-
function awaitingText(reviewers) {
|
|
1938
|
-
if (reviewers.length > 2)
|
|
1939
|
-
return `awaiting ${reviewers.length} reviewers`;
|
|
1940
|
-
return `awaiting ${reviewers.map((username) => `@${username}`).join(", ")}`;
|
|
1941
|
-
}
|
|
1942
2137
|
function threadsText(request) {
|
|
1943
2138
|
return `${request.unresolvedThreads}${request.threadsComplete ? "" : "+"} unresolved thread${request.unresolvedThreads === 1 && request.threadsComplete ? "" : "s"}`;
|
|
1944
2139
|
}
|
|
@@ -2042,7 +2237,10 @@ function footerSegments(snapshot) {
|
|
|
2042
2237
|
segments.push({ text: "conflicts", tone: "error", essential: true });
|
|
2043
2238
|
if (!request.conflictsKnown)
|
|
2044
2239
|
segments.push({ text: "mergeability unknown", tone: "muted" });
|
|
2045
|
-
|
|
2240
|
+
const reviewIndicators = traitsOf(request).reviewIndicators;
|
|
2241
|
+
if (reviewIndicators)
|
|
2242
|
+
segments.push(...reviewIndicators(request));
|
|
2243
|
+
else if (request.awaitingReviewers.length)
|
|
2046
2244
|
segments.push({ text: awaitingText(request.awaitingReviewers), tone: "muted" });
|
|
2047
2245
|
else if (request.approved)
|
|
2048
2246
|
segments.push({ text: "approved", tone: "success" });
|
|
@@ -2059,6 +2257,9 @@ function responsiveFooterSegments(snapshot, width) {
|
|
|
2059
2257
|
}));
|
|
2060
2258
|
if (segmentsWidth(compact) <= width)
|
|
2061
2259
|
return compact;
|
|
2260
|
+
const trimmed = compact.filter((segment) => !segment.optional);
|
|
2261
|
+
if (segmentsWidth(trimmed) <= width)
|
|
2262
|
+
return trimmed;
|
|
2062
2263
|
const minimal = compact.filter((segment) => segment.essential);
|
|
2063
2264
|
if (segmentsWidth(minimal) <= width)
|
|
2064
2265
|
return minimal;
|
|
@@ -2544,7 +2745,7 @@ function linkOptions(item) {
|
|
|
2544
2745
|
const jobs = item.kind === "ci-failed";
|
|
2545
2746
|
return [
|
|
2546
2747
|
...comments.map((url, index) => ({
|
|
2547
|
-
title: `${jobs ? "Failed job" : "Comment"} ${comments.length > 1 ? `${index + 1} of ${comments.length} ` : ""}(${jobs ? new URL(url).pathname.split("/").filter(Boolean).slice(-2).join("/") : new URL(url).hash || "no anchor"})`,
|
|
2748
|
+
title: item.kind === "issue-outdated" ? "Issue" : `${jobs ? "Failed job" : "Comment"} ${comments.length > 1 ? `${index + 1} of ${comments.length} ` : ""}(${jobs ? new URL(url).pathname.split("/").filter(Boolean).slice(-2).join("/") : new URL(url).hash || "no anchor"})`,
|
|
2548
2749
|
description: url,
|
|
2549
2750
|
value: url
|
|
2550
2751
|
})),
|
|
@@ -2614,11 +2815,6 @@ var tui_default = {
|
|
|
2614
2815
|
client.show(current);
|
|
2615
2816
|
onCleanup(() => client.hide(current));
|
|
2616
2817
|
});
|
|
2617
|
-
createEffect(() => {
|
|
2618
|
-
context.data.location.vcs.sync({
|
|
2619
|
-
directory: place().directory
|
|
2620
|
-
}).catch(() => {});
|
|
2621
|
-
});
|
|
2622
2818
|
const snapshot = createMemo(() => snapshotOf(place()));
|
|
2623
2819
|
const fullWidth = createMemo(() => enabledFor(place().directory) ? segmentsWidth(footerSegments(snapshot())) : 0);
|
|
2624
2820
|
const [availableWidth, setAvailableWidth] = createSignal(0);
|
|
@@ -3353,7 +3549,7 @@ var tui_default = {
|
|
|
3353
3549
|
}
|
|
3354
3550
|
if (requests.length === 0) {
|
|
3355
3551
|
context.ui.toast.show({
|
|
3356
|
-
message: "No PR/MR for this session
|
|
3552
|
+
message: "No PR/MR for this session",
|
|
3357
3553
|
variant: "info"
|
|
3358
3554
|
});
|
|
3359
3555
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-forgekeeper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "OpenCode plugin that tracks each session's GitHub and GitLab issues and PRs/MRs: title prefixes, a PR/MR status footer, and review notifications",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Pedro Pombeiro",
|