@leitwerk-dev/forgejo-repo-change 0.0.0-bootstrap.0 → 0.2.1
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 +123 -1
- package/dist/LICENSE +13 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1392 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +48 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/params.d.ts +48 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/process.d.ts +6 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/profile-bindings.d.ts +14 -0
- package/dist/profile-bindings.d.ts.map +1 -0
- package/package.json +52 -14
- package/src/index.ts +64 -0
- package/src/launcher.ts +342 -0
- package/src/params.ts +114 -0
- package/src/process.ts +760 -0
- package/src/profile-bindings.ts +59 -0
- package/src/routing.test-fixture.ts +14 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Server-owned, non-secret wiring for future launches. @internal */
|
|
2
|
+
export interface ProfileBinding {
|
|
3
|
+
/** @internal */
|
|
4
|
+
woodpeckerProfile: string;
|
|
5
|
+
/** @internal */
|
|
6
|
+
sshCredentialRef: string;
|
|
7
|
+
}
|
|
8
|
+
/** @internal */
|
|
9
|
+
export type ProfileBindings = Readonly<Record<string, Readonly<ProfileBinding>>>;
|
|
10
|
+
|
|
11
|
+
function record(value: unknown, label: string): Record<string, unknown> {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13
|
+
throw new Error(`${label} must be an object`);
|
|
14
|
+
return value as Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
function field(value: unknown, fallback: string, label: string): string {
|
|
17
|
+
if (value === undefined) return fallback;
|
|
18
|
+
if (typeof value !== "string" || !value.trim())
|
|
19
|
+
throw new Error(`${label} must be a non-empty string`);
|
|
20
|
+
return value.trim();
|
|
21
|
+
}
|
|
22
|
+
/** @internal */
|
|
23
|
+
export function parseProfileBindings(raw: unknown): ProfileBindings {
|
|
24
|
+
const config = raw === undefined ? {} : record(raw, "forgejo-repo-change configuration");
|
|
25
|
+
if (config.profile_bindings === undefined) return Object.freeze({});
|
|
26
|
+
const mappings = record(config.profile_bindings, "profile_bindings");
|
|
27
|
+
const entries = Object.entries(mappings).map(([profile, value]) => {
|
|
28
|
+
if (!profile.trim() || profile.trim() !== profile)
|
|
29
|
+
throw new Error(
|
|
30
|
+
"profile_bindings keys must be non-empty profile names without surrounding whitespace",
|
|
31
|
+
);
|
|
32
|
+
const mapping = record(value, `profile_bindings.${profile}`);
|
|
33
|
+
for (const key of Object.keys(mapping))
|
|
34
|
+
if (key !== "woodpecker_profile" && key !== "ssh_credential_ref")
|
|
35
|
+
throw new Error(`Unknown profile_bindings.${profile}.${key}`);
|
|
36
|
+
return [
|
|
37
|
+
profile,
|
|
38
|
+
Object.freeze({
|
|
39
|
+
woodpeckerProfile: field(
|
|
40
|
+
mapping.woodpecker_profile,
|
|
41
|
+
profile,
|
|
42
|
+
`profile_bindings.${profile}.woodpecker_profile`,
|
|
43
|
+
),
|
|
44
|
+
sshCredentialRef: field(
|
|
45
|
+
mapping.ssh_credential_ref,
|
|
46
|
+
profile,
|
|
47
|
+
`profile_bindings.${profile}.ssh_credential_ref`,
|
|
48
|
+
),
|
|
49
|
+
}),
|
|
50
|
+
];
|
|
51
|
+
});
|
|
52
|
+
return Object.freeze(Object.fromEntries(entries));
|
|
53
|
+
}
|
|
54
|
+
/** @internal */
|
|
55
|
+
export function resolveProfileBinding(bindings: ProfileBindings, profile: string): ProfileBinding {
|
|
56
|
+
return Object.hasOwn(bindings, profile)
|
|
57
|
+
? { ...bindings[profile] }
|
|
58
|
+
: { woodpeckerProfile: profile, sshCredentialRef: profile };
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { forgejoRepoChangeProcess as process } from "./testing/default-process.js";
|
|
2
|
+
|
|
3
|
+
export function deliveryTurn() {
|
|
4
|
+
const turn = process.turns.get("deliver_change")?.definition;
|
|
5
|
+
if (turn?.kind !== "automatic") throw new Error("Missing delivery turn");
|
|
6
|
+
return turn;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function routingState(
|
|
10
|
+
forgejoRepoChange: Record<string, unknown>,
|
|
11
|
+
extensionState: Record<string, unknown> = {},
|
|
12
|
+
) {
|
|
13
|
+
return process.stateCodec.parse({ extensionState: { ...extensionState, forgejoRepoChange } });
|
|
14
|
+
}
|