@mergelight/cli 0.1.16 → 0.1.17
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 +1 -0
- package/dist/cli.js +9 -6
- package/dist/publish/publish.js +11 -3
- package/dist/publish/team-checks.js +21 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ Other ways to name the pull request: `owner/repo#123`, or just `123` inside a cl
|
|
|
62
62
|
| `--keep` | Keep the temporary checkout |
|
|
63
63
|
| `--post` | Post the review to the PR: inline findings, one summary comment and a **Mergelight** check. GitHub only lets Apps write checks, so a personal `gh` login gets the comments and no check. The [GitHub Action](https://github.com/mergelightai/mergelight/blob/main/docs/github-action.md) gets all three |
|
|
64
64
|
| `--dry-run` | With `--post`, `post` or `approve`: print what would be posted and change nothing |
|
|
65
|
+
| `--no-approve` | With `--post` or `post`: never approve the PR, and take back an approval Mergelight gave. Without it, a 🟢 review approves |
|
|
65
66
|
| `--yellow-blocks` | With `--post` or `post`: a 🟡 check waits for an approval and a 🔴 one fails, instead of both being neutral |
|
|
66
67
|
|
|
67
68
|
Two more commands, used by the GitHub Action:
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { declinesOf, fetchContext, MAX_REASON, reportReview } from "./cloud.js";
|
|
|
7
7
|
import { GitHub } from "./publish/api.js";
|
|
8
8
|
import { writeAccess } from "./publish/handled.js";
|
|
9
9
|
import { publishTeamChecks } from "./publish/team-checks.js";
|
|
10
|
-
import { answerRemembered, confirmReasons, approveCheck, checkLimitTitle, checkLoginTitle, failCheck, failSummary, previousFindings, publishReview, startCheck, startSummary, syncApproval, UNREVIEWED } from "./publish/publish.js";
|
|
10
|
+
import { answerRemembered, confirmReasons, approveCheck, checkLimitTitle, checkLoginTitle, failCheck, failSummary, previousFindings, publishReview, startCheck, startSummary, syncApproval, UNREVIEWED, APPROVALS_OFF } from "./publish/publish.js";
|
|
11
11
|
import { LimitError, LoginError, loginFailureMessage } from "./providers/codex.js";
|
|
12
12
|
import { limitNotice, loginNotice } from "./publish/markdown.js";
|
|
13
13
|
import { renderRejected, renderTerminal } from "./render.js";
|
|
@@ -35,6 +35,7 @@ Options
|
|
|
35
35
|
(the check needs a GitHub App, a personal gh login skips it)
|
|
36
36
|
--dry-run With --post, post or approve: print what would be posted, change nothing
|
|
37
37
|
--yellow-blocks With --post or post: a "needs a human" check waits for an approval and a "blocked" one fails
|
|
38
|
+
--no-approve With --post or post: never approve the pull request, and take back an approval Mergelight gave
|
|
38
39
|
--json Print the review as JSON
|
|
39
40
|
--out <file> Also write the JSON review to a file
|
|
40
41
|
--provider <name> Who hunts for problems: codex or claude (default: codex)
|
|
@@ -97,6 +98,7 @@ async function main() {
|
|
|
97
98
|
post: { type: "boolean" },
|
|
98
99
|
"dry-run": { type: "boolean" },
|
|
99
100
|
"yellow-blocks": { type: "boolean" },
|
|
101
|
+
"no-approve": { type: "boolean" },
|
|
100
102
|
json: { type: "boolean" },
|
|
101
103
|
out: { type: "string" },
|
|
102
104
|
model: { type: "string" },
|
|
@@ -171,7 +173,7 @@ async function main() {
|
|
|
171
173
|
}
|
|
172
174
|
if (command === "post") {
|
|
173
175
|
const review = JSON.parse(readFileSync(target, "utf8"));
|
|
174
|
-
const result = await publishReview(review, { dryRun, log, yellowBlocks: values["yellow-blocks"] });
|
|
176
|
+
const result = await publishReview(review, { dryRun, log, yellowBlocks: values["yellow-blocks"], approve: !values["no-approve"] });
|
|
175
177
|
log(`Posted: ${result.inline} inline, ${result.outside} in the summary only, ${result.resolved} resolved. ${result.summaryUrl ?? ""}`);
|
|
176
178
|
return 0;
|
|
177
179
|
}
|
|
@@ -255,11 +257,11 @@ async function main() {
|
|
|
255
257
|
// Reasons given in threads that this review sends to keep: the state holds them until the server confirms.
|
|
256
258
|
// Also when the server couldn't be asked this time, so a waiting reason isn't dropped from the state.
|
|
257
259
|
const remember = cloud.connected || cloud.failed ? (previous ?? []).filter((p) => p.handled?.from === "reply" && p.handled.remember && p.handled.at).map((p) => ({ id: p.id, at: p.handled.at, tries: (p.handled.tries ?? 0) + (cloud.connected ? 1 : 0) })) : [];
|
|
258
|
-
const result = await publishReview(review, { dryRun, log, checkRunId, yellowBlocks: values["yellow-blocks"], teamUnread: cloud.failed === true, startedAt, remember });
|
|
260
|
+
const result = await publishReview(review, { dryRun, log, checkRunId, yellowBlocks: values["yellow-blocks"], approve: !values["no-approve"], teamUnread: cloud.failed === true, startedAt, remember });
|
|
259
261
|
log(`Posted: ${result.inline} inline, ${result.outside} in the summary only, ${result.resolved} resolved. ${result.summaryUrl ?? ""}`);
|
|
260
262
|
if (review.team_checks?.length) {
|
|
261
263
|
checksPosted = true;
|
|
262
|
-
const posted = await publishTeamChecks(api, review.pr.head_sha, review.team_checks, log).catch((e) => (log(`Couldn't post your team's checks: ${e.message}`), 0));
|
|
264
|
+
const posted = await publishTeamChecks(api, review.pr.head_sha, review.team_checks, log, Boolean(values["yellow-blocks"])).catch((e) => (log(`Couldn't post your team's checks: ${e.message}`), 0));
|
|
263
265
|
if (posted)
|
|
264
266
|
log(`Posted ${posted} of your team's check${posted === 1 ? "" : "s"}.`);
|
|
265
267
|
}
|
|
@@ -298,13 +300,14 @@ async function main() {
|
|
|
298
300
|
await failCheck(api, checkRunId, headSha, message, log, title).catch((e) => log(`Couldn't update the check: ${e.message}`));
|
|
299
301
|
await failSummary(api, ref.number, notice).catch((e) => log(`Couldn't update the summary: ${e.message}`));
|
|
300
302
|
// The newest commit wasn't reviewed. An approval Mergelight gave to an earlier commit must not count for this one.
|
|
301
|
-
|
|
303
|
+
// With approvals turned off, none of Mergelight's approvals stands, this commit's included.
|
|
304
|
+
await syncApproval(api, ref.number, "yellow", headSha, log, values["no-approve"] ? { why: APPROVALS_OFF } : { why: UNREVIEWED, otherCommitsOnly: true });
|
|
302
305
|
// Each of the team's checks still gets an answer on GitHub, so a required one says why it holds the merge:
|
|
303
306
|
// the answer it already has, or that it wasn't asked.
|
|
304
307
|
const unasked = cloud.checks.map((c) => ({ id: c.id, name: c.name, text: c.text, outcome: "error", summary: "The review couldn't run, so this check wasn't asked.", problems: [] }));
|
|
305
308
|
const owed = checksPosted ? [] : (answered ?? unasked);
|
|
306
309
|
if (owed.length)
|
|
307
|
-
await publishTeamChecks(api, headSha, owed, log).catch((e) => log(`Couldn't post your team's checks: ${e.message}`));
|
|
310
|
+
await publishTeamChecks(api, headSha, owed, log, Boolean(values["yellow-blocks"])).catch((e) => log(`Couldn't post your team's checks: ${e.message}`));
|
|
308
311
|
}
|
|
309
312
|
return 1;
|
|
310
313
|
}
|
package/dist/publish/publish.js
CHANGED
|
@@ -335,9 +335,15 @@ export async function publishReview(review, opts = {}) {
|
|
|
335
335
|
},
|
|
336
336
|
};
|
|
337
337
|
await writeCheck(api, opts.checkRunId, review.pr.head_sha, check, log);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
if (opts.approve === false) {
|
|
339
|
+
// Turned off: no approval, and none of Mergelight's earlier ones stands next to a review that doesn't give one.
|
|
340
|
+
await syncApproval(api, n, "yellow", review.pr.head_sha, log, { why: APPROVALS_OFF });
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
// A review that isn't green takes the approval back for what it found. Only a green one is held by something else.
|
|
344
|
+
const hold = review.light === "green" ? approvalHold(review, opts.teamUnread) : null;
|
|
345
|
+
await syncApproval(api, n, approvalLight(review, opts.teamUnread), review.pr.head_sha, log, hold ? { why: hold } : {});
|
|
346
|
+
}
|
|
341
347
|
return { summaryUrl, inline: inline.length, outside: outside.length, resolved, light: review.light };
|
|
342
348
|
}
|
|
343
349
|
/**
|
|
@@ -358,6 +364,8 @@ export function approvalHold(review, teamUnread = false) {
|
|
|
358
364
|
export function approvalLight(review, teamUnread = false) {
|
|
359
365
|
return review.light === "green" && approvalHold(review, teamUnread) ? "yellow" : review.light;
|
|
360
366
|
}
|
|
367
|
+
/** What a dismissal says when a team turned Mergelight's approvals off. */
|
|
368
|
+
export const APPROVALS_OFF = "Approvals by Mergelight are turned off for this repository (auto-approve: false).";
|
|
361
369
|
/** What a dismissal says when a review that couldn't run takes Mergelight's earlier approval back. */
|
|
362
370
|
export const UNREVIEWED = "Mergelight couldn't review the newest commit, so its approval of an earlier one no longer stands.";
|
|
363
371
|
export const APPROVAL_MARKER = "<!-- mergelight:approval -->";
|
|
@@ -22,28 +22,37 @@ export function plain(text) {
|
|
|
22
22
|
.trim();
|
|
23
23
|
}
|
|
24
24
|
/** What GitHub shows for one check: its conclusion, a title, and the reasons. */
|
|
25
|
+
/** What a check says below its result when it didn't pass and the team's checks don't hold merges. */
|
|
26
|
+
const WARNING = "This check is neutral, so it doesn't hold the merge. To let Mergelight's checks hold merges, set `yellow-blocks: true` in the workflow.";
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* What GitHub shows for one check: its conclusion, a title, and the reasons.
|
|
29
|
+
*
|
|
30
|
+
* Whether a check that didn't pass can hold a merge is the team's choice, and the same one as for
|
|
31
|
+
* the Mergelight check itself: yellow-blocks in the workflow. Off, a failed check, one that
|
|
32
|
+
* couldn't tell and one that couldn't run all end neutral, which GitHub lets through, and the title
|
|
33
|
+
* says what happened. On, a failed check fails, and "couldn't tell" and "couldn't run" ask for a
|
|
34
|
+
* person, which a required check doesn't let through. So where a team lets its checks hold merges,
|
|
35
|
+
* the author of a pull request can't get past one by making its run fail.
|
|
30
36
|
*/
|
|
31
|
-
export function teamCheckBody(r) {
|
|
37
|
+
export function teamCheckBody(r, holds = false) {
|
|
32
38
|
const asked = `**The check:** ${code(r.text)}`;
|
|
33
39
|
if (r.outcome === "skipped")
|
|
34
40
|
return { conclusion: "skipped", output: { title: "Not needed: none of its files changed", summary: `${asked}\n\n${r.summary}` } };
|
|
35
41
|
if (r.outcome === "unsure") {
|
|
36
|
-
|
|
42
|
+
const then = holds ? "This is not a pass. It holds the merge until a run can tell." : `This is not a pass. ${WARNING}`;
|
|
43
|
+
return { conclusion: holds ? "action_required" : "neutral", output: { title: "Couldn't tell: look at this one yourself", summary: `${asked}\n\n${plain(r.summary)}\n\n${then}` } };
|
|
37
44
|
}
|
|
38
45
|
if (r.outcome === "error") {
|
|
39
|
-
|
|
46
|
+
const then = holds ? "This is not a pass. It holds the merge. Run the review again, or push, to try once more." : `This is not a pass. ${WARNING}`;
|
|
47
|
+
return { conclusion: holds ? "action_required" : "neutral", output: { title: "Couldn't run this check", summary: `${asked}\n\n${plain(r.summary)}\n\n${then}` } };
|
|
40
48
|
}
|
|
41
49
|
const problems = r.problems.map((p) => `- ${code(p.line ? `${p.file}:${p.line}` : p.file)} ${plain(p.note)}`);
|
|
50
|
+
const failed = r.outcome === "fail";
|
|
42
51
|
return {
|
|
43
|
-
conclusion:
|
|
52
|
+
conclusion: !failed ? "success" : holds ? "failure" : "neutral",
|
|
44
53
|
output: {
|
|
45
|
-
title:
|
|
46
|
-
summary: [asked, "", plain(r.summary), ...(problems.length ? ["", ...problems] : [])].join("\n").slice(0, 60_000),
|
|
54
|
+
title: !failed ? "Passed" : `Failed${r.problems.length ? `: ${r.problems.length} place${r.problems.length === 1 ? "" : "s"} to fix` : ""}`,
|
|
55
|
+
summary: [asked, "", plain(r.summary), ...(problems.length ? ["", ...problems] : []), ...(failed && !holds ? ["", WARNING] : [])].join("\n").slice(0, 60_000),
|
|
47
56
|
},
|
|
48
57
|
};
|
|
49
58
|
}
|
|
@@ -51,11 +60,11 @@ export function teamCheckBody(r) {
|
|
|
51
60
|
* Posts each of the team's checks as a check of its own on the commit. Returns how many were
|
|
52
61
|
* posted. One that can't be posted is logged and doesn't stop the others.
|
|
53
62
|
*/
|
|
54
|
-
export async function publishTeamChecks(api, headSha, results, log = () => { }) {
|
|
63
|
+
export async function publishTeamChecks(api, headSha, results, log = () => { }, holds = false) {
|
|
55
64
|
let posted = 0;
|
|
56
65
|
for (const r of results) {
|
|
57
66
|
try {
|
|
58
|
-
await api.write("POST", "check-runs", { name: teamCheckName(r.name), head_sha: headSha, status: "completed", completed_at: new Date().toISOString(), ...teamCheckBody(r) });
|
|
67
|
+
await api.write("POST", "check-runs", { name: teamCheckName(r.name), head_sha: headSha, status: "completed", completed_at: new Date().toISOString(), ...teamCheckBody(r, holds) });
|
|
59
68
|
posted++;
|
|
60
69
|
}
|
|
61
70
|
catch (err) {
|