@uipath/uipath-extensions-sdk 0.1.21 → 0.1.22
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 +21 -8
- package/dist/adopt.js +3 -24
- package/dist/adopt.js.map +1 -1
- package/dist/cli.js +39 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/new.d.ts +1 -0
- package/dist/commands/new.js +50 -2
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/submit.d.ts +26 -0
- package/dist/commands/submit.js +366 -17
- package/dist/commands/submit.js.map +1 -1
- package/dist/connector.d.ts +23 -0
- package/dist/connector.js +246 -0
- package/dist/connector.js.map +1 -0
- package/dist/github.d.ts +6 -0
- package/dist/github.js +12 -0
- package/dist/github.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +2 -0
- package/dist/lib.js +89 -11
- package/dist/lib.js.map +1 -1
- package/dist/registrationFile.d.ts +10 -0
- package/dist/registrationFile.js +51 -1
- package/dist/registrationFile.js.map +1 -1
- package/dist/symlinkProblem.d.ts +1 -0
- package/dist/symlinkProblem.js +25 -0
- package/dist/symlinkProblem.js.map +1 -0
- package/package.json +5 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Exec, type GateReport } from "@uipath/uipath-extensions-gates";
|
|
2
2
|
import { type GitHubClient, type PullReview } from "../github.js";
|
|
3
|
+
import { type Maintainer } from "../registrationFile.js";
|
|
3
4
|
import { type ValidateOptions, type ValidateResult } from "./validate.js";
|
|
4
5
|
export declare const DEFAULT_INDEX_REPO = "UiPath/uipath-extensions";
|
|
5
6
|
export declare class SubmitError extends Error {
|
|
@@ -30,6 +31,12 @@ export interface SubmitOptions {
|
|
|
30
31
|
value: string;
|
|
31
32
|
}[];
|
|
32
33
|
validate?: (options: ValidateOptions) => Promise<ValidateResult>;
|
|
34
|
+
connectorId?: string;
|
|
35
|
+
bump?: string;
|
|
36
|
+
}
|
|
37
|
+
export type MaintainerSource = "signed-in" | "index";
|
|
38
|
+
export interface PlannedMaintainer extends Maintainer {
|
|
39
|
+
from: MaintainerSource;
|
|
33
40
|
}
|
|
34
41
|
export interface SubmitPlan {
|
|
35
42
|
index: string;
|
|
@@ -47,6 +54,11 @@ export interface SubmitPlan {
|
|
|
47
54
|
checks: GateReport;
|
|
48
55
|
approvedBy: string[];
|
|
49
56
|
warnings: string[];
|
|
57
|
+
securityContact?: string;
|
|
58
|
+
maintainers: PlannedMaintainer[];
|
|
59
|
+
maintainersNote?: string;
|
|
60
|
+
connectorKey?: string;
|
|
61
|
+
rewritten?: string[];
|
|
50
62
|
}
|
|
51
63
|
export interface SubmitResult extends SubmitPlan {
|
|
52
64
|
url: string;
|
|
@@ -61,13 +73,27 @@ export declare function collectFolder(root: string): Promise<{
|
|
|
61
73
|
skipped: string[];
|
|
62
74
|
problems: string[];
|
|
63
75
|
}>;
|
|
76
|
+
export interface ConnectorSourceCheck {
|
|
77
|
+
report: GateReport;
|
|
78
|
+
ok: boolean;
|
|
79
|
+
folderKey?: string;
|
|
80
|
+
key?: string;
|
|
81
|
+
id?: string;
|
|
82
|
+
}
|
|
83
|
+
export declare function validateConnectorSource(projectDir: string, id: string | undefined): Promise<ConnectorSourceCheck>;
|
|
84
|
+
export declare const FIRST_CONNECTOR_VERSION = "1.0.0";
|
|
85
|
+
export declare function approvedVersions(existing: string | undefined): string[];
|
|
86
|
+
export declare function bumpProblem(bump: string | undefined, connector: boolean): string | undefined;
|
|
87
|
+
export declare function nextConnectorVersion(previous: string[], bump: string | undefined): string;
|
|
64
88
|
export declare function registrationText(input: {
|
|
65
89
|
id: string;
|
|
66
90
|
packageId: string;
|
|
67
91
|
version: string;
|
|
68
92
|
date: string;
|
|
69
93
|
securityContact?: string;
|
|
94
|
+
maintainers?: Maintainer[];
|
|
70
95
|
existing?: string;
|
|
96
|
+
higherThanApproved?: boolean;
|
|
71
97
|
}): string;
|
|
72
98
|
export declare function fillTemplate(template: string, fields: {
|
|
73
99
|
id: string;
|
package/dist/commands/submit.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readFile, rm, writeFile, } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { CONNECTOR_ELEMENT, CONNECTOR_KEY, ConnectorError, connectorFacts, connectorIdParts, connectorKeyFor, idOf, isAllowedSourceDir, isAllowedSourcePath, isConnectorProject, isFaultFixture, isLocalOnlySource, loadConnectorTemplate, loadTemplate, MANIFEST_FILE, packageNameProblem, readConnectorFiles, SHARED_PUBLISHER, secretFindings, } from "@uipath/uipath-extensions-gates";
|
|
5
|
+
import semver from "semver";
|
|
4
6
|
import { parse, stringify } from "yaml";
|
|
7
|
+
import { connectorPackageId, validateConnector, withConnectorKey, withConnectorVersion, } from "../connector.js";
|
|
5
8
|
import { GitHubError, HeadMovedError, } from "../github.js";
|
|
6
9
|
import { SDK_PACKAGE } from "../manifest.js";
|
|
7
|
-
import { EMAIL, REGISTRATION_FILE, registrationFileCheck, } from "../registrationFile.js";
|
|
10
|
+
import { EMAIL, isMaintainerLogin, maintainerProblems, REGISTRATION_FILE, registrationFileCheck, withoutControls, } from "../registrationFile.js";
|
|
8
11
|
import { excludedNames, isSkippedEntry, offListRemedy, walkSources, } from "../sourceWalk.js";
|
|
9
12
|
import { validate as runValidate, } from "./validate.js";
|
|
10
13
|
export const DEFAULT_INDEX_REPO = "UiPath/uipath-extensions";
|
|
@@ -162,6 +165,174 @@ export async function collectFolder(root) {
|
|
|
162
165
|
}));
|
|
163
166
|
return { files, skipped, problems: reported };
|
|
164
167
|
}
|
|
168
|
+
const CONNECTOR_SKIPPED = [
|
|
169
|
+
"package.json",
|
|
170
|
+
"package-lock.json",
|
|
171
|
+
"app/package.json",
|
|
172
|
+
"node_modules",
|
|
173
|
+
];
|
|
174
|
+
// The gates run on the same bytes that submit sends, so a file edited mid-submit cannot slip past them.
|
|
175
|
+
async function validateSnapshot(files, context = {}) {
|
|
176
|
+
const snapshot = await mkdtemp(join(tmpdir(), "connector-submit-"));
|
|
177
|
+
try {
|
|
178
|
+
for (const file of files) {
|
|
179
|
+
await mkdir(dirname(join(snapshot, file.path)), { recursive: true });
|
|
180
|
+
await writeFile(join(snapshot, file.path), file.content);
|
|
181
|
+
}
|
|
182
|
+
return await validateConnector({ projectDir: snapshot, ...context });
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
await rm(snapshot, { recursive: true, force: true });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function sharedIdOf(folderKey) {
|
|
189
|
+
const name = folderKey.split("-").at(-1) ?? "";
|
|
190
|
+
const id = `${SHARED_PUBLISHER}.${name}`;
|
|
191
|
+
try {
|
|
192
|
+
connectorKeyFor(id);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (!(error instanceof ConnectorError))
|
|
196
|
+
throw error;
|
|
197
|
+
throw new ConnectorError(`the folder key ${JSON.stringify(folderKey.slice(0, 80))} does not end in a name of lowercase letters and digits, so pass the node id as <publisher>.<name>`);
|
|
198
|
+
}
|
|
199
|
+
return id;
|
|
200
|
+
}
|
|
201
|
+
// validate checks what submit would send: the folder's files with the community key of the node id, in a copy.
|
|
202
|
+
export async function validateConnectorSource(projectDir, id) {
|
|
203
|
+
const collected = await collectConnectorFolder(projectDir);
|
|
204
|
+
let folderKey;
|
|
205
|
+
try {
|
|
206
|
+
folderKey = connectorFacts(collected.files).key;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (!(error instanceof ConnectorError))
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
const nodeId = id ??
|
|
213
|
+
(folderKey === undefined || CONNECTOR_KEY.test(folderKey)
|
|
214
|
+
? undefined
|
|
215
|
+
: sharedIdOf(folderKey));
|
|
216
|
+
if (nodeId === undefined) {
|
|
217
|
+
return {
|
|
218
|
+
...withFolderProblems(await validateSnapshot(collected.files), collected.problems),
|
|
219
|
+
...(folderKey !== undefined && { folderKey }),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const keyed = withConnectorKey(collected.files, nodeId);
|
|
223
|
+
return {
|
|
224
|
+
...withFolderProblems(await validateSnapshot(keyed.files, { nodeId }), collected.problems),
|
|
225
|
+
...(folderKey !== undefined && { folderKey }),
|
|
226
|
+
key: keyed.key,
|
|
227
|
+
id: nodeId,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const CONTENTS_GATE = "connector-contents";
|
|
231
|
+
// The copy holds only the files submit would send, so what the folder walk refused is reported here.
|
|
232
|
+
function withFolderProblems(checked, problems) {
|
|
233
|
+
if (problems.length === 0)
|
|
234
|
+
return checked;
|
|
235
|
+
const findings = problems.map((message) => ({
|
|
236
|
+
gate: CONTENTS_GATE,
|
|
237
|
+
severity: "error",
|
|
238
|
+
message,
|
|
239
|
+
}));
|
|
240
|
+
const held = checked.report.results.some((result) => result.id === CONTENTS_GATE);
|
|
241
|
+
const results = held
|
|
242
|
+
? checked.report.results.map((result) => result.id === CONTENTS_GATE
|
|
243
|
+
? {
|
|
244
|
+
...result,
|
|
245
|
+
status: "fail",
|
|
246
|
+
findings: [...result.findings, ...findings],
|
|
247
|
+
}
|
|
248
|
+
: result)
|
|
249
|
+
: [
|
|
250
|
+
...checked.report.results,
|
|
251
|
+
{ id: CONTENTS_GATE, status: "fail", findings },
|
|
252
|
+
];
|
|
253
|
+
return { report: { ...checked.report, results }, ok: false };
|
|
254
|
+
}
|
|
255
|
+
function nodeKindOf(paths) {
|
|
256
|
+
if (paths.includes(CONNECTOR_ELEMENT))
|
|
257
|
+
return "connector";
|
|
258
|
+
if (paths.includes("package.json"))
|
|
259
|
+
return "function";
|
|
260
|
+
if (paths.includes("pyproject.toml"))
|
|
261
|
+
return "agent";
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
async function collectConnectorFolder(root) {
|
|
265
|
+
const { files, problems } = await readConnectorFiles(root);
|
|
266
|
+
const skipped = [];
|
|
267
|
+
const registration = await lstat(join(root, REGISTRATION_FILE)).catch(() => undefined);
|
|
268
|
+
if (registration?.isFile())
|
|
269
|
+
skipped.push(REGISTRATION_FILE);
|
|
270
|
+
for (const path of CONNECTOR_SKIPPED) {
|
|
271
|
+
if (await lstat(join(root, path)).then(() => true, () => false)) {
|
|
272
|
+
skipped.push(path);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (files.length + 1 > MAX_FILES) {
|
|
276
|
+
problems.push(`the folder holds ${files.length} files, and the limit is ${MAX_FILES} with ${REGISTRATION_FILE}`);
|
|
277
|
+
}
|
|
278
|
+
return { files, skipped, problems: problems.slice(0, MAX_REPORTED_PROBLEMS) };
|
|
279
|
+
}
|
|
280
|
+
function connectorIdentity(files, id) {
|
|
281
|
+
try {
|
|
282
|
+
return {
|
|
283
|
+
packageId: connectorPackageId(id),
|
|
284
|
+
version: connectorFacts(files).version,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error instanceof ConnectorError)
|
|
289
|
+
throw new SubmitError(error.message);
|
|
290
|
+
throw error;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const BUMPS = new Set(["patch", "minor", "major"]);
|
|
294
|
+
export const FIRST_CONNECTOR_VERSION = "1.0.0";
|
|
295
|
+
export function approvedVersions(existing) {
|
|
296
|
+
if (existing === undefined)
|
|
297
|
+
return [];
|
|
298
|
+
let data;
|
|
299
|
+
try {
|
|
300
|
+
data = parse(existing);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
throw new SubmitError("the registration file in the index is not YAML");
|
|
304
|
+
}
|
|
305
|
+
const approved = isRecord(data) ? data.approved : undefined;
|
|
306
|
+
return Array.isArray(approved)
|
|
307
|
+
? approved.flatMap((item) => isRecord(item) && typeof item.version === "string"
|
|
308
|
+
? [item.version]
|
|
309
|
+
: [])
|
|
310
|
+
: [];
|
|
311
|
+
}
|
|
312
|
+
export function bumpProblem(bump, connector) {
|
|
313
|
+
if (bump === undefined)
|
|
314
|
+
return undefined;
|
|
315
|
+
if (!BUMPS.has(bump))
|
|
316
|
+
return "--bump must be patch, minor or major";
|
|
317
|
+
if (!connector) {
|
|
318
|
+
return "--bump is for connectors only. A function or agent takes its version from package.json, so set it there and run submit without --bump";
|
|
319
|
+
}
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
// The index holds the version history, so the next version is the highest approved one plus the bump.
|
|
323
|
+
export function nextConnectorVersion(previous, bump) {
|
|
324
|
+
const problem = bumpProblem(bump, true);
|
|
325
|
+
if (problem !== undefined)
|
|
326
|
+
throw new SubmitError(problem);
|
|
327
|
+
const valid = previous.filter((version) => semver.valid(version) === version);
|
|
328
|
+
if (valid.length === 0)
|
|
329
|
+
return FIRST_CONNECTOR_VERSION;
|
|
330
|
+
const highest = semver.rsort([...valid])[0];
|
|
331
|
+
if (bump === undefined) {
|
|
332
|
+
throw new SubmitError(`the index already holds this connector up to ${highest}, so pass --bump patch, minor or major`);
|
|
333
|
+
}
|
|
334
|
+
return semver.inc(highest, bump);
|
|
335
|
+
}
|
|
165
336
|
const SCANNED_ON_SEND = [MANIFEST_FILE, "project.uiproj"];
|
|
166
337
|
function sentSecretProblems(files) {
|
|
167
338
|
return SCANNED_ON_SEND.flatMap((name) => {
|
|
@@ -222,6 +393,8 @@ export function registrationText(input) {
|
|
|
222
393
|
security_contact: securityContact,
|
|
223
394
|
deprecated: null,
|
|
224
395
|
approved: [entry],
|
|
396
|
+
...(input.maintainers &&
|
|
397
|
+
input.maintainers.length > 0 && { maintainers: input.maintainers }),
|
|
225
398
|
}, options);
|
|
226
399
|
}
|
|
227
400
|
let data;
|
|
@@ -244,6 +417,17 @@ export function registrationText(input) {
|
|
|
244
417
|
if (approved.some((item) => isRecord(item) && item.version === version)) {
|
|
245
418
|
throw new SubmitError(`${id} ${version} is already in the registration file of the index. Bump the version, then run submit again.`);
|
|
246
419
|
}
|
|
420
|
+
if (input.higherThanApproved) {
|
|
421
|
+
const notLower = approved.flatMap((item) => isRecord(item) &&
|
|
422
|
+
typeof item.version === "string" &&
|
|
423
|
+
semver.valid(item.version) === item.version &&
|
|
424
|
+
!semver.gt(version, item.version)
|
|
425
|
+
? [item.version]
|
|
426
|
+
: []);
|
|
427
|
+
if (notLower.length > 0) {
|
|
428
|
+
throw new SubmitError(`${id} ${version} is not higher than ${notLower.join(", ")} in the registration file of the index, and a connector version only goes up`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
247
431
|
return stringify({
|
|
248
432
|
...data,
|
|
249
433
|
...(securityContact && { security_contact: securityContact }),
|
|
@@ -277,6 +461,44 @@ function checkInputs(index, securityContact) {
|
|
|
277
461
|
throw new SubmitError("the security contact must be an email address such as security@acme.example");
|
|
278
462
|
}
|
|
279
463
|
}
|
|
464
|
+
async function signedInMaintainer(github) {
|
|
465
|
+
let login;
|
|
466
|
+
let user;
|
|
467
|
+
try {
|
|
468
|
+
login = (await github.currentLogin()).toLowerCase();
|
|
469
|
+
if (!isMaintainerLogin(login)) {
|
|
470
|
+
return {
|
|
471
|
+
reason: `the signed-in account ${login} does not have the login shape of a user`,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
user = await github.user(login);
|
|
475
|
+
}
|
|
476
|
+
catch (error) {
|
|
477
|
+
if (!(error instanceof GitHubError))
|
|
478
|
+
throw error;
|
|
479
|
+
return {
|
|
480
|
+
reason: `GitHub did not say who is signed in (${error.message})`,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
if (!user)
|
|
484
|
+
return { reason: `GitHub has no user ${login}` };
|
|
485
|
+
if (user.type !== "User") {
|
|
486
|
+
return { reason: `the signed-in account ${login} is a ${user.type}` };
|
|
487
|
+
}
|
|
488
|
+
return { maintainer: { login, id: user.id } };
|
|
489
|
+
}
|
|
490
|
+
function registeredMaintainers(existing) {
|
|
491
|
+
try {
|
|
492
|
+
const data = parse(existing);
|
|
493
|
+
const listed = isRecord(data) ? data.maintainers : undefined;
|
|
494
|
+
return listed !== undefined && maintainerProblems(listed).length === 0
|
|
495
|
+
? listed.map((kept) => ({ ...kept, from: "index" }))
|
|
496
|
+
: [];
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
return [];
|
|
500
|
+
}
|
|
501
|
+
}
|
|
280
502
|
const APPROVAL_STATES = new Set(["APPROVED", "CHANGES_REQUESTED", "DISMISSED"]);
|
|
281
503
|
export function approvers(reviews) {
|
|
282
504
|
const latest = new Map();
|
|
@@ -347,6 +569,33 @@ async function checkPull(github, index, { branch, head }, baseSha, failures) {
|
|
|
347
569
|
: [headSha, baseSha],
|
|
348
570
|
};
|
|
349
571
|
}
|
|
572
|
+
async function forkProblems(github, index, target, baseSha) {
|
|
573
|
+
const { publisher, name } = connectorIdParts(target.id);
|
|
574
|
+
if (publisher === SHARED_PUBLISHER)
|
|
575
|
+
return [];
|
|
576
|
+
const shared = `nodes/${SHARED_PUBLISHER}/${name}`;
|
|
577
|
+
const sharedId = `${SHARED_PUBLISHER}/${name}`;
|
|
578
|
+
const registered = await github.fileText(index, `${shared}/${REGISTRATION_FILE}`, baseSha);
|
|
579
|
+
const flat = registered === undefined
|
|
580
|
+
? await github.fileText(index, `${shared}.yaml`, baseSha)
|
|
581
|
+
: undefined;
|
|
582
|
+
if (registered === undefined && flat === undefined) {
|
|
583
|
+
return [
|
|
584
|
+
`${target.id} is a fork, and a fork needs the shared connector ${sharedId} in ${index}. Improve the shared connector with a pull request to ${shared}/, or ask its maintainers to add it first`,
|
|
585
|
+
];
|
|
586
|
+
}
|
|
587
|
+
const kind = registered === undefined
|
|
588
|
+
? undefined
|
|
589
|
+
: nodeKindOf((await github.folderPaths(index, baseSha, shared)) ?? []);
|
|
590
|
+
if (kind === "connector")
|
|
591
|
+
return [];
|
|
592
|
+
const held = kind === undefined
|
|
593
|
+
? `${index} holds ${sharedId} with no connector files`
|
|
594
|
+
: `${sharedId} is a ${kind} node in ${index}`;
|
|
595
|
+
return [
|
|
596
|
+
`${target.id} is a fork, and a fork needs the shared connector ${sharedId}, but ${held}. Use a name that no other node of ${SHARED_PUBLISHER} has`,
|
|
597
|
+
];
|
|
598
|
+
}
|
|
350
599
|
function githubFailure(error) {
|
|
351
600
|
if (!(error instanceof GitHubError))
|
|
352
601
|
throw error;
|
|
@@ -356,11 +605,19 @@ async function prepare(options) {
|
|
|
356
605
|
const { github, securityContact } = options;
|
|
357
606
|
const index = options.index ?? DEFAULT_INDEX_REPO;
|
|
358
607
|
checkInputs(index, securityContact);
|
|
359
|
-
await
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
608
|
+
const connector = await isConnectorProject(options.projectDir);
|
|
609
|
+
const bumped = bumpProblem(options.bump, connector);
|
|
610
|
+
if (bumped !== undefined)
|
|
611
|
+
throw new SubmitError(bumped);
|
|
612
|
+
if (connector) {
|
|
613
|
+
await loadConnectorTemplate(options.projectDir);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
await loadTemplate(options.projectDir);
|
|
617
|
+
}
|
|
618
|
+
const collected = connector
|
|
619
|
+
? await collectConnectorFolder(options.projectDir)
|
|
620
|
+
: undefined;
|
|
364
621
|
const failures = [];
|
|
365
622
|
let indexInfo;
|
|
366
623
|
try {
|
|
@@ -375,11 +632,14 @@ async function prepare(options) {
|
|
|
375
632
|
catch (error) {
|
|
376
633
|
failures.push(githubFailure(error));
|
|
377
634
|
}
|
|
378
|
-
const { files, skipped, problems } = await collectFolder(options.projectDir);
|
|
379
|
-
|
|
635
|
+
const { files: folderFiles, skipped, problems, } = collected ?? (await collectFolder(options.projectDir));
|
|
636
|
+
let files = folderFiles;
|
|
637
|
+
failures.push(...problems, ...sentSecretProblems(files), ...(problems.length === 0 && !connector ? fixtureSendProblems(files) : []));
|
|
380
638
|
let target;
|
|
381
639
|
try {
|
|
382
|
-
target = nodeTarget(
|
|
640
|
+
target = nodeTarget(connector
|
|
641
|
+
? connectorIdentity(files, options.connectorId)
|
|
642
|
+
: readPackageJson(files), index);
|
|
383
643
|
}
|
|
384
644
|
catch (error) {
|
|
385
645
|
if (!(error instanceof SubmitError))
|
|
@@ -404,6 +664,56 @@ async function prepare(options) {
|
|
|
404
664
|
failures.push(githubFailure(error));
|
|
405
665
|
}
|
|
406
666
|
}
|
|
667
|
+
let connectorKey;
|
|
668
|
+
const context = {};
|
|
669
|
+
if (collected && target) {
|
|
670
|
+
try {
|
|
671
|
+
const keyed = withConnectorKey(files, target.id);
|
|
672
|
+
files = keyed.files;
|
|
673
|
+
connectorKey = keyed.key;
|
|
674
|
+
context.nodeId = target.id;
|
|
675
|
+
}
|
|
676
|
+
catch (error) {
|
|
677
|
+
if (!(error instanceof ConnectorError))
|
|
678
|
+
throw error;
|
|
679
|
+
failures.push(error.message);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (collected && indexInfo && target && remote) {
|
|
683
|
+
try {
|
|
684
|
+
const registered = (await github.fileText(index, target.registrationPath, remote.baseSha)) ?? (await github.fileText(index, target.flatPath, remote.baseSha));
|
|
685
|
+
const previous = approvedVersions(registered);
|
|
686
|
+
const version = nextConnectorVersion(previous, options.bump);
|
|
687
|
+
files = withConnectorVersion(files, version);
|
|
688
|
+
target.version = version;
|
|
689
|
+
context.expectedVersion = version;
|
|
690
|
+
context.previousVersions = previous;
|
|
691
|
+
failures.push(...(await forkProblems(github, index, target, remote.baseSha)));
|
|
692
|
+
}
|
|
693
|
+
catch (error) {
|
|
694
|
+
if (error instanceof SubmitError || error instanceof ConnectorError) {
|
|
695
|
+
failures.push(error.message);
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
failures.push(githubFailure(error));
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
const rewritten = collected
|
|
703
|
+
? files.flatMap((file, at) => {
|
|
704
|
+
const before = folderFiles[at]?.content;
|
|
705
|
+
return before !== undefined &&
|
|
706
|
+
Buffer.compare(Buffer.from(before), Buffer.from(file.content)) === 0
|
|
707
|
+
? []
|
|
708
|
+
: [file.path];
|
|
709
|
+
})
|
|
710
|
+
: [];
|
|
711
|
+
const checks = collected
|
|
712
|
+
? await validateSnapshot(files, context)
|
|
713
|
+
: await (options.validate ?? runValidate)({
|
|
714
|
+
projectDir: options.projectDir,
|
|
715
|
+
...(options.exec && { exec: options.exec }),
|
|
716
|
+
});
|
|
407
717
|
if (!checks.ok || failures.length > 0 || !indexInfo || !target || !remote) {
|
|
408
718
|
throw checks.ok
|
|
409
719
|
? new PrepareFailedError(failures)
|
|
@@ -419,6 +729,21 @@ async function prepare(options) {
|
|
|
419
729
|
throw new SubmitError(`${index} holds both ${flatPath} and ${registrationPath}, and a node may have only one. Remove one of them, then run submit again.`);
|
|
420
730
|
}
|
|
421
731
|
const existing = current ?? flat;
|
|
732
|
+
const basePaths = current === undefined
|
|
733
|
+
? []
|
|
734
|
+
: ((await github.folderPaths(index, baseSha, folder)) ?? []);
|
|
735
|
+
const baseKind = nodeKindOf(basePaths);
|
|
736
|
+
const sentKind = nodeKindOf(files.map((file) => file.path));
|
|
737
|
+
if (existing !== undefined &&
|
|
738
|
+
sentKind === "connector" &&
|
|
739
|
+
baseKind !== "connector") {
|
|
740
|
+
throw new SubmitError(`${id} is registered in ${index} as a ${baseKind ?? "function"} node, and a connector cannot take over its registration. Use a new id for the connector.`);
|
|
741
|
+
}
|
|
742
|
+
if (baseKind !== undefined &&
|
|
743
|
+
sentKind !== undefined &&
|
|
744
|
+
baseKind !== sentKind) {
|
|
745
|
+
throw new SubmitError(`${id} is a ${baseKind} node in ${index}, and submit does not change the kind of a node. Use a new id for the ${sentKind}.`);
|
|
746
|
+
}
|
|
422
747
|
if (existing === undefined && securityContact === undefined) {
|
|
423
748
|
throw new SecurityContactRequiredError(id);
|
|
424
749
|
}
|
|
@@ -441,19 +766,31 @@ async function prepare(options) {
|
|
|
441
766
|
body = `${body.trimEnd()}\n\nGate library: ${checks.report.gateLibraryVersion}\n`;
|
|
442
767
|
}
|
|
443
768
|
}
|
|
769
|
+
const signedIn = existing === undefined ? await signedInMaintainer(github) : undefined;
|
|
770
|
+
const maintainers = existing !== undefined
|
|
771
|
+
? registeredMaintainers(existing)
|
|
772
|
+
: signedIn && "maintainer" in signedIn
|
|
773
|
+
? [{ ...signedIn.maintainer, from: "signed-in" }]
|
|
774
|
+
: [];
|
|
444
775
|
const registration = registrationText({
|
|
445
776
|
id,
|
|
446
777
|
packageId,
|
|
447
778
|
version,
|
|
448
779
|
date: (options.now?.() ?? new Date()).toISOString().slice(0, 10),
|
|
449
780
|
...(securityContact && { securityContact }),
|
|
781
|
+
...(existing === undefined && {
|
|
782
|
+
maintainers: maintainers.map(({ login, id }) => ({ login, id })),
|
|
783
|
+
}),
|
|
450
784
|
...(existing !== undefined && { existing }),
|
|
785
|
+
...(connector && { higherThanApproved: true }),
|
|
451
786
|
});
|
|
787
|
+
const written = parse(registration);
|
|
788
|
+
const writtenContact = isRecord(written)
|
|
789
|
+
? written.security_contact
|
|
790
|
+
: undefined;
|
|
452
791
|
const sent = new Set(files.map((file) => file.path));
|
|
453
792
|
const notSent = (paths) => paths.filter((path) => path !== REGISTRATION_FILE && !sent.has(path));
|
|
454
|
-
const deleted = notSent(
|
|
455
|
-
? []
|
|
456
|
-
: ((await github.folderPaths(index, baseSha, folder)) ?? []));
|
|
793
|
+
const deleted = notSent(basePaths);
|
|
457
794
|
const droppedFromPull = notSent(headSha === undefined
|
|
458
795
|
? []
|
|
459
796
|
: ((await github.folderPaths(index, headSha, folder)) ?? []));
|
|
@@ -489,6 +826,15 @@ async function prepare(options) {
|
|
|
489
826
|
checks: checks.report,
|
|
490
827
|
approvedBy: [],
|
|
491
828
|
warnings,
|
|
829
|
+
...(typeof writtenContact === "string" && {
|
|
830
|
+
securityContact: writtenContact,
|
|
831
|
+
}),
|
|
832
|
+
maintainers,
|
|
833
|
+
...(connectorKey !== undefined && { connectorKey, rewritten }),
|
|
834
|
+
...(signedIn &&
|
|
835
|
+
"reason" in signedIn && {
|
|
836
|
+
maintainersNote: `no maintainers were written, because ${withoutControls(signedIn.reason)}`,
|
|
837
|
+
}),
|
|
492
838
|
base,
|
|
493
839
|
baseSha,
|
|
494
840
|
head,
|
|
@@ -510,6 +856,9 @@ export async function submit(options) {
|
|
|
510
856
|
}
|
|
511
857
|
: plan;
|
|
512
858
|
}
|
|
859
|
+
const writeWarnings = plan.maintainersNote
|
|
860
|
+
? [...plan.warnings, plan.maintainersNote]
|
|
861
|
+
: [...plan.warnings];
|
|
513
862
|
if (!pull) {
|
|
514
863
|
await github.pushTree({
|
|
515
864
|
repo: index,
|
|
@@ -534,7 +883,7 @@ export async function submit(options) {
|
|
|
534
883
|
throw new SubmitError(`the branch ${branch} was pushed to ${index}, but opening the pull request failed: ${error.message}. GitHub may still have created the pull request. Check ${index} for an open pull request from ${branch}. If there is one, run submit again to update it. If there is none, delete the branch (gh api -X DELETE repos/${index}/git/refs/heads/${branch}), because submit refuses a branch that has no pull request, then run submit again.`, { cause: error });
|
|
535
884
|
}
|
|
536
885
|
const labelled = await github.addLabel(index, created.number, LABEL);
|
|
537
|
-
return { ...plan, url: created.url, labelled };
|
|
886
|
+
return { ...plan, warnings: writeWarnings, url: created.url, labelled };
|
|
538
887
|
}
|
|
539
888
|
try {
|
|
540
889
|
await github.pushTree({
|
|
@@ -553,7 +902,7 @@ export async function submit(options) {
|
|
|
553
902
|
}
|
|
554
903
|
throw error;
|
|
555
904
|
}
|
|
556
|
-
const warnings = [...
|
|
905
|
+
const warnings = [...writeWarnings];
|
|
557
906
|
const current = await github.pullBody(index, pull.number);
|
|
558
907
|
const next = withVersionLine(current, plan.version);
|
|
559
908
|
if (next === undefined) {
|