@theholocron/holocron-plugin-github 5.0.0-alpha.257 → 5.0.0-alpha.259
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/index.mjs +64 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createGitHubClient, createGitHubClient as createGitHubClient$1 } from "
|
|
|
4
4
|
import { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { findRootSync } from "@theholocron/fs-utils";
|
|
7
|
+
import { ProviderApiError as ProviderApiError$1 } from "@theholocron/http-client";
|
|
7
8
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
8
9
|
// src/auth.ts
|
|
9
10
|
const resolveReadToken = createFeatureResolver({
|
|
@@ -497,9 +498,71 @@ async function syncLabels(client, repo, canonical, stale) {
|
|
|
497
498
|
}
|
|
498
499
|
return `${created} created, ${updated} updated, ${deleted} deleted`;
|
|
499
500
|
}
|
|
501
|
+
// src/capabilities/rejected-properties.ts
|
|
502
|
+
/** The values `repo setup` sends for `true_false` properties; anything else is rejected. */
|
|
503
|
+
const BOOLEANS = /* @__PURE__ */ new Set(["true", "false"]);
|
|
504
|
+
/**
|
|
505
|
+
* What is wrong with `values` when compared with the organization's property definitions, one sentence per
|
|
506
|
+
* problem, in the order the properties are given: a property the organization does not define, a value a
|
|
507
|
+
* `single_select` or `multi_select` property does not allow, or a `true_false` property that is not `true` or
|
|
508
|
+
* `false`. A `string` or `url` property has nothing to check here. Empty when every value fits its definition.
|
|
509
|
+
*/
|
|
510
|
+
function rejectedProperties(values, schema) {
|
|
511
|
+
const byName = new Map(schema.map((property) => [property.property_name, property]));
|
|
512
|
+
const problems = [];
|
|
513
|
+
for (const [name, value] of Object.entries(values)) {
|
|
514
|
+
const definition = byName.get(name);
|
|
515
|
+
if (!definition) {
|
|
516
|
+
problems.push(`${name} is not a custom property of the organization`);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
const sent = Array.isArray(value) ? value : [value];
|
|
520
|
+
if (definition.value_type === "true_false") {
|
|
521
|
+
for (const item of sent.filter((item) => !BOOLEANS.has(item))) problems.push(`${name} is "${item}", but it takes only true or false`);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const allowed = definition.allowed_values ?? [];
|
|
525
|
+
if (definition.value_type !== "single_select" && definition.value_type !== "multi_select") continue;
|
|
526
|
+
for (const item of sent.filter((item) => !allowed.includes(item))) problems.push(`${name} has "${item}", which is not one of its allowed values (${allowed.join(", ")})`);
|
|
527
|
+
}
|
|
528
|
+
return problems;
|
|
529
|
+
}
|
|
500
530
|
// src/capabilities/properties.ts
|
|
531
|
+
/** GitHub's own message from a 422 body (`{"message": ..., "errors": [...]}`), or the start of the body when it is not JSON. */
|
|
532
|
+
function githubMessage(details) {
|
|
533
|
+
const raw = String(details ?? "").trim();
|
|
534
|
+
try {
|
|
535
|
+
const body = JSON.parse(raw);
|
|
536
|
+
const errors = Array.isArray(body.errors) ? body.errors.map((e) => JSON.stringify(e)).join(", ") : "";
|
|
537
|
+
const message = typeof body.message === "string" ? body.message : raw;
|
|
538
|
+
return errors ? `${message}: ${errors}` : message;
|
|
539
|
+
} catch {
|
|
540
|
+
return raw.slice(0, 300);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
/** The organization's property definitions, or `undefined` when they cannot be read (permission, an older client). */
|
|
544
|
+
async function orgSchema(client, repo) {
|
|
545
|
+
try {
|
|
546
|
+
return await client.properties.orgSchema(repo.split("/")[0]);
|
|
547
|
+
} catch {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Sets the repo's custom properties. When GitHub answers 422 the error says which value it refused: the values
|
|
553
|
+
* are compared with the organization's property definitions (read-only), and GitHub's own message is added.
|
|
554
|
+
* One refused value fails the whole request, so none of the properties is set.
|
|
555
|
+
*/
|
|
501
556
|
async function syncProperties(client, repo, values) {
|
|
502
|
-
|
|
557
|
+
try {
|
|
558
|
+
await client.properties.setProperties(repo, values);
|
|
559
|
+
} catch (err) {
|
|
560
|
+
if (!(err instanceof ProviderApiError$1) || err.status !== 422) throw err;
|
|
561
|
+
const schema = await orgSchema(client, repo);
|
|
562
|
+
const problems = schema ? rejectedProperties(values, schema) : [];
|
|
563
|
+
const said = githubMessage(err.details);
|
|
564
|
+
throw new Error(`GitHub refused the custom properties (422), so none was set: ${problems.length > 0 ? problems.join("; ") : "no value differs from the organization's definitions, or they could not be read"}. GitHub said: ${said}`, { cause: err });
|
|
565
|
+
}
|
|
503
566
|
return `${Object.keys(values).length} properties set`;
|
|
504
567
|
}
|
|
505
568
|
// src/capabilities/teams.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-github",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.259",
|
|
4
4
|
"description": "Holocron plugin for GitHub. Implements source, ci, secrets, environments, and issues capabilities against the GitHub REST API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -44,21 +44,21 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
46
|
"vitest": "^5.0.5",
|
|
47
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
47
|
+
"@theholocron/cli": "5.0.0-alpha.259",
|
|
48
48
|
"@theholocron/eslint-config": "^8.9.0-alpha.3",
|
|
49
49
|
"@theholocron/fs-utils": "^1.16.1-alpha.1",
|
|
50
|
-
"@theholocron/github-client": "^1.57.1-alpha.
|
|
50
|
+
"@theholocron/github-client": "^1.57.1-alpha.2",
|
|
51
51
|
"@theholocron/misc-utils": "^1.16.1-alpha.1",
|
|
52
|
-
"@theholocron/http-client": "^1.57.1-alpha.1",
|
|
53
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.3",
|
|
54
52
|
"@theholocron/tsconfig": "^8.9.0-alpha.3",
|
|
53
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.3",
|
|
54
|
+
"@theholocron/http-client": "^1.57.1-alpha.2",
|
|
55
55
|
"@theholocron/tsdown-config": "^8.9.0-alpha.3"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@theholocron/fs-utils": "^1.16.0",
|
|
59
59
|
"@theholocron/github-client": "^1.51.0",
|
|
60
60
|
"@theholocron/misc-utils": "^1.16.0",
|
|
61
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
61
|
+
"@theholocron/cli": "5.0.0-alpha.259"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=22"
|