@leitwerk-dev/gitlab 0.5.11 → 0.5.13
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 +13 -0
- package/dist/{chunk-KW4UOHAM.js → chunk-JPPNVWMZ.js} +65 -17
- package/dist/chunk-JPPNVWMZ.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/delivery-tools.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/merge-request-template.d.ts +5 -0
- package/dist/merge-request-template.d.ts.map +1 -0
- package/dist/publication.d.ts.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +1 -1
- package/package.json +7 -7
- package/src/client.ts +2 -0
- package/src/delivery-tools.ts +14 -5
- package/src/merge-request-template.ts +60 -0
- package/src/publication.ts +1 -0
- package/src/testing.ts +2 -2
- package/dist/chunk-KW4UOHAM.js.map +0 -1
package/src/delivery-tools.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
stringArg,
|
|
8
8
|
} from "@leitwerk-dev/process-sdk";
|
|
9
9
|
import type { GitLabIntegration } from "./capability.js";
|
|
10
|
+
import { mergeRequestBody } from "./merge-request-template.js";
|
|
10
11
|
import {
|
|
11
12
|
ensureGitLabSeenReaction,
|
|
12
13
|
resolveGitLabBinding,
|
|
@@ -55,17 +56,25 @@ export function registerGitLabDeliveryTools(
|
|
|
55
56
|
);
|
|
56
57
|
const request = await ctx.externalWrites.ensure(identity, {
|
|
57
58
|
reconcile: async () => (await find()) ?? null,
|
|
58
|
-
execute: () =>
|
|
59
|
-
|
|
59
|
+
execute: async () => {
|
|
60
|
+
const title = stringArg(args, "title");
|
|
61
|
+
const body = await mergeRequestBody(
|
|
62
|
+
client,
|
|
63
|
+
binding.projectId,
|
|
64
|
+
stringArg(args, "body"),
|
|
65
|
+
ctx,
|
|
66
|
+
);
|
|
67
|
+
return client.createMergeRequest(
|
|
60
68
|
binding.projectId,
|
|
61
69
|
{
|
|
62
|
-
title
|
|
63
|
-
description: `${
|
|
70
|
+
title,
|
|
71
|
+
description: `${body}\n\n${marker}`,
|
|
64
72
|
source_branch: workBranch,
|
|
65
73
|
target_branch: project.baseBranch,
|
|
66
74
|
},
|
|
67
75
|
ctx.signal,
|
|
68
|
-
)
|
|
76
|
+
);
|
|
77
|
+
},
|
|
69
78
|
toMetadata: (mr) => ({ iid: mr.iid, url: mr.web_url }),
|
|
70
79
|
});
|
|
71
80
|
const latest = projects.getByInstanceAndKey(ctx.process.id, project.key);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { IntegrationToolExecutionContext } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { GitLabClientLike } from "./client.js";
|
|
3
|
+
|
|
4
|
+
const directory = ".gitlab/merge_request_templates";
|
|
5
|
+
|
|
6
|
+
/** @internal */
|
|
7
|
+
export async function mergeRequestBody(
|
|
8
|
+
client: Pick<
|
|
9
|
+
GitLabClientLike,
|
|
10
|
+
"getProject" | "getBranch" | "listRepositoryTree" | "getRepositoryFile"
|
|
11
|
+
>,
|
|
12
|
+
projectId: number,
|
|
13
|
+
body: string,
|
|
14
|
+
ctx: Pick<IntegrationToolExecutionContext, "signal" | "reportProgress">,
|
|
15
|
+
): Promise<string> {
|
|
16
|
+
if (!client.getRepositoryFile || !client.listRepositoryTree)
|
|
17
|
+
throw new Error("GitLab repository template lookup is unavailable");
|
|
18
|
+
|
|
19
|
+
const { default_branch: branch } = await client.getProject(projectId, ctx.signal);
|
|
20
|
+
if (!branch) throw new Error("GitLab repository has no default branch for template lookup");
|
|
21
|
+
const { commit } = await client.getBranch(projectId, branch, ctx.signal);
|
|
22
|
+
const list = client.listRepositoryTree.bind(client, projectId, commit.id);
|
|
23
|
+
// Check parent trees explicitly: a 404 alone also means an inaccessible ref or repository.
|
|
24
|
+
const hasTree = (entries: Awaited<ReturnType<typeof list>>, path: string) =>
|
|
25
|
+
entries.some((entry) => entry.type === "tree" && entry.path === path);
|
|
26
|
+
if (
|
|
27
|
+
!hasTree(await list("", ctx.signal), ".gitlab") ||
|
|
28
|
+
!hasTree(await list(".gitlab", ctx.signal), directory)
|
|
29
|
+
)
|
|
30
|
+
return body;
|
|
31
|
+
|
|
32
|
+
const candidates = (await list(directory, ctx.signal)).filter(
|
|
33
|
+
({ path, type, mode }) =>
|
|
34
|
+
type === "blob" &&
|
|
35
|
+
mode !== "120000" &&
|
|
36
|
+
path.startsWith(`${directory}/`) &&
|
|
37
|
+
/^[^/\r\n\0]+\.md$/i.test(path.slice(directory.length + 1)),
|
|
38
|
+
);
|
|
39
|
+
const template =
|
|
40
|
+
candidates.find(({ path }) => path === `${directory}/Default.md`) ??
|
|
41
|
+
(candidates.length === 1 ? candidates[0] : undefined);
|
|
42
|
+
if (!template) {
|
|
43
|
+
if (candidates.length > 1)
|
|
44
|
+
ctx.reportProgress({
|
|
45
|
+
title: "Creating GitLab merge request without a template",
|
|
46
|
+
summary: "Multiple repository templates exist and none is Default.md.",
|
|
47
|
+
steps: [],
|
|
48
|
+
});
|
|
49
|
+
return body;
|
|
50
|
+
}
|
|
51
|
+
const file = await client.getRepositoryFile(projectId, commit.id, template.path, ctx.signal);
|
|
52
|
+
if (file.file_path !== template.path || file.encoding !== "base64")
|
|
53
|
+
throw new Error("Invalid GitLab merge request template response");
|
|
54
|
+
const markdown = new TextDecoder("utf-8", { fatal: true }).decode(
|
|
55
|
+
Buffer.from(file.content, "base64"),
|
|
56
|
+
);
|
|
57
|
+
// Templates are Markdown, not authority to execute GitLab quick actions as the bot.
|
|
58
|
+
const description = markdown.replace(/^(\s*)\/(?=[a-z])/gim, "$1\\/").trimEnd();
|
|
59
|
+
return description ? `${description}\n\n${body}` : body;
|
|
60
|
+
}
|
package/src/publication.ts
CHANGED
|
@@ -165,6 +165,7 @@ export function createGitLabPublicationAdapter<P extends Partial<GitLabPublicati
|
|
|
165
165
|
register: (api, process) => registerGitLabPublicationMaintenance(api, process, adapter),
|
|
166
166
|
},
|
|
167
167
|
namespace,
|
|
168
|
+
prepareSubmodules: true,
|
|
168
169
|
label: "GitLab MR",
|
|
169
170
|
ids: {
|
|
170
171
|
deliver: "deliver_change",
|
package/src/testing.ts
CHANGED
|
@@ -331,8 +331,8 @@ export class LocalGitLabAdapter {
|
|
|
331
331
|
.filter(Boolean)
|
|
332
332
|
.map((line) => {
|
|
333
333
|
const [details, filePath] = line.split("\t");
|
|
334
|
-
const [, type, objectId] = details.split(" ");
|
|
335
|
-
return { path: filePath, type, id: objectId };
|
|
334
|
+
const [mode, type, objectId] = details.split(" ");
|
|
335
|
+
return { path: filePath, type, mode, id: objectId };
|
|
336
336
|
}),
|
|
337
337
|
getRepositoryFile: async (id, ref, filePath) => ({
|
|
338
338
|
file_path: filePath,
|