@bakers-build/addon-forge 0.11.1-next.8 → 0.11.1-next.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/src/backend.d.ts +12 -0
- package/dist/src/backend.js +1 -0
- package/dist/src/tool-definitions.js +4 -0
- package/dist/src/tools.js +62 -0
- package/package.json +4 -4
package/dist/src/backend.d.ts
CHANGED
|
@@ -78,12 +78,24 @@ export interface ForgeBackend {
|
|
|
78
78
|
add?: string;
|
|
79
79
|
remove: readonly string[];
|
|
80
80
|
}): Promise<string[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Adds the forge accounts found by these e-mails as reviewers of `pr`;
|
|
83
|
+
* removes none. A mail without an account or refused by the forge is skipped.
|
|
84
|
+
*/
|
|
85
|
+
addReviewers(pr: ForgePr, mails: readonly string[]): Promise<ReviewerResult>;
|
|
81
86
|
/** One write, never retried: a lost answer must not post twice. */
|
|
82
87
|
commentIssue(issueUrl: string, body: string): Promise<{
|
|
83
88
|
id: number;
|
|
84
89
|
url: string;
|
|
85
90
|
}>;
|
|
86
91
|
}
|
|
92
|
+
export interface ReviewerResult {
|
|
93
|
+
readonly requested: string[];
|
|
94
|
+
readonly skipped: {
|
|
95
|
+
mail: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
}[];
|
|
98
|
+
}
|
|
87
99
|
export interface LogTail {
|
|
88
100
|
readonly text: string;
|
|
89
101
|
/** The whole log's size. */
|
package/dist/src/backend.js
CHANGED
|
@@ -41,6 +41,10 @@ export const FORGE_TOOL_DEFINITIONS = {
|
|
|
41
41
|
branch,
|
|
42
42
|
title: { type: 'string' },
|
|
43
43
|
body: { type: 'string' },
|
|
44
|
+
request_reviewers: {
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
description: "set when the ticket asks for its reviewers on the PR/MR: adds the ticket's reviewers, found by their public forge e-mail, and removes none; the result lists requested and skipped reviewers with the reason",
|
|
47
|
+
},
|
|
44
48
|
},
|
|
45
49
|
required: ['title'],
|
|
46
50
|
},
|
package/dist/src/tools.js
CHANGED
|
@@ -44,6 +44,58 @@ async function originOf(req) {
|
|
|
44
44
|
throw new Error(FORGE_NEEDS_ORIGIN);
|
|
45
45
|
return t.issueUrl;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Requests the ticket's reviewers on `pr` by e-mail. Never throws: the PR is
|
|
49
|
+
* already written, so every failure becomes a named skip.
|
|
50
|
+
*/
|
|
51
|
+
async function requestReviewers(req, b, pr) {
|
|
52
|
+
const skipped = [];
|
|
53
|
+
let reviewers;
|
|
54
|
+
try {
|
|
55
|
+
reviewers =
|
|
56
|
+
(req.currentTicket ? await req.currentTicket() : req.ticket)?.reviewers ??
|
|
57
|
+
[];
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return {
|
|
61
|
+
requested: [],
|
|
62
|
+
skipped: [{ reviewer: '*', reason: errorText(err) }],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const byMail = new Map();
|
|
66
|
+
for (const r of reviewers)
|
|
67
|
+
if (r.mail)
|
|
68
|
+
byMail.set(r.mail, r.name);
|
|
69
|
+
else
|
|
70
|
+
skipped.push({ reviewer: r.name, reason: 'e-mail not readable' });
|
|
71
|
+
if (byMail.size === 0)
|
|
72
|
+
return { requested: [], skipped };
|
|
73
|
+
let result;
|
|
74
|
+
try {
|
|
75
|
+
result = await b.addReviewers(pr, [...byMail.keys()]);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
result = {
|
|
79
|
+
requested: [],
|
|
80
|
+
skipped: [...byMail.keys()].map((mail) => ({
|
|
81
|
+
mail,
|
|
82
|
+
reason: errorText(err),
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const name = (mail) => byMail.get(mail) ?? mail;
|
|
87
|
+
return {
|
|
88
|
+
requested: result.requested.map(name),
|
|
89
|
+
skipped: [
|
|
90
|
+
...skipped,
|
|
91
|
+
...result.skipped.map((s) => ({
|
|
92
|
+
reviewer: name(s.mail),
|
|
93
|
+
reason: s.reason,
|
|
94
|
+
})),
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const errorText = (err) => err instanceof Error ? err.message : String(err);
|
|
47
99
|
function ownedBranch(req, run) {
|
|
48
100
|
const branch = req.args.branch ?? run.branchName;
|
|
49
101
|
if (!isOwned(branch, run.branchName))
|
|
@@ -196,6 +248,13 @@ export function forgeTools(deps) {
|
|
|
196
248
|
const run = runOf(req);
|
|
197
249
|
const branch = ownedBranch(req, run);
|
|
198
250
|
const body = req.args.body ?? '';
|
|
251
|
+
// One server read serves the base and the reviewers.
|
|
252
|
+
const read = req.currentTicket;
|
|
253
|
+
if (read) {
|
|
254
|
+
// Lazy: a suffixed branch without the flag never reads the ticket.
|
|
255
|
+
let once;
|
|
256
|
+
req = { ...req, currentTicket: () => (once ??= read()) };
|
|
257
|
+
}
|
|
199
258
|
const base = await currentBase(req, branch, run);
|
|
200
259
|
const b = await backend();
|
|
201
260
|
const open = await b.findOpenPr(branch);
|
|
@@ -212,6 +271,9 @@ export function forgeTools(deps) {
|
|
|
212
271
|
number: pr.number,
|
|
213
272
|
target: pr.base,
|
|
214
273
|
created: !open,
|
|
274
|
+
...(req.args.request_reviewers === true
|
|
275
|
+
? { reviewers: await requestReviewers(req, b, pr) }
|
|
276
|
+
: {}),
|
|
215
277
|
});
|
|
216
278
|
},
|
|
217
279
|
forge_checks: async (req) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-forge",
|
|
3
|
-
"version": "0.11.1-next.
|
|
3
|
+
"version": "0.11.1-next.9",
|
|
4
4
|
"description": "bakers.build forge tools: a sandboxed run fetches, pushes its own branches, opens its PR/MR, reads checks and merges through the conductor, which holds the token. Backends implement the ForgeBackend contract (./backend).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"directory": "bakers-cli/addons/forge"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@bakers-build/conductor": "^0.11.1-next.
|
|
26
|
-
"@bakers-build/core": "^0.11.1-next.
|
|
25
|
+
"@bakers-build/conductor": "^0.11.1-next.9",
|
|
26
|
+
"@bakers-build/core": "^0.11.1-next.9"
|
|
27
27
|
},
|
|
28
28
|
"bakersBuild": {
|
|
29
|
-
"commit": "
|
|
29
|
+
"commit": "4c0c7ffab0be833fb9cbb50b0784a949593f08e6",
|
|
30
30
|
"channel": "next"
|
|
31
31
|
}
|
|
32
32
|
}
|