@simplysf/simply-gitlab-core 0.2.0 → 0.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.
- package/README.md +5 -0
- package/lib/baseline-apply.d.ts +35 -0
- package/lib/baseline-apply.js +177 -0
- package/lib/baseline-apply.js.map +1 -0
- package/lib/baseline-config.d.ts +100 -0
- package/lib/baseline-config.js +342 -0
- package/lib/baseline-config.js.map +1 -0
- package/lib/baseline-export.d.ts +21 -0
- package/lib/baseline-export.js +245 -0
- package/lib/baseline-export.js.map +1 -0
- package/lib/baseline-plan.d.ts +96 -0
- package/lib/baseline-plan.js +412 -0
- package/lib/baseline-plan.js.map +1 -0
- package/lib/baseline-render.d.ts +13 -0
- package/lib/baseline-render.js +139 -0
- package/lib/baseline-render.js.map +1 -0
- package/lib/baseline-run.d.ts +49 -0
- package/lib/baseline-run.js +102 -0
- package/lib/baseline-run.js.map +1 -0
- package/lib/baseline-targets.d.ts +31 -0
- package/lib/baseline-targets.js +100 -0
- package/lib/baseline-targets.js.map +1 -0
- package/lib/gitlab-client.d.ts +32 -0
- package/lib/gitlab-client.js +96 -0
- package/lib/gitlab-client.js.map +1 -1
- package/lib/index.d.ts +7 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -66,6 +66,11 @@ Every export from `src/index.ts` is semver-covered: adding one is a minor or pat
|
|
|
66
66
|
or renaming one is breaking. `test/index.test.ts` pins the list, so a removal fails a test rather
|
|
67
67
|
than shipping quietly in a patch.
|
|
68
68
|
|
|
69
|
+
## Guides
|
|
70
|
+
|
|
71
|
+
User-facing documentation for the CLI and MCP server built on this package:
|
|
72
|
+
**https://simplysf.github.io/simply-cli/gitlab/**
|
|
73
|
+
|
|
69
74
|
## Documentation
|
|
70
75
|
|
|
71
76
|
- [GitLab client core design](../../docs/design/0001-gitlab-client-core.md)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BaselinePlan, TargetPlan } from './baseline-plan.js';
|
|
2
|
+
import { type RunOptions } from './baseline-run.js';
|
|
3
|
+
import type { GitLabClient } from './gitlab-client.js';
|
|
4
|
+
/** What executing one target's plan amounted to. */
|
|
5
|
+
export interface TargetResult {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly kind: 'project' | 'group';
|
|
8
|
+
readonly applied: number;
|
|
9
|
+
/** Set when execution stopped part-way; the actions before it are already applied. */
|
|
10
|
+
readonly error?: string;
|
|
11
|
+
/** The section that failed, so a partial application can be described precisely. */
|
|
12
|
+
readonly failedSection?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ApplyResult {
|
|
15
|
+
readonly targets: readonly TargetResult[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Executes one target's plan, in the order the sections were planned.
|
|
19
|
+
*
|
|
20
|
+
* There is no transaction across GitLab endpoints and this does not pretend otherwise: a failure
|
|
21
|
+
* part-way leaves the earlier sections applied, and the result says which section stopped it so a
|
|
22
|
+
* following `plan` can be read against that.
|
|
23
|
+
*/
|
|
24
|
+
export declare function applyTarget(client: GitLabClient, target: TargetPlan): Promise<TargetResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Executes a whole plan.
|
|
27
|
+
*
|
|
28
|
+
* One target failing does not abandon the other forty-nine — that is the default, because a run
|
|
29
|
+
* that stopped at the twelfth project would leave the operator worse off than one that reported
|
|
30
|
+
* twelve successes and one failure. `--fail-fast` is there for the systematic problem where the
|
|
31
|
+
* rest are pointless.
|
|
32
|
+
*/
|
|
33
|
+
export declare function applyPlan(client: GitLabClient, plan: BaselinePlan, options?: RunOptions): Promise<ApplyResult>;
|
|
34
|
+
/** How many targets an apply failed on, for the exit code. */
|
|
35
|
+
export declare function applyFailures(result: ApplyResult): readonly TargetResult[];
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026, SimplySF.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { mapPool, DEFAULT_CONCURRENCY } from './baseline-run.js';
|
|
17
|
+
import { ConfigError } from './errors.js';
|
|
18
|
+
function asRecord(value) {
|
|
19
|
+
return (typeof value === 'object' && value !== null ? value : {});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the name-based references an approval rule carries into the ids the API demands.
|
|
23
|
+
*
|
|
24
|
+
* This has to happen here rather than at plan time. A rule scoped to `main` needs that branch's
|
|
25
|
+
* protection id, and the protected-branches section that creates it runs moments earlier in this
|
|
26
|
+
* same apply — so at plan time the id does not exist yet.
|
|
27
|
+
*/
|
|
28
|
+
async function resolveRuleReferences(client, ref, body, branches, groups) {
|
|
29
|
+
const resolved = { ...body };
|
|
30
|
+
if (branches !== undefined && branches.length > 0) {
|
|
31
|
+
const protectedBranches = (await client.listProtectedBranches(ref)).items.map(asRecord);
|
|
32
|
+
const byName = new Map(protectedBranches.map((branch) => [String(branch.name), branch.id]));
|
|
33
|
+
const ids = [];
|
|
34
|
+
for (const name of branches) {
|
|
35
|
+
const id = byName.get(name);
|
|
36
|
+
if (typeof id !== 'number') {
|
|
37
|
+
throw new ConfigError(`Approval rule references protected branch "${name}", which is not protected on this project. ` +
|
|
38
|
+
'Declare it under protectedBranches so it exists before the rule is written.');
|
|
39
|
+
}
|
|
40
|
+
ids.push(id);
|
|
41
|
+
}
|
|
42
|
+
resolved.protected_branch_ids = ids;
|
|
43
|
+
}
|
|
44
|
+
if (groups !== undefined && groups.length > 0) {
|
|
45
|
+
const ids = [];
|
|
46
|
+
/* Each group is one lookup; there are rarely more than a couple on a rule. */
|
|
47
|
+
/* eslint-disable no-await-in-loop */
|
|
48
|
+
for (const path of groups) {
|
|
49
|
+
const group = asRecord(await client.getGroup(path));
|
|
50
|
+
if (typeof group.id !== 'number') {
|
|
51
|
+
throw new ConfigError(`Approval rule references group "${path}", which could not be resolved to an id.`);
|
|
52
|
+
}
|
|
53
|
+
ids.push(group.id);
|
|
54
|
+
}
|
|
55
|
+
/* eslint-enable no-await-in-loop */
|
|
56
|
+
resolved.group_ids = ids;
|
|
57
|
+
}
|
|
58
|
+
return resolved;
|
|
59
|
+
}
|
|
60
|
+
/** Executes one action. Split out so the switch stays exhaustive as actions are added. */
|
|
61
|
+
async function execute(client, target, action) {
|
|
62
|
+
const ref = target.path;
|
|
63
|
+
switch (action.kind) {
|
|
64
|
+
case 'updateProject':
|
|
65
|
+
await client.updateProject(ref, action.body);
|
|
66
|
+
return;
|
|
67
|
+
case 'updateGroup':
|
|
68
|
+
await client.updateGroup(ref, action.body);
|
|
69
|
+
return;
|
|
70
|
+
case 'protectBranch':
|
|
71
|
+
await client.protectBranch(ref, action.body);
|
|
72
|
+
return;
|
|
73
|
+
case 'patchProtectedBranch':
|
|
74
|
+
await client.patchProtectedBranch(ref, action.name, action.body);
|
|
75
|
+
return;
|
|
76
|
+
case 'unprotectBranch':
|
|
77
|
+
await client.unprotectBranch(ref, action.name);
|
|
78
|
+
return;
|
|
79
|
+
case 'protectTag':
|
|
80
|
+
await client.protectTag(ref, action.body);
|
|
81
|
+
return;
|
|
82
|
+
case 'unprotectTag':
|
|
83
|
+
await client.unprotectTag(ref, action.name);
|
|
84
|
+
return;
|
|
85
|
+
case 'updateApprovalSettings':
|
|
86
|
+
await client.updateApprovalSettings(ref, action.body);
|
|
87
|
+
return;
|
|
88
|
+
case 'createApprovalRule': {
|
|
89
|
+
const groups = Array.isArray(action.body.groups) ? action.body.groups : undefined;
|
|
90
|
+
const body = await resolveRuleReferences(client, ref, action.body, action.branches, groups);
|
|
91
|
+
await client.createApprovalRule(ref, body);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
case 'updateApprovalRule': {
|
|
95
|
+
const groups = Array.isArray(action.body.groups) ? action.body.groups : undefined;
|
|
96
|
+
const body = await resolveRuleReferences(client, ref, action.body, action.branches, groups);
|
|
97
|
+
await client.updateApprovalRule(ref, action.ruleId, body);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
case 'deleteApprovalRule':
|
|
101
|
+
await client.deleteApprovalRule(ref, action.ruleId);
|
|
102
|
+
return;
|
|
103
|
+
case 'setPushRules':
|
|
104
|
+
// POST creates the rule set, PUT edits it. Which one applies was decided at plan time from
|
|
105
|
+
// whether the project already had push rules.
|
|
106
|
+
if (action.exists)
|
|
107
|
+
await client.updatePushRules(ref, action.body);
|
|
108
|
+
else
|
|
109
|
+
await client.createPushRules(ref, action.body);
|
|
110
|
+
return;
|
|
111
|
+
default: {
|
|
112
|
+
const exhaustive = action;
|
|
113
|
+
throw new ConfigError(`Unknown action ${JSON.stringify(exhaustive)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Executes one target's plan, in the order the sections were planned.
|
|
119
|
+
*
|
|
120
|
+
* There is no transaction across GitLab endpoints and this does not pretend otherwise: a failure
|
|
121
|
+
* part-way leaves the earlier sections applied, and the result says which section stopped it so a
|
|
122
|
+
* following `plan` can be read against that.
|
|
123
|
+
*/
|
|
124
|
+
export async function applyTarget(client, target) {
|
|
125
|
+
let applied = 0;
|
|
126
|
+
for (const section of target.sections) {
|
|
127
|
+
for (const action of section.actions) {
|
|
128
|
+
try {
|
|
129
|
+
// eslint-disable-next-line no-await-in-loop -- order across sections is the contract
|
|
130
|
+
await execute(client, target, action);
|
|
131
|
+
applied += 1;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
return {
|
|
135
|
+
path: target.path,
|
|
136
|
+
kind: target.kind,
|
|
137
|
+
applied,
|
|
138
|
+
failedSection: section.section,
|
|
139
|
+
error: error instanceof Error ? error.message : String(error),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return { path: target.path, kind: target.kind, applied };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Executes a whole plan.
|
|
148
|
+
*
|
|
149
|
+
* One target failing does not abandon the other forty-nine — that is the default, because a run
|
|
150
|
+
* that stopped at the twelfth project would leave the operator worse off than one that reported
|
|
151
|
+
* twelve successes and one failure. `--fail-fast` is there for the systematic problem where the
|
|
152
|
+
* rest are pointless.
|
|
153
|
+
*/
|
|
154
|
+
export async function applyPlan(client, plan, options = {}) {
|
|
155
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
156
|
+
// A target that failed to plan is not applied: acting on a half-read project is how a baseline
|
|
157
|
+
// makes things worse than it found them.
|
|
158
|
+
const runnable = plan.targets.filter((target) => target.error === undefined);
|
|
159
|
+
const unplanned = plan.targets
|
|
160
|
+
.filter((target) => target.error !== undefined)
|
|
161
|
+
.map((target) => ({ path: target.path, kind: target.kind, applied: 0, error: target.error }));
|
|
162
|
+
const groups = runnable.filter((target) => target.kind === 'group');
|
|
163
|
+
const projects = runnable.filter((target) => target.kind === 'project');
|
|
164
|
+
const stopAfter = options.failFast === true ? (result) => result.error !== undefined : undefined;
|
|
165
|
+
// Groups first: a group setting that projects inherit should be in place before the projects are
|
|
166
|
+
// reconciled against it.
|
|
167
|
+
const groupResults = await mapPool(groups, concurrency, (target) => applyTarget(client, target), stopAfter);
|
|
168
|
+
const projectResults = options.failFast === true && groupResults.some((result) => result.error !== undefined)
|
|
169
|
+
? []
|
|
170
|
+
: await mapPool(projects, concurrency, (target) => applyTarget(client, target), stopAfter);
|
|
171
|
+
return { targets: [...unplanned, ...groupResults, ...projectResults] };
|
|
172
|
+
}
|
|
173
|
+
/** How many targets an apply failed on, for the exit code. */
|
|
174
|
+
export function applyFailures(result) {
|
|
175
|
+
return result.targets.filter((target) => target.error !== undefined);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=baseline-apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseline-apply.js","sourceRoot":"","sources":["../src/baseline-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,OAAO,EAAmB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAkB1C,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAA4B,CAAC;AAC/F,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,qBAAqB,CAClC,MAAoB,EACpB,GAAe,EACf,IAA6B,EAC7B,QAAuC,EACvC,MAAqC;IAErC,MAAM,QAAQ,GAA4B,EAAE,GAAG,IAAI,EAAE,CAAC;IAEtD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,MAAM,iBAAiB,GAAG,CAAC,MAAM,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5F,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,KAAK,M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KAAK,KAAK,SAAS,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The baseline configuration file: what a set of projects should have in common.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is data. Reading it, diffing against an instance, and converging are three other
|
|
5
|
+
* modules; this one only turns a file into a validated, merged description of intent — which is
|
|
6
|
+
* what makes the merge semantics below testable without a server.
|
|
7
|
+
*
|
|
8
|
+
* See docs/design/0007-configuration-baselines.md.
|
|
9
|
+
*/
|
|
10
|
+
export interface BaselineConfig {
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
readonly targets?: BaselineTargets;
|
|
13
|
+
readonly group?: GroupDesired;
|
|
14
|
+
readonly project?: ProjectDesired;
|
|
15
|
+
readonly overrides?: Readonly<Record<string, TargetOverride>>;
|
|
16
|
+
}
|
|
17
|
+
export interface BaselineTargets {
|
|
18
|
+
/** Group paths or ids. Expands to every project in the group and its subgroups. */
|
|
19
|
+
readonly groups?: readonly string[];
|
|
20
|
+
/** Individual project paths or ids, added to whatever the groups expanded to. */
|
|
21
|
+
readonly projects?: readonly string[];
|
|
22
|
+
/** Removed from the union. A trailing `*` drops a whole subtree. */
|
|
23
|
+
readonly exclude?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
export interface TargetOverride {
|
|
26
|
+
readonly project?: ProjectDesired;
|
|
27
|
+
readonly group?: GroupDesired;
|
|
28
|
+
}
|
|
29
|
+
export interface GroupDesired {
|
|
30
|
+
readonly settings?: Readonly<Record<string, unknown>>;
|
|
31
|
+
}
|
|
32
|
+
export interface ProjectDesired {
|
|
33
|
+
readonly settings?: Readonly<Record<string, unknown>>;
|
|
34
|
+
readonly protectedBranches?: Section;
|
|
35
|
+
readonly protectedTags?: Section;
|
|
36
|
+
readonly approvals?: Readonly<Record<string, unknown>>;
|
|
37
|
+
readonly approvalRules?: Section;
|
|
38
|
+
readonly pushRules?: Readonly<Record<string, unknown>>;
|
|
39
|
+
readonly variables?: Section;
|
|
40
|
+
}
|
|
41
|
+
/** An entry in a keyed section. Fields are GitLab's own, so this stays deliberately open. */
|
|
42
|
+
export type Entry = Readonly<Record<string, unknown>>;
|
|
43
|
+
/**
|
|
44
|
+
* A list section, in either of the two shapes the file accepts: a bare array, or an object that
|
|
45
|
+
* can also turn on pruning or wholesale replacement.
|
|
46
|
+
*/
|
|
47
|
+
export type Section = readonly Entry[] | SectionObject;
|
|
48
|
+
export interface SectionObject {
|
|
49
|
+
/** Delete entries that exist on the instance but are not declared here. Off by default. */
|
|
50
|
+
readonly prune?: boolean;
|
|
51
|
+
/** Replace the baseline's entries entirely instead of merging into them, in an override. */
|
|
52
|
+
readonly $replace?: boolean;
|
|
53
|
+
readonly entries: readonly Entry[];
|
|
54
|
+
}
|
|
55
|
+
/** A section reduced to the three things every consumer needs. */
|
|
56
|
+
export interface NormalizedSection {
|
|
57
|
+
readonly prune: boolean;
|
|
58
|
+
readonly replace: boolean;
|
|
59
|
+
readonly entries: readonly Entry[];
|
|
60
|
+
}
|
|
61
|
+
/** The list sections, in the order `apply` reconciles them. */
|
|
62
|
+
export declare const LIST_SECTIONS: readonly ["protectedBranches", "protectedTags", "approvalRules", "variables"];
|
|
63
|
+
export type ListSection = (typeof LIST_SECTIONS)[number];
|
|
64
|
+
/** The object sections, which merge key by key rather than by entry. */
|
|
65
|
+
export declare const OBJECT_SECTIONS: readonly ["settings", "approvals", "pushRules"];
|
|
66
|
+
/** The identity of one entry, as a string, for keying a map. */
|
|
67
|
+
export declare function entryKey(section: ListSection, entry: Entry): string;
|
|
68
|
+
/** The human-readable identity of one entry, for plan output. */
|
|
69
|
+
export declare function entryLabel(section: ListSection, entry: Entry): string;
|
|
70
|
+
export declare function normalizeSection(section: Section | undefined): NormalizedSection | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Validates the parsed file, reporting the JSON path of whatever is wrong.
|
|
73
|
+
*
|
|
74
|
+
* Hand-written rather than schema-driven because the error is the product: a caller who wrote
|
|
75
|
+
* `"targets": {"group": "x"}` needs to be told that the key is `groups` and that it takes an array,
|
|
76
|
+
* at that path, not that the document failed to match a schema. The published JSON Schema gives an
|
|
77
|
+
* editor completion and hover text; this is what runs.
|
|
78
|
+
*/
|
|
79
|
+
export declare function validateBaselineConfig(value: unknown, label?: string): BaselineConfig;
|
|
80
|
+
/**
|
|
81
|
+
* The effective configuration for one project: the baseline with its override merged over it.
|
|
82
|
+
*
|
|
83
|
+
* Objects merge key by key. Lists merge by the section's natural key, so an override adjusts one
|
|
84
|
+
* entry rather than restating the array — unless it sets `$replace`, which swaps the list wholesale
|
|
85
|
+
* for the project that genuinely needs different rules rather than adjusted ones.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mergeProjectDesired(base?: ProjectDesired, override?: ProjectDesired): ProjectDesired;
|
|
88
|
+
export declare function mergeGroupDesired(base?: GroupDesired, override?: GroupDesired): GroupDesired;
|
|
89
|
+
/** The effective project configuration for one path, baseline merged with any override for it. */
|
|
90
|
+
export declare function effectiveProject(config: BaselineConfig, path: string): ProjectDesired;
|
|
91
|
+
/** The effective group configuration for one path. */
|
|
92
|
+
export declare function effectiveGroup(config: BaselineConfig, path: string): GroupDesired;
|
|
93
|
+
/**
|
|
94
|
+
* Reads and validates a baseline config file.
|
|
95
|
+
*
|
|
96
|
+
* A parse failure reports only the position, never the parser's snippet of the content — the same
|
|
97
|
+
* rule the rest of this package follows, because a caller can name any path and the snippet would
|
|
98
|
+
* echo the first bytes of whatever file that was.
|
|
99
|
+
*/
|
|
100
|
+
export declare function loadBaselineConfig(path: string): BaselineConfig;
|