@weareikko/code-review 0.9.8 → 0.9.9
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-CgQF5-WG.js → cli-SQpUnA6c.js} +113 -11
- package/dist/cli-SQpUnA6c.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +15 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/github.d.ts +7 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/gitlab.d.ts +6 -0
- package/dist/gitlab.d.ts.map +1 -1
- package/dist/platform.d.ts +5 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platforms/github.d.ts +1 -0
- package/dist/platforms/github.d.ts.map +1 -1
- package/dist/platforms/gitlab.d.ts +1 -0
- package/dist/platforms/gitlab.d.ts.map +1 -1
- package/dist/review.js +1 -1
- package/package.json +1 -1
- package/dist/cli-CgQF5-WG.js.map +0 -1
|
@@ -310,6 +310,25 @@ var GitHubClient = class {
|
|
|
310
310
|
body: JSON.stringify({ body })
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
|
+
/** Add labels to an issue or pull request (`POST /issues/{n}/labels`). */
|
|
314
|
+
async addIssueLabels(owner, repo, issue, labels) {
|
|
315
|
+
await this.request(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${issue}/labels`, {
|
|
316
|
+
method: "POST",
|
|
317
|
+
body: JSON.stringify({ labels })
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Remove one label from an issue or pull request. GitHub answers 404 when the
|
|
322
|
+
* label is not on it; that is the desired end state, so it is not an error.
|
|
323
|
+
*/
|
|
324
|
+
async removeIssueLabel(owner, repo, issue, label) {
|
|
325
|
+
try {
|
|
326
|
+
await this.request(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${issue}/labels/${encodeURIComponent(label)}`, { method: "DELETE" });
|
|
327
|
+
} catch (error) {
|
|
328
|
+
if (error instanceof GitHubApiError && error.status === 404) return;
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
313
332
|
getCurrentUser() {
|
|
314
333
|
return this.request("/user");
|
|
315
334
|
}
|
|
@@ -1751,7 +1770,7 @@ function buildSummaryBody(summary, costFooter, options = {}) {
|
|
|
1751
1770
|
return `${withFooter}\n\n${buildSummaryHistoryBlock(historyEntries)}`;
|
|
1752
1771
|
}
|
|
1753
1772
|
function buildReviewedCommitFooter(commitSha) {
|
|
1754
|
-
return `Reviewed by ${PRODUCT_LINK} v0.9.
|
|
1773
|
+
return `Reviewed by ${PRODUCT_LINK} v0.9.9 for commit ${commitSha}.`;
|
|
1755
1774
|
}
|
|
1756
1775
|
function extractReviewedCommitSha(body) {
|
|
1757
1776
|
return REVIEWED_COMMIT_FOOTER_PATTERN.exec(body)?.[1] ?? null;
|
|
@@ -2095,7 +2114,9 @@ var RESERVED_ENV_SUFFIXES = [
|
|
|
2095
2114
|
"MCP",
|
|
2096
2115
|
"DISABLE_MCP",
|
|
2097
2116
|
"MCP_ENV",
|
|
2098
|
-
"MCP_DISCOVERY"
|
|
2117
|
+
"MCP_DISCOVERY",
|
|
2118
|
+
"LABELS_ON_FINDINGS",
|
|
2119
|
+
"LABELS_ON_CLEAN"
|
|
2099
2120
|
];
|
|
2100
2121
|
var CODE_REVIEW_PREFIX = "CODE_REVIEW_";
|
|
2101
2122
|
var RESERVED_ENV_SUFFIX_SET = new Set(RESERVED_ENV_SUFFIXES);
|
|
@@ -2362,6 +2383,13 @@ function resolveMarketplaces(args, env) {
|
|
|
2362
2383
|
function resolveModelPool(args, env) {
|
|
2363
2384
|
return ((typeof args.modelPool === "string" && args.modelPool.length > 0 ? args.modelPool : env.CODE_REVIEW_MODEL_POOL) ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
2364
2385
|
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Resolve a comma-separated label list from its flag (preferred) or env var.
|
|
2388
|
+
* Entries are trimmed and empty entries dropped; `[]` when unset.
|
|
2389
|
+
*/
|
|
2390
|
+
function resolveLabels(flag, envValue) {
|
|
2391
|
+
return ((typeof flag === "string" && flag.length > 0 ? flag : envValue) ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
2392
|
+
}
|
|
2365
2393
|
function resolveGitLabToken(args, env) {
|
|
2366
2394
|
if (typeof args.gitlabToken === "string" && args.gitlabToken.length > 0) return {
|
|
2367
2395
|
token: args.gitlabToken,
|
|
@@ -2535,7 +2563,9 @@ function resolveConfig(argv = process.argv.slice(2), env = process.env) {
|
|
|
2535
2563
|
mcp: resolveMcp(args, env),
|
|
2536
2564
|
disableMcp: resolveDisableMcp(args, env),
|
|
2537
2565
|
mcpEnv: resolveMcpEnv(args, env),
|
|
2538
|
-
mcpDiscovery: resolveMcpDiscovery(args, env)
|
|
2566
|
+
mcpDiscovery: resolveMcpDiscovery(args, env),
|
|
2567
|
+
labelsOnFindings: resolveLabels(args.labelsOnFindings, env.CODE_REVIEW_LABELS_ON_FINDINGS),
|
|
2568
|
+
labelsOnClean: resolveLabels(args.labelsOnClean, env.CODE_REVIEW_LABELS_ON_CLEAN)
|
|
2539
2569
|
};
|
|
2540
2570
|
}
|
|
2541
2571
|
function validateConfig(config) {
|
|
@@ -2576,6 +2606,9 @@ function validateConfig(config) {
|
|
|
2576
2606
|
if (!REVIEW_DEPTHS.includes(config.reviewDepth)) throw new ConfigError(`--review-depth must be one of: ${REVIEW_DEPTHS.join(", ")}`);
|
|
2577
2607
|
if (config.inputMode !== void 0 && !REVIEW_INPUT_MODES.includes(config.inputMode)) throw new ConfigError(`--input-mode must be one of: ${REVIEW_INPUT_MODES.join(", ")}`);
|
|
2578
2608
|
if (!POSTING_MODES.includes(config.postingMode)) throw new ConfigError(`--posting-mode must be one of: ${POSTING_MODES.join(", ")}`);
|
|
2609
|
+
const clean = new Set(config.labelsOnClean ?? []);
|
|
2610
|
+
const overlap = (config.labelsOnFindings ?? []).filter((label) => clean.has(label));
|
|
2611
|
+
if (overlap.length > 0) throw new ConfigError(`--labels-on-findings and --labels-on-clean share label(s): ${overlap.join(", ")}.`, { hint: "Each review outcome adds its own labels and removes the other set, so a label cannot belong to both." });
|
|
2579
2612
|
}
|
|
2580
2613
|
//#endregion
|
|
2581
2614
|
//#region src/diagnostics.ts
|
|
@@ -3329,7 +3362,7 @@ async function connectOne(config, options) {
|
|
|
3329
3362
|
};
|
|
3330
3363
|
const client = new Client({
|
|
3331
3364
|
name: PRODUCT_NAME,
|
|
3332
|
-
version: "0.9.
|
|
3365
|
+
version: "0.9.9"
|
|
3333
3366
|
});
|
|
3334
3367
|
try {
|
|
3335
3368
|
await withMcpTrace(runId, "mcp.connect", config.name, () => client.connect(options.createTransport(config), { timeout: MCP_CONNECT_TIMEOUT_MS }));
|
|
@@ -7002,7 +7035,7 @@ async function loadDefaultRuntime() {
|
|
|
7002
7035
|
const [sdkNode, resources, semconv] = modules;
|
|
7003
7036
|
const serviceResource = resources.resourceFromAttributes({
|
|
7004
7037
|
[semconv.ATTR_SERVICE_NAME ?? "service.name"]: SERVICE_NAME,
|
|
7005
|
-
[semconv.ATTR_SERVICE_VERSION ?? "service.version"]: "0.9.
|
|
7038
|
+
[semconv.ATTR_SERVICE_VERSION ?? "service.version"]: "0.9.9"
|
|
7006
7039
|
});
|
|
7007
7040
|
applyOtelExporterDefaults(process.env);
|
|
7008
7041
|
const sdk = new sdkNode.NodeSDK({ resource: resources.defaultResource().merge(serviceResource) });
|
|
@@ -7248,6 +7281,7 @@ var NUMERIC_RESULT_ATTRIBUTES = [
|
|
|
7248
7281
|
];
|
|
7249
7282
|
var STRING_RESULT_ATTRIBUTES = [
|
|
7250
7283
|
["summaryAction", "code_review.summary.action"],
|
|
7284
|
+
["labelsOutcome", "code_review.labels.outcome"],
|
|
7251
7285
|
["httpRequestMethod", "http.request.method"],
|
|
7252
7286
|
["httpUrl", "url.full"],
|
|
7253
7287
|
["serverAddress", "server.address"]
|
|
@@ -7514,7 +7548,7 @@ function boldCommentTitle(body) {
|
|
|
7514
7548
|
*/
|
|
7515
7549
|
function buildCommentBody(body, commitSha, confidence) {
|
|
7516
7550
|
const confidenceLine = `_Confidence: ${confidence}._`;
|
|
7517
|
-
const footer = `<sub>Reviewed by ${PRODUCT_LINK} v0.9.
|
|
7551
|
+
const footer = `<sub>Reviewed by ${PRODUCT_LINK} v0.9.9 for commit ${commitSha}.</sub>`;
|
|
7518
7552
|
return `${boldCommentTitle(body.trim())}\n\n${confidenceLine}\n\n---\n\n${footer}`;
|
|
7519
7553
|
}
|
|
7520
7554
|
function buildPayload(comment, body, refs, resolved) {
|
|
@@ -7809,6 +7843,10 @@ var GitHubPlatform = class {
|
|
|
7809
7843
|
return { posted };
|
|
7810
7844
|
}
|
|
7811
7845
|
}
|
|
7846
|
+
async updateLabels(add, remove) {
|
|
7847
|
+
for (const label of remove) await this.client.removeIssueLabel(this.owner, this.repo, this.pull, label);
|
|
7848
|
+
if (add.length > 0) await this.client.addIssueLabels(this.owner, this.repo, this.pull, add);
|
|
7849
|
+
}
|
|
7812
7850
|
async upsertSummary(summary, discussions, options) {
|
|
7813
7851
|
const { body, existing } = buildUpsertSummary(summary, discussions, options);
|
|
7814
7852
|
if (existing) {
|
|
@@ -7985,6 +8023,20 @@ var GitLabClient = class {
|
|
|
7985
8023
|
body: JSON.stringify({ body })
|
|
7986
8024
|
});
|
|
7987
8025
|
}
|
|
8026
|
+
/**
|
|
8027
|
+
* Add and remove MR labels in one `PUT`. GitLab applies `add_labels` and
|
|
8028
|
+
* `remove_labels` against the current set, ignores removing an absent label,
|
|
8029
|
+
* and creates a missing project label on add. An empty list is omitted.
|
|
8030
|
+
*/
|
|
8031
|
+
async updateMergeRequestLabels(project, mr, add, remove) {
|
|
8032
|
+
await this.request(`/projects/${encodeURIComponent(project)}/merge_requests/${encodeURIComponent(mr)}`, {
|
|
8033
|
+
method: "PUT",
|
|
8034
|
+
body: JSON.stringify({
|
|
8035
|
+
...add.length > 0 ? { add_labels: add.join(",") } : {},
|
|
8036
|
+
...remove.length > 0 ? { remove_labels: remove.join(",") } : {}
|
|
8037
|
+
})
|
|
8038
|
+
});
|
|
8039
|
+
}
|
|
7988
8040
|
getCurrentUser() {
|
|
7989
8041
|
return this.request("/user");
|
|
7990
8042
|
}
|
|
@@ -8060,6 +8112,9 @@ var GitLabPlatform = class {
|
|
|
8060
8112
|
postComments(generated, mode) {
|
|
8061
8113
|
return postGeneratedComments(this.client, this.project, this.mr, generated, mode);
|
|
8062
8114
|
}
|
|
8115
|
+
updateLabels(add, remove) {
|
|
8116
|
+
return this.client.updateMergeRequestLabels(this.project, this.mr, add, remove);
|
|
8117
|
+
}
|
|
8063
8118
|
upsertSummary(summary, discussions, options) {
|
|
8064
8119
|
return upsertSummaryNote(this.client, this.project, this.mr, summary, discussions, options);
|
|
8065
8120
|
}
|
|
@@ -8145,7 +8200,7 @@ function gitRepoWebUrl(cloneUrl) {
|
|
|
8145
8200
|
*/
|
|
8146
8201
|
function skillSourceUrl(origin, context = {}) {
|
|
8147
8202
|
switch (origin.kind) {
|
|
8148
|
-
case "builtin": return blobUrl(PRODUCT_URL, "0.9.
|
|
8203
|
+
case "builtin": return blobUrl(PRODUCT_URL, "0.9.9", `skills/${origin.name}/SKILL.md`);
|
|
8149
8204
|
case "project":
|
|
8150
8205
|
if (!context.projectWebUrl || !context.commitSha) return void 0;
|
|
8151
8206
|
return blobUrl(context.projectWebUrl, context.commitSha, `${origin.path}/SKILL.md`);
|
|
@@ -8377,6 +8432,14 @@ Options:
|
|
|
8377
8432
|
(env: CODE_REVIEW_VERIFY_MODEL)
|
|
8378
8433
|
--posting-mode <mode> direct (sequential discussions) or draft (atomic bulk publish)
|
|
8379
8434
|
(default: direct)
|
|
8435
|
+
--labels-on-findings <labels>
|
|
8436
|
+
Comma-separated labels added to the MR/PR when the review posts at
|
|
8437
|
+
least one new comment; the --labels-on-clean set is removed.
|
|
8438
|
+
(env: CODE_REVIEW_LABELS_ON_FINDINGS)
|
|
8439
|
+
--labels-on-clean <labels>
|
|
8440
|
+
Comma-separated labels added to the MR/PR when the review posts no
|
|
8441
|
+
new comment; the --labels-on-findings set is removed.
|
|
8442
|
+
(env: CODE_REVIEW_LABELS_ON_CLEAN)
|
|
8380
8443
|
--review-file <path> Raw code-review output file (default: code-review.md)
|
|
8381
8444
|
--output <path> Generated payload artifact (default: review-comments.json)
|
|
8382
8445
|
--cwd <path> Working directory (default: process.cwd())
|
|
@@ -8558,6 +8621,8 @@ async function run(config, bridges) {
|
|
|
8558
8621
|
if (config.dryRun || config.noPost) {
|
|
8559
8622
|
console.log(`Generated ${generated.length} comments, ${newCount} new. Posting disabled.`);
|
|
8560
8623
|
if (config.postSummary && parsed.summary) console.log("Summary note generated but not posted (posting disabled).");
|
|
8624
|
+
const dryRunLabels = resolveLabelChange(config, newCount > 0);
|
|
8625
|
+
if (dryRunLabels) console.log(`Would set ${dryRunLabels.outcome} labels: ${formatLabelChange(dryRunLabels)} (posting disabled).`);
|
|
8561
8626
|
runContext.posted = 0;
|
|
8562
8627
|
return {
|
|
8563
8628
|
generated,
|
|
@@ -8621,6 +8686,15 @@ async function run(config, bridges) {
|
|
|
8621
8686
|
runContext.posted = posted;
|
|
8622
8687
|
runContext.draftsPublishFailed = draftsPublishFailed;
|
|
8623
8688
|
if (posted > 0) runContext.postedBySeverity = countPostedBySeverity(generated);
|
|
8689
|
+
const labelChange = resolveLabelChange(config, posted > 0);
|
|
8690
|
+
if (labelChange) try {
|
|
8691
|
+
await platform.updateLabels(labelChange.add, labelChange.remove);
|
|
8692
|
+
runContext.labelsOutcome = labelChange.outcome;
|
|
8693
|
+
console.log(`Set ${labelChange.outcome} labels: ${formatLabelChange(labelChange)}.`);
|
|
8694
|
+
} catch (error) {
|
|
8695
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
8696
|
+
console.warn(`[code-review] Could not set ${labelChange.outcome} labels (${formatLabelChange(labelChange)}) — not failing the review. (${detail})`);
|
|
8697
|
+
}
|
|
8624
8698
|
return {
|
|
8625
8699
|
generated,
|
|
8626
8700
|
posted,
|
|
@@ -8629,6 +8703,34 @@ async function run(config, bridges) {
|
|
|
8629
8703
|
};
|
|
8630
8704
|
});
|
|
8631
8705
|
}
|
|
8706
|
+
/**
|
|
8707
|
+
* Pick the label change for a review outcome: `findings` when the review
|
|
8708
|
+
* published at least one fresh comment, `clean` otherwise. The outcome's labels
|
|
8709
|
+
* are added and the other outcome's labels removed, since GitLab CE does not
|
|
8710
|
+
* enforce scoped-label exclusivity. Returns `null` when neither label set is
|
|
8711
|
+
* configured, so the feature makes no API call unless opted in.
|
|
8712
|
+
*/
|
|
8713
|
+
function resolveLabelChange(config, hasFreshComments) {
|
|
8714
|
+
const onFindings = config.labelsOnFindings ?? [];
|
|
8715
|
+
const onClean = config.labelsOnClean ?? [];
|
|
8716
|
+
if (onFindings.length === 0 && onClean.length === 0) return null;
|
|
8717
|
+
return hasFreshComments ? {
|
|
8718
|
+
outcome: "findings",
|
|
8719
|
+
add: onFindings,
|
|
8720
|
+
remove: onClean
|
|
8721
|
+
} : {
|
|
8722
|
+
outcome: "clean",
|
|
8723
|
+
add: onClean,
|
|
8724
|
+
remove: onFindings
|
|
8725
|
+
};
|
|
8726
|
+
}
|
|
8727
|
+
/** Render a label change for logs, e.g. `add [mr::needs-review]; remove [mr::change-requested]`. */
|
|
8728
|
+
function formatLabelChange(change) {
|
|
8729
|
+
const parts = [];
|
|
8730
|
+
if (change.add.length > 0) parts.push(`add [${change.add.join(", ")}]`);
|
|
8731
|
+
if (change.remove.length > 0) parts.push(`remove [${change.remove.join(", ")}]`);
|
|
8732
|
+
return parts.join("; ");
|
|
8733
|
+
}
|
|
8632
8734
|
function zeroReviewUsage(model, thinkingLevel) {
|
|
8633
8735
|
return {
|
|
8634
8736
|
model,
|
|
@@ -8766,10 +8868,10 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
8766
8868
|
return;
|
|
8767
8869
|
}
|
|
8768
8870
|
if (argv.includes("--version") || argv.includes("-v")) {
|
|
8769
|
-
console.log("0.9.
|
|
8871
|
+
console.log("0.9.9");
|
|
8770
8872
|
return;
|
|
8771
8873
|
}
|
|
8772
|
-
process.stderr.write(`[code-review] @weareikko/code-review v0.9.
|
|
8874
|
+
process.stderr.write(`[code-review] @weareikko/code-review v0.9.9\n`);
|
|
8773
8875
|
assertNodeVersion();
|
|
8774
8876
|
applyCodeReviewEnvPrefix();
|
|
8775
8877
|
applyDefaultCacheRetention();
|
|
@@ -8790,6 +8892,6 @@ if (isDirectRun()) main().catch((error) => {
|
|
|
8790
8892
|
process.exitCode = 1;
|
|
8791
8893
|
});
|
|
8792
8894
|
//#endregion
|
|
8793
|
-
export {
|
|
8895
|
+
export { buildSummaryHistoryEntries as $, connectMcpServers as A, traceMcpDiagnostic as B, findSkillForPath as C, readToolPath as D, formatSkillUsageState as E, createDiagnosticRunId as F, SUMMARY_HISTORY_ENTRY_START as G, toGitLabReviewSeverity as H, diagnosticChannels as I, SUMMARY_MARKER as J, SUMMARY_HISTORY_LIMIT as K, mcpDiagnosticChannels as L, DIAGNOSTIC_CHANNEL_PREFIX as M, MCP_DIAGNOSTIC_CHANNEL_NAMES as N, parseReviewMarkdown as O, createDiagnosticContext as P, buildSummaryBody as Q, traceDiagnostic as R, createSkillReadCounter as S, formatReviewUsageSummary as T, SUMMARY_HISTORY_END as U, normalizeSeverity as V, SUMMARY_HISTORY_ENTRY_END as W, buildReviewedCommitFooter as X, buildArchivedSummaryEntry as Y, buildSizeNoticeBlock as Z, buildPayload as _, resolveNpmSkillDir as _t, formatSkillsFooter as a, stripSummaryHistory as at, filterDiff as b, resolveLabelChange as c, appendFingerprintMarkers as ct, blobUrl as d, fingerprints as dt, extractReviewedCommitSha as et, formatSkillLink as f, normalizeBody as ft, buildGeneratedComments as g, parseSkillSpec as gt, skillSourceUrl as h, loadNamedSkill as ht, formatPerModelUsage as i, findExistingSummaryNoteId as it, DIAGNOSTIC_CHANNEL_NAMES as j, parseReviewMarkdownWithWarnings as k, run as l, extractDiffHunkContext as lt, skillDisplayName as m, gitSkillCacheKey as mt, formatLabelChange as n, findExistingReviewedCommitSha as nt, formatUsageLine as o, stripSummaryMarker as ot, gitRepoWebUrl as p, sha256 as pt, SUMMARY_HISTORY_START as q, formatMcpFooter as r, findExistingSummaryNote as rt, main as s, upsertSummaryNote as st, countPostedBySeverity as t, extractSummaryHistoryEntries as tt, withHttpStamping as u, extractExistingFingerprints as ut, isOtelEnabled as v, resolveSkillCacheDir as vt, formatMcpUsageState as w, runReview as x, startOtelBridge as y, traceDiagnosticPhase as z };
|
|
8794
8896
|
|
|
8795
|
-
//# sourceMappingURL=cli-
|
|
8897
|
+
//# sourceMappingURL=cli-SQpUnA6c.js.map
|