@leitwerk-dev/gitlab 0.4.0 → 0.4.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 +33 -13
- package/dist/{chunk-YPCOVBQS.js → chunk-23NUGZ3Q.js} +116 -30
- package/dist/chunk-23NUGZ3Q.js.map +1 -0
- package/dist/client.d.ts +18 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -30
- package/dist/index.js.map +1 -1
- package/dist/maintenance.d.ts +3 -13
- package/dist/maintenance.d.ts.map +1 -1
- package/dist/publication-maintenance.d.ts.map +1 -1
- package/dist/publication.d.ts +2 -0
- package/dist/publication.d.ts.map +1 -1
- package/dist/testing.d.ts +4 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +34 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +44 -0
- package/dist/tools.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/client.ts +46 -1
- package/src/index.ts +0 -1
- package/src/maintenance.ts +8 -46
- package/src/publication-maintenance.ts +41 -39
- package/src/publication.ts +24 -4
- package/src/testing.ts +35 -0
- package/src/tools.ts +126 -0
- package/dist/chunk-YPCOVBQS.js.map +0 -1
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ extensions:
|
|
|
62
62
|
- `registerGitLabMaintainedProcess()` registers a typed MR maintenance policy through
|
|
63
63
|
the capability registry. One server service observes all registered processes,
|
|
64
64
|
including running turns and operator waits. The process supplies its repair
|
|
65
|
-
destinations, state adapters
|
|
65
|
+
destinations, state adapters and completion policy.
|
|
66
66
|
- `gitlabRepositoryCredentials(profile, projects)` derives internal credential references. The core authorizes their HTTPS origin and exact repository path against the process projects.
|
|
67
67
|
- `selectGitLabProjects()` expands exact includes and groups, including subgroups, then applies exclusions. Includes form a union; stable project IDs remove duplicates. An explicit include or `all_accessible: true` is required.
|
|
68
68
|
- `observeMergeRequest()` selects the newest pipeline associated with the current MR source revision. Synthetic merge commits must contain that head as a parent. With no matching MR pipeline, it falls back to the current source branch's push pipeline. A newer pending result supersedes older terminal results. The observation includes GitLab's `has_conflicts`, `merge_status` and `detailed_merge_status`, plus `targetHead` read from the current target branch (not the historical diff base). Closed MRs do not require branch or pipeline reads.
|
|
@@ -102,6 +102,8 @@ conflict observations remain available.
|
|
|
102
102
|
|
|
103
103
|
`ensureGitLabSeenReaction()` lets a process acknowledge an authorized MR comment with an eyes reaction. It reconciles the authenticated bot's reaction and records it with `ctx.externalWrites.ensure()`. Other users' eyes reactions do not suppress the bot's acknowledgement; retries and restarts do not duplicate it. The calling process owns selection and lifecycle checks.
|
|
104
104
|
|
|
105
|
+
`gitlab_approve_merge_request` approves the bound MR when its current source SHA matches the supplied full SHA. The write key includes that SHA. A repeated call reconciles the bot's existing approval and does not approve again. A SHA that is no longer HEAD is left unapproved. `gitlab_unapprove_merge_request` removes that approval when the same SHA is still HEAD. A repeated call does not unapprove again. A moved HEAD is left unchanged so the next review can decide.
|
|
106
|
+
|
|
105
107
|
The extension contains no Renovate selection or repair policy. `./testing` exports a persistent `LocalGitLabAdapter` with real local repository ancestry for integration tests.
|
|
106
108
|
|
|
107
109
|
## Shared MR maintenance
|
|
@@ -115,11 +117,6 @@ registerGitLabMaintainedProcess(api, {
|
|
|
115
117
|
paramsCodec: process.paramsCodec,
|
|
116
118
|
stateCodec: process.stateCodec,
|
|
117
119
|
idleTurnId: "deliver_change",
|
|
118
|
-
destinations: {
|
|
119
|
-
feedback: "maintenance_feedback",
|
|
120
|
-
conflict: "maintenance_conflict",
|
|
121
|
-
ci: "maintenance_ci",
|
|
122
|
-
},
|
|
123
120
|
observe: repairPolicy.observe,
|
|
124
121
|
stopped: repairPolicy.stopped,
|
|
125
122
|
terminal: repairPolicy.terminal,
|
|
@@ -132,9 +129,9 @@ Bindings default to each process project's `gitlab` metadata. `bindings` can
|
|
|
132
129
|
provide explicit MR targets. `settings` supplies the consumed feedback cursor,
|
|
133
130
|
activation receipt, polling interval and quiet period; the quiet period defaults
|
|
134
131
|
to two minutes. `assess`, `eligible` and `canWrite` retain process-specific admission
|
|
135
|
-
rules. `observe` returns state and an optional
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
rules. `observe` returns state and an optional declared external action ID, such
|
|
133
|
+
as `maintenance_feedback`. It replaces the former `destinations` alias mapping.
|
|
134
|
+
The service fires that edge; ordinary observations allocate no worker or turn record.
|
|
138
135
|
`currentBinding` identifies a selected repair or operator decision so removing a
|
|
139
136
|
different MR's label preserves that business position. Interrupted repairs on
|
|
140
137
|
remaining MRs retain their staged work and repair budgets.
|
|
@@ -142,8 +139,15 @@ remaining MRs retain their staged work and repair budgets.
|
|
|
142
139
|
`messages` supplies retry-safe discussion replies or comments. `settled` advances
|
|
143
140
|
business acknowledgement state after those writes succeed. `completion` determines
|
|
144
141
|
the terminal lifecycle without remote writes. `complete` delivers process-specific
|
|
145
|
-
terminal writes and retries them after the process ends.
|
|
146
|
-
|
|
142
|
+
terminal writes and retries them after the process ends.
|
|
143
|
+
|
|
144
|
+
Eligible, owned bindings request server-managed recovery for failed unaccepted
|
|
145
|
+
worker starts. The server allows three starts per episode, with 30/60 second
|
|
146
|
+
retry delays for known transient failures. Configuration errors, OOMs and unknown
|
|
147
|
+
failures require manual recovery. Accepted failed turns are never retried by
|
|
148
|
+
maintenance. Recovery does not consume the process's business repair budget.
|
|
149
|
+
The deprecated `retry.maxAttempts` setting is ignored; maintenance cannot override
|
|
150
|
+
the server's startup budget.
|
|
147
151
|
|
|
148
152
|
Taking responsibility adds `leitwerk-active`. Green CI keeps maintenance active for
|
|
149
153
|
later feedback. Removing the label ends that MR's activation and leaves the MR open.
|
|
@@ -166,11 +170,27 @@ Processes retain their own reactivation admission and partial-completion rules.
|
|
|
166
170
|
The shared publication adapter used by Jira and GitLab repository changes registers
|
|
167
171
|
this policy. Settled feedback and actionable conflicts invoke Address Feedback
|
|
168
172
|
directly; failed current-revision CI invokes Fix CI. Changed work returns to Deliver.
|
|
169
|
-
A no-change outcome
|
|
170
|
-
|
|
173
|
+
A no-change outcome returns through Deliver to check concurrent source updates and
|
|
174
|
+
retained local work before acknowledging its batch. An unchanged checkout creates
|
|
175
|
+
no commit or push. Label, target-head and mergeability updates do not replay a
|
|
171
176
|
handled pipeline failure. A new pipeline or an observed running-to-failed retry
|
|
172
177
|
remains actionable. Maintenance adds no business turns.
|
|
173
178
|
|
|
179
|
+
The current source branch is authoritative, including developer rebases and pushes.
|
|
180
|
+
Idle observations adopt its head while retaining the earlier work baseline and
|
|
181
|
+
publication receipt separately. Feedback stays actionable when the head changes;
|
|
182
|
+
the worker reconciles unpublished local work before adjusting the current revision.
|
|
183
|
+
Source/target project or branch changes are explicit binding errors, not permission
|
|
184
|
+
to publish elsewhere. Active workers keep their captured state; delivery rechecks
|
|
185
|
+
the branch after their work. Only pipelines associated with the current source
|
|
186
|
+
revision or a merge-result commit containing it can trigger repair.
|
|
187
|
+
|
|
188
|
+
An eyes reaction means the watcher saw an authorized comment. It does not mean a
|
|
189
|
+
worker started, completed an adjustment, or consumed the feedback. Comments remain
|
|
190
|
+
pending until publication or a verified no-change result is acknowledged. Conflict
|
|
191
|
+
resolution, validation retries and safe publication use the shared
|
|
192
|
+
[Coding reconciliation contract](../coding/README.md#source-branch-reconciliation).
|
|
193
|
+
|
|
174
194
|
## Creating repository changes
|
|
175
195
|
|
|
176
196
|
Load [gitlab-repo-change](../gitlab-repo-change/README.md) for UI and labeled-issue
|
|
@@ -344,6 +344,18 @@ var GitLabClient = class {
|
|
|
344
344
|
getMergeRequest(id, iid, signal) {
|
|
345
345
|
return this.request(mrPath(id, iid), signal);
|
|
346
346
|
}
|
|
347
|
+
/** @internal */
|
|
348
|
+
getMergeRequestApprovals(id, iid, signal) {
|
|
349
|
+
return this.request(`${mrPath(id, iid)}/approvals`, signal);
|
|
350
|
+
}
|
|
351
|
+
/** @internal */
|
|
352
|
+
approveMergeRequest(id, iid, sha, signal) {
|
|
353
|
+
return this.request(`${mrPath(id, iid)}/approve`, signal, { sha });
|
|
354
|
+
}
|
|
355
|
+
/** @internal */
|
|
356
|
+
unapproveMergeRequest(id, iid, signal) {
|
|
357
|
+
return this.request(`${mrPath(id, iid)}/unapprove`, signal, {});
|
|
358
|
+
}
|
|
347
359
|
/** Read every label transition, including changes between watcher polls. @public */
|
|
348
360
|
listMergeRequestLabelEvents(id, iid, signal) {
|
|
349
361
|
return this.pages(`${mrPath(id, iid)}/resource_label_events`, signal);
|
|
@@ -527,7 +539,12 @@ async function observeMergeRequest(client, projectId, iid, signal) {
|
|
|
527
539
|
matches = commit.parent_ids.includes(mr.sha);
|
|
528
540
|
}
|
|
529
541
|
if (matches)
|
|
530
|
-
return {
|
|
542
|
+
return {
|
|
543
|
+
mr,
|
|
544
|
+
targetHead,
|
|
545
|
+
pipeline: await client.getPipeline(id, candidate.id, signal),
|
|
546
|
+
pipelineSourceHead: mr.sha
|
|
547
|
+
};
|
|
531
548
|
}
|
|
532
549
|
const candidates = await client.listBranchPipelines(
|
|
533
550
|
mr.source_project_id,
|
|
@@ -539,7 +556,8 @@ async function observeMergeRequest(client, projectId, iid, signal) {
|
|
|
539
556
|
return {
|
|
540
557
|
mr,
|
|
541
558
|
targetHead,
|
|
542
|
-
pipeline: latest ? await client.getPipeline(mr.source_project_id, latest.id, signal) : null
|
|
559
|
+
pipeline: latest ? await client.getPipeline(mr.source_project_id, latest.id, signal) : null,
|
|
560
|
+
...latest ? { pipelineSourceHead: mr.sha } : {}
|
|
543
561
|
};
|
|
544
562
|
}
|
|
545
563
|
|
|
@@ -747,6 +765,73 @@ async function ensureGitLabResolveDiscussion(input) {
|
|
|
747
765
|
);
|
|
748
766
|
return { discussionId, resolved: true };
|
|
749
767
|
}
|
|
768
|
+
async function ensureGitLabApproval(input) {
|
|
769
|
+
const { client, writes, instanceId, projectId, iid, writeKey, sha, signal } = input;
|
|
770
|
+
if (!/^[a-f0-9]{40}$/i.test(sha)) throw new Error("GitLab approval requires the full source SHA");
|
|
771
|
+
const current = await client.getMergeRequest(projectId, iid, signal);
|
|
772
|
+
if (current.sha !== sha) return { sha, approved: false };
|
|
773
|
+
const digest = hashIdentity([
|
|
774
|
+
client.baseUrl,
|
|
775
|
+
projectId,
|
|
776
|
+
iid,
|
|
777
|
+
instanceId,
|
|
778
|
+
"approve",
|
|
779
|
+
writeKey,
|
|
780
|
+
sha
|
|
781
|
+
]);
|
|
782
|
+
await writes.ensure(
|
|
783
|
+
{ writeType: "gitlab.approval", dedupKey: digest },
|
|
784
|
+
{
|
|
785
|
+
reconcile: async () => {
|
|
786
|
+
const head = await client.getMergeRequest(projectId, iid, signal);
|
|
787
|
+
const approvals = await client.getMergeRequestApprovals(projectId, iid, signal);
|
|
788
|
+
return head.sha === sha && approvals.user_has_approved ? { sha } : null;
|
|
789
|
+
},
|
|
790
|
+
execute: () => client.approveMergeRequest(projectId, iid, sha, signal),
|
|
791
|
+
toMetadata: (approval) => ({ projectId, iid, sha: approval.sha })
|
|
792
|
+
}
|
|
793
|
+
);
|
|
794
|
+
return { sha, approved: true };
|
|
795
|
+
}
|
|
796
|
+
async function ensureGitLabUnapproval(input) {
|
|
797
|
+
const { client, writes, instanceId, projectId, iid, writeKey, sha, signal } = input;
|
|
798
|
+
if (!/^[a-f0-9]{40}$/i.test(sha))
|
|
799
|
+
throw new Error("GitLab unapprove requires the full source SHA");
|
|
800
|
+
const current = await client.getMergeRequest(projectId, iid, signal);
|
|
801
|
+
if (current.sha !== sha) return { sha, unapproved: false };
|
|
802
|
+
const digest = hashIdentity([
|
|
803
|
+
client.baseUrl,
|
|
804
|
+
projectId,
|
|
805
|
+
iid,
|
|
806
|
+
instanceId,
|
|
807
|
+
"unapprove",
|
|
808
|
+
writeKey,
|
|
809
|
+
sha
|
|
810
|
+
]);
|
|
811
|
+
try {
|
|
812
|
+
await writes.ensure(
|
|
813
|
+
{ writeType: "gitlab.unapproval", dedupKey: digest },
|
|
814
|
+
{
|
|
815
|
+
reconcile: async () => {
|
|
816
|
+
const head = await client.getMergeRequest(projectId, iid, signal);
|
|
817
|
+
const approvals = await client.getMergeRequestApprovals(projectId, iid, signal);
|
|
818
|
+
return head.sha === sha && !approvals.user_has_approved ? { sha } : null;
|
|
819
|
+
},
|
|
820
|
+
execute: async () => {
|
|
821
|
+
const head = await client.getMergeRequest(projectId, iid, signal);
|
|
822
|
+
if (head.sha !== sha) throw new Error("GitLab source SHA is no longer HEAD");
|
|
823
|
+
return client.unapproveMergeRequest(projectId, iid, signal);
|
|
824
|
+
},
|
|
825
|
+
toMetadata: (removed) => ({ projectId, iid, sha: removed.sha })
|
|
826
|
+
}
|
|
827
|
+
);
|
|
828
|
+
} catch (error) {
|
|
829
|
+
if ((await client.getMergeRequest(projectId, iid, signal)).sha !== sha)
|
|
830
|
+
return { sha, unapproved: false };
|
|
831
|
+
throw error;
|
|
832
|
+
}
|
|
833
|
+
return { sha, unapproved: true };
|
|
834
|
+
}
|
|
750
835
|
async function ensureGitLabSeenReaction(input) {
|
|
751
836
|
const { client, writes, instanceId, projectId, iid, noteId, signal } = input;
|
|
752
837
|
const digest = hashIdentity([client.baseUrl, projectId, iid, instanceId, "eyes", noteId]);
|
|
@@ -862,6 +947,16 @@ function registerGitLabTools(api, integration, beforeWrite) {
|
|
|
862
947
|
"gitlab_resolve_discussion",
|
|
863
948
|
"Resolve a retry-safe MR inline discussion",
|
|
864
949
|
["writeKey", "discussionId"]
|
|
950
|
+
],
|
|
951
|
+
[
|
|
952
|
+
"gitlab_approve_merge_request",
|
|
953
|
+
"Approve the bound MR at an exact source SHA",
|
|
954
|
+
["writeKey", "sha"]
|
|
955
|
+
],
|
|
956
|
+
[
|
|
957
|
+
"gitlab_unapprove_merge_request",
|
|
958
|
+
"Remove the bot approval while the reviewed source SHA is still HEAD",
|
|
959
|
+
["writeKey", "sha"]
|
|
865
960
|
]
|
|
866
961
|
]) {
|
|
867
962
|
api.tool({
|
|
@@ -880,7 +975,8 @@ function registerGitLabTools(api, integration, beforeWrite) {
|
|
|
880
975
|
side: { type: "string" },
|
|
881
976
|
baseSha: { type: "string" },
|
|
882
977
|
startSha: { type: "string" },
|
|
883
|
-
headSha: { type: "string" }
|
|
978
|
+
headSha: { type: "string" },
|
|
979
|
+
sha: { type: "string" }
|
|
884
980
|
},
|
|
885
981
|
[...required]
|
|
886
982
|
),
|
|
@@ -936,6 +1032,18 @@ function registerGitLabTools(api, integration, beforeWrite) {
|
|
|
936
1032
|
writeKey: stringArg(args, "writeKey"),
|
|
937
1033
|
discussionId: stringArg(args, "discussionId")
|
|
938
1034
|
});
|
|
1035
|
+
if (name === "gitlab_approve_merge_request")
|
|
1036
|
+
return ensureGitLabApproval({
|
|
1037
|
+
...writeContext,
|
|
1038
|
+
writeKey: stringArg(args, "writeKey"),
|
|
1039
|
+
sha: stringArg(args, "sha")
|
|
1040
|
+
});
|
|
1041
|
+
if (name === "gitlab_unapprove_merge_request")
|
|
1042
|
+
return ensureGitLabUnapproval({
|
|
1043
|
+
...writeContext,
|
|
1044
|
+
writeKey: stringArg(args, "writeKey"),
|
|
1045
|
+
sha: stringArg(args, "sha")
|
|
1046
|
+
});
|
|
939
1047
|
const observation = await observeMergeRequest(client, b.projectId, b.iid, ctx.signal);
|
|
940
1048
|
if (!observation.pipeline || observation.pipeline.id !== numberArg(args, "pipelineId"))
|
|
941
1049
|
throw new Error("Pipeline is not current for the authorized MR");
|
|
@@ -1700,9 +1808,8 @@ function createGitLabMaintenance(api, deps, integration, now = Date.now) {
|
|
|
1700
1808
|
fresh = deps.processes.getById(process2.id);
|
|
1701
1809
|
if (!fresh) continue;
|
|
1702
1810
|
if (eligible && decision.action && fresh.lifecycleStatus === "waiting" && unchangedWork(fresh, ctx.process)) {
|
|
1703
|
-
const destination = policy.destinations[decision.action] ?? decision.action;
|
|
1704
1811
|
const armed = deps.externalSources.listArmed(policy.sourceKind ?? GITLAB_MAINTAINED_KIND).find(
|
|
1705
|
-
(item) => item.instanceId === process2.id && item.externalActionId ===
|
|
1812
|
+
(item) => item.instanceId === process2.id && item.externalActionId === decision.action
|
|
1706
1813
|
);
|
|
1707
1814
|
if (armed) {
|
|
1708
1815
|
await service.assertOwnership(fresh.id, binding.projectKey, ctx.signal);
|
|
@@ -1727,30 +1834,9 @@ function createGitLabMaintenance(api, deps, integration, now = Date.now) {
|
|
|
1727
1834
|
if (!fresh.currentExecution && settledState !== ctx.state)
|
|
1728
1835
|
await observe(fresh, { state: settledState });
|
|
1729
1836
|
fresh = deps.processes.getById(process2.id);
|
|
1730
|
-
if (fresh && eligible &&
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
if (retry.executionId !== fresh.currentExecution.id) {
|
|
1734
|
-
await observe(fresh, {
|
|
1735
|
-
metadata: {
|
|
1736
|
-
gitlabMaintenanceRetry: {
|
|
1737
|
-
attempts,
|
|
1738
|
-
executionId: fresh.currentExecution.id,
|
|
1739
|
-
nextAt: now() + Math.min(3e5, 3e4 * 2 ** attempts),
|
|
1740
|
-
attempted: false
|
|
1741
|
-
}
|
|
1742
|
-
},
|
|
1743
|
-
preserveUpdatedAt: true
|
|
1744
|
-
});
|
|
1745
|
-
} else if (!retry.attempted && attempts < policy.retry.maxAttempts && Number(retry.nextAt) <= now()) {
|
|
1746
|
-
await service.assertOwnership(fresh.id, binding.projectKey, ctx.signal);
|
|
1747
|
-
const saved2 = await observe(fresh, {
|
|
1748
|
-
metadata: {
|
|
1749
|
-
gitlabMaintenanceRetry: { ...retry, attempts: attempts + 1, attempted: true }
|
|
1750
|
-
}
|
|
1751
|
-
});
|
|
1752
|
-
if (saved2.ok) await deps.commands.retryProcess(fresh.id);
|
|
1753
|
-
}
|
|
1837
|
+
if (fresh && eligible && fresh.lifecycleStatus === "error" && fresh.currentExecution?.kind === "worker_start") {
|
|
1838
|
+
await service.assertOwnership(fresh.id, binding.projectKey, ctx.signal);
|
|
1839
|
+
await deps.commands.retryStartupAutomatically(fresh.id, fresh.currentExecution.id);
|
|
1754
1840
|
} else if (fresh?.lifecycleStatus === "waiting" && !fresh.currentExecution && fresh.selectedTurnId === policy.idleTurnId && fresh.metadata?.gitlabMaintenanceRetry) {
|
|
1755
1841
|
await observe(fresh, {
|
|
1756
1842
|
metadata: { gitlabMaintenanceRetry: null },
|
|
@@ -2340,4 +2426,4 @@ export {
|
|
|
2340
2426
|
createGitLabRepositoryCatalog,
|
|
2341
2427
|
setupGitLabIntegration
|
|
2342
2428
|
};
|
|
2343
|
-
//# sourceMappingURL=chunk-
|
|
2429
|
+
//# sourceMappingURL=chunk-23NUGZ3Q.js.map
|