agent-dealer 1.3.5 → 1.4.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.
|
@@ -346,7 +346,11 @@ export function parseWorkflowRunInfo(raw) {
|
|
|
346
346
|
return { databaseId: row.databaseId, headSha: row.headSha, conclusion, status };
|
|
347
347
|
}
|
|
348
348
|
const NO_COMMITS_PATTERN = /no commits between/i;
|
|
349
|
-
const defaultExec = (args, opts) => run("gh", args, {
|
|
349
|
+
const defaultExec = (args, opts) => run("gh", args, {
|
|
350
|
+
cwd: opts.cwd,
|
|
351
|
+
maxBuffer: opts.maxBuffer,
|
|
352
|
+
...(opts.env ? { env: { ...process.env, ...opts.env } } : {}),
|
|
353
|
+
});
|
|
350
354
|
async function ghPrView(exec, cwd, fields, selector) {
|
|
351
355
|
const args = ["pr", "view", ...(selector != null ? [selector] : []), "--json", fields];
|
|
352
356
|
try {
|
|
@@ -628,11 +632,22 @@ const REVIEW_FLAG = {
|
|
|
628
632
|
};
|
|
629
633
|
/** GitHub's self-review rejection, worded per event ("approve" / "request changes"). */
|
|
630
634
|
const OWN_PR_REVIEW_PATTERN = /own pull request/i;
|
|
635
|
+
/**
|
|
636
|
+
* Optional separate GitHub identity for review submission only. Repos that require an
|
|
637
|
+
* approval from someone other than the PR author reject the operator's own `--approve`;
|
|
638
|
+
* a second account's token lets the approval count. Set it in `~/.agent-dealer/.env`
|
|
639
|
+
* (loaded at startup, so a change needs a restart); unset keeps every `gh` call on the
|
|
640
|
+
* operator's ambient login.
|
|
641
|
+
*/
|
|
642
|
+
function reviewerExecOpts(cwd) {
|
|
643
|
+
const token = process.env.AGENT_DEALER_REVIEWER_GH_TOKEN;
|
|
644
|
+
return token ? { cwd, env: { GH_TOKEN: token } } : { cwd };
|
|
645
|
+
}
|
|
631
646
|
async function runReview(exec, cwd, number, event, bodyFilePath) {
|
|
632
647
|
try {
|
|
633
648
|
// The PR is targeted explicitly by number — the reviewer's worktree is a detached-HEAD
|
|
634
649
|
// checkout with no current branch for a bare `gh pr review` to resolve against.
|
|
635
|
-
await exec(["pr", "review", String(number), REVIEW_FLAG[event], "--body-file", bodyFilePath],
|
|
650
|
+
await exec(["pr", "review", String(number), REVIEW_FLAG[event], "--body-file", bodyFilePath], reviewerExecOpts(cwd));
|
|
636
651
|
return { ok: true };
|
|
637
652
|
}
|
|
638
653
|
catch (err) {
|
|
@@ -902,3 +902,46 @@ test("NOT-384: downloadRunArtifact downloads one named artifact into the dest di
|
|
|
902
902
|
destDir: "/store/ui-diff",
|
|
903
903
|
}), /gh run download failed/);
|
|
904
904
|
});
|
|
905
|
+
async function withReviewerToken(value, fn) {
|
|
906
|
+
const prev = process.env.AGENT_DEALER_REVIEWER_GH_TOKEN;
|
|
907
|
+
if (value === undefined)
|
|
908
|
+
delete process.env.AGENT_DEALER_REVIEWER_GH_TOKEN;
|
|
909
|
+
else
|
|
910
|
+
process.env.AGENT_DEALER_REVIEWER_GH_TOKEN = value;
|
|
911
|
+
try {
|
|
912
|
+
return await fn();
|
|
913
|
+
}
|
|
914
|
+
finally {
|
|
915
|
+
if (prev === undefined)
|
|
916
|
+
delete process.env.AGENT_DEALER_REVIEWER_GH_TOKEN;
|
|
917
|
+
else
|
|
918
|
+
process.env.AGENT_DEALER_REVIEWER_GH_TOKEN = prev;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
test("AGENT_DEALER_REVIEWER_GH_TOKEN: publishReview runs `gh pr review` as that identity via GH_TOKEN", async () => {
|
|
922
|
+
const { exec, calls, execOpts } = queuedExec([{ stdout: "" }]);
|
|
923
|
+
const result = await withReviewerToken("tok-123", () => createGithubAdapter(exec).publishReview({ cwd: "/repo", number: 7, event: "APPROVE", bodyFilePath: "/tmp/body.md" }));
|
|
924
|
+
assert.deepEqual(result, { ok: true, event: "APPROVE", usedCommentFallback: false });
|
|
925
|
+
assert.deepEqual(calls, [["pr", "review", "7", "--approve", "--body-file", "/tmp/body.md"]]);
|
|
926
|
+
assert.deepEqual(execOpts, [{ cwd: "/repo", env: { GH_TOKEN: "tok-123" } }]);
|
|
927
|
+
});
|
|
928
|
+
test("AGENT_DEALER_REVIEWER_GH_TOKEN: unset or empty keeps the ambient login and the own-PR comment fallback", async () => {
|
|
929
|
+
for (const value of [undefined, ""]) {
|
|
930
|
+
const { exec, calls, execOpts } = queuedExec([
|
|
931
|
+
{ error: "failed to create review: Can not approve your own pull request" },
|
|
932
|
+
{ stdout: "" },
|
|
933
|
+
]);
|
|
934
|
+
const result = await withReviewerToken(value, () => createGithubAdapter(exec).publishReview({ cwd: "/repo", number: 7, event: "APPROVE", bodyFilePath: "/tmp/body.md" }));
|
|
935
|
+
assert.deepEqual(result, { ok: true, event: "COMMENT", usedCommentFallback: true });
|
|
936
|
+
assert.deepEqual(calls.map((c) => c[3]), ["--approve", "--comment"]);
|
|
937
|
+
assert.deepEqual(execOpts, [{ cwd: "/repo" }, { cwd: "/repo" }]);
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
test("AGENT_DEALER_REVIEWER_GH_TOKEN: non-review gh calls never receive the reviewer token", async () => {
|
|
941
|
+
const { exec, execOpts } = queuedExec([
|
|
942
|
+
{ stdout: JSON.stringify({ number: 5, url: "u", baseRefName: "main", headRefName: "issue-x", headRefOid: "abc", isDraft: true }) },
|
|
943
|
+
]);
|
|
944
|
+
await withReviewerToken("tok-123", () => createGithubAdapter(exec).viewPr({ cwd: "/repo", branch: "issue-x" }));
|
|
945
|
+
assert.equal(execOpts.length, 1);
|
|
946
|
+
assert.equal(execOpts[0].env, undefined);
|
|
947
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-dealer/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "AGENT_DEALER_SKIP_GITHUB_HEALTH=1 AGENT_DEALER_SKIP_AGENT_HEALTH=1 npm run build -w @agent-dealer/shared && AGENT_DEALER_SKIP_GITHUB_HEALTH=1 AGENT_DEALER_SKIP_AGENT_HEALTH=1 node ../../scripts/run-workspace-tests.mjs"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@agent-dealer/shared": "1.
|
|
26
|
+
"@agent-dealer/shared": "1.4.0",
|
|
27
27
|
"@fastify/cors": "^11.0.1",
|
|
28
28
|
"@fastify/static": "^8.2.0",
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.29.0",
|