@mastra/factory 0.29.0-alpha.3 → 0.29.0-alpha.4
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 +4 -4
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +2 -10
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/integrations/dependabot/rules.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +1 -5
- package/dist/integrations/dependabot/rules.js.map +1 -1
- package/dist/integrations/github/commits.d.ts +0 -21
- package/dist/integrations/github/commits.d.ts.map +1 -1
- package/dist/integrations/github/commits.js +1 -24
- package/dist/integrations/github/commits.js.map +1 -1
- package/dist/integrations/github/integration.d.ts +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +2 -6
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +1 -11
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +6 -515
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +59 -10
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/gitlab/discovery.d.ts +1 -1
- package/dist/integrations/gitlab/discovery.js +1 -1
- package/dist/integrations/gitlab/discovery.js.map +1 -1
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +0 -1
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/routes.d.ts +0 -2
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +49 -165
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +20 -7
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/routes.d.ts +5 -5
- package/dist/integrations/incidentio/routes.d.ts.map +1 -1
- package/dist/integrations/incidentio/routes.js +3 -59
- package/dist/integrations/incidentio/routes.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +1 -5
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/routes.d.ts +2 -2
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +0 -68
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +1 -5
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +2 -2
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +0 -83
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +1 -5
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +1 -3
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/routes.d.ts +2 -2
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +0 -69
- package/dist/integrations/platform/jira/routes.js.map +1 -1
- package/dist/integrations/vanta/rules.d.ts.map +1 -1
- package/dist/integrations/vanta/rules.js +1 -5
- package/dist/integrations/vanta/rules.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/routes/automation-runs.d.ts +0 -2
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +2 -6
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/contracts.d.ts +0 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +2 -4
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/fs.d.ts +10 -0
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +184 -11
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +4 -17
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +0 -3
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +0 -19
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +0 -2
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -12
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +1 -5
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +1 -6
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/start-coordinator.js +1 -1
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +0 -2
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +0 -4
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +11 -10
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +30 -65
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/integrations/base.d.ts +0 -2
- package/dist/storage/domains/integrations/base.d.ts.map +1 -1
- package/dist/storage/domains/integrations/base.js +0 -6
- package/dist/storage/domains/integrations/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +0 -12
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +0 -10
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +1 -19
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +1 -6
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +1 -36
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +24 -81
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +12 -3
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +12 -3
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/storage/legacy-collections.d.ts +9 -0
- package/dist/storage/legacy-collections.d.ts.map +1 -0
- package/dist/storage/legacy-collections.js +17 -0
- package/dist/storage/legacy-collections.js.map +1 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +1 -3
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +2 -2
- package/package.json +9 -9
- package/dist/session/filesystem-capture.d.ts +0 -50
- package/dist/session/filesystem-capture.d.ts.map +0 -1
- package/dist/session/filesystem-capture.js +0 -229
- package/dist/session/filesystem-capture.js.map +0 -1
- package/dist/storage/domains/filesystem/base.d.ts +0 -30
- package/dist/storage/domains/filesystem/base.d.ts.map +0 -1
- package/dist/storage/domains/filesystem/base.js +0 -78
- package/dist/storage/domains/filesystem/base.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { loose } from "../../routes/route.js";
|
|
2
|
-
import { sanitizeSegment } from "../../sandbox/workdir.js";
|
|
3
2
|
import { GitLabApiError } from "./api.js";
|
|
4
|
-
import { decodeIssueReference, decodeSourceId,
|
|
3
|
+
import { decodeIssueReference, decodeSourceId, encodeSourceId, gitlabConnection } from "./integration.js";
|
|
5
4
|
import { listMergeRequestSubscriptionsForThread, mergeRequestUrl } from "./subscriptions.js";
|
|
6
5
|
import { handleGitLabWebhook } from "./webhook.js";
|
|
7
6
|
import { registerApiRoute } from "@mastra/core/server";
|
|
@@ -37,7 +36,6 @@ function gitlabProjectPayload(source) {
|
|
|
37
36
|
const projectId = typeof source.metadata?.projectId === "string" ? source.metadata.projectId : null;
|
|
38
37
|
const projectPath = typeof source.metadata?.projectPath === "string" ? source.metadata.projectPath : source.name;
|
|
39
38
|
if (!connectionId || !projectId) return null;
|
|
40
|
-
const repositoryName = projectPath.split("/").filter(Boolean).at(-1) ?? "repo";
|
|
41
39
|
return {
|
|
42
40
|
id: source.id,
|
|
43
41
|
name: source.name,
|
|
@@ -45,23 +43,13 @@ function gitlabProjectPayload(source) {
|
|
|
45
43
|
projectPath,
|
|
46
44
|
connectionId,
|
|
47
45
|
accountLabel: typeof source.metadata?.accountLabel === "string" ? source.metadata.accountLabel : null,
|
|
48
|
-
defaultBranch: typeof source.metadata?.defaultBranch === "string" ? source.metadata.defaultBranch : "main"
|
|
49
|
-
sandboxProvider: "none",
|
|
50
|
-
sandboxWorkdir: `~/${sanitizeSegment(repositoryName)}`
|
|
46
|
+
defaultBranch: typeof source.metadata?.defaultBranch === "string" ? source.metadata.defaultBranch : "main"
|
|
51
47
|
};
|
|
52
48
|
}
|
|
53
49
|
function positiveId(value) {
|
|
54
50
|
const number = Number(value);
|
|
55
51
|
return value && /^[1-9]\d*$/.test(value) && Number.isSafeInteger(number) ? number : null;
|
|
56
52
|
}
|
|
57
|
-
function mergeRequestSourceKey(host, projectId, mergeRequestIid) {
|
|
58
|
-
return `gitlab-pr:${Buffer.from(JSON.stringify({
|
|
59
|
-
version: 1,
|
|
60
|
-
host,
|
|
61
|
-
projectId,
|
|
62
|
-
mergeRequestIid
|
|
63
|
-
}), "utf8").toString("base64url")}`;
|
|
64
|
-
}
|
|
65
53
|
const LINKED_BACKLOG_MAX_PAGES = 5;
|
|
66
54
|
const POLLED_ACTOR = "__factory_poll__";
|
|
67
55
|
function listedMergeRequestEvent(project, pr) {
|
|
@@ -344,10 +332,7 @@ function buildGitLabRoutes(options) {
|
|
|
344
332
|
}
|
|
345
333
|
return c.json({ projects: sources.flatMap((source) => {
|
|
346
334
|
const project = gitlabProjectPayload(source);
|
|
347
|
-
return project ? [
|
|
348
|
-
...project,
|
|
349
|
-
sandboxProvider: options.sandbox ? "custom" : "none"
|
|
350
|
-
}] : [];
|
|
335
|
+
return project ? [project] : [];
|
|
351
336
|
}) });
|
|
352
337
|
} catch (error) {
|
|
353
338
|
return gitlabFetchError(loose(c), error);
|
|
@@ -378,62 +363,12 @@ function buildGitLabRoutes(options) {
|
|
|
378
363
|
});
|
|
379
364
|
return c.json({ project: {
|
|
380
365
|
...project,
|
|
381
|
-
installationStorageId: installation.id
|
|
382
|
-
sandboxProvider: options.sandbox ? "custom" : "none"
|
|
366
|
+
installationStorageId: installation.id
|
|
383
367
|
} });
|
|
384
368
|
} catch (error) {
|
|
385
369
|
return gitlabFetchError(loose(c), error);
|
|
386
370
|
}
|
|
387
371
|
}
|
|
388
|
-
}), registerApiRoute("/web/gitlab/projects/:id/prs", {
|
|
389
|
-
method: "GET",
|
|
390
|
-
requiresAuth: false,
|
|
391
|
-
handler: async (c) => {
|
|
392
|
-
const resolved = await resolveOrgTenant(loose(c), auth);
|
|
393
|
-
if ("response" in resolved) return resolved.response;
|
|
394
|
-
const factoryProjectId = c.req.query("factoryProjectId")?.trim();
|
|
395
|
-
const page = positiveId(c.req.query("page") ?? "1");
|
|
396
|
-
if (!factoryProjectId || !page) return c.json({ error: "invalid_request" }, 400);
|
|
397
|
-
if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
|
|
398
|
-
const linked = await gitlab.getLinkedRepository({
|
|
399
|
-
orgId: resolved.tenant.orgId,
|
|
400
|
-
factoryProjectId,
|
|
401
|
-
projectRepositoryId: c.req.param("id")
|
|
402
|
-
});
|
|
403
|
-
if (!linked) return c.json({ error: "project_repository_not_found" }, 404);
|
|
404
|
-
const projectId = positiveId(linked.repository.externalId);
|
|
405
|
-
if (!projectId) return c.json({ error: "invalid_gitlab_project" }, 502);
|
|
406
|
-
try {
|
|
407
|
-
const target = await gitlab.versionControl.getRepositoryTarget({
|
|
408
|
-
orgId: resolved.tenant.orgId,
|
|
409
|
-
repositoryId: linked.repository.id
|
|
410
|
-
});
|
|
411
|
-
const result = await gitlab.versionControl.listPullRequests({
|
|
412
|
-
...target,
|
|
413
|
-
includeDrafts: false,
|
|
414
|
-
cursor: String(page)
|
|
415
|
-
});
|
|
416
|
-
return c.json({
|
|
417
|
-
pullRequests: result.pullRequests.map((pr) => ({
|
|
418
|
-
number: Number(pr.id),
|
|
419
|
-
externalId: mergeRequestSourceKey(linked.host, projectId, Number(pr.id)),
|
|
420
|
-
title: pr.title,
|
|
421
|
-
url: pr.url,
|
|
422
|
-
author: pr.author,
|
|
423
|
-
assignees: pr.assignees ?? [],
|
|
424
|
-
requestedReviewers: pr.requestedReviewers ?? [],
|
|
425
|
-
labels: pr.labels ?? [],
|
|
426
|
-
baseBranch: pr.baseBranch,
|
|
427
|
-
headBranch: pr.headBranch,
|
|
428
|
-
createdAt: pr.createdAt,
|
|
429
|
-
updatedAt: pr.updatedAt
|
|
430
|
-
})),
|
|
431
|
-
nextPage: result.nextCursor === null ? null : Number(result.nextCursor)
|
|
432
|
-
});
|
|
433
|
-
} catch (error) {
|
|
434
|
-
return gitlabFetchError(loose(c), error);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
372
|
}), registerApiRoute("/web/gitlab/projects/:id/prs/:number", {
|
|
438
373
|
method: "GET",
|
|
439
374
|
requiresAuth: false,
|
|
@@ -478,104 +413,52 @@ function buildGitLabRoutes(options) {
|
|
|
478
413
|
}
|
|
479
414
|
}
|
|
480
415
|
}));
|
|
481
|
-
if (gitlab && auth && intake) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
...issue,
|
|
520
|
-
externalId: encodeIssueReference({
|
|
521
|
-
...source,
|
|
522
|
-
issueIid
|
|
523
|
-
})
|
|
524
|
-
};
|
|
525
|
-
})
|
|
526
|
-
});
|
|
527
|
-
} catch (error) {
|
|
528
|
-
return gitlabFetchError(loose(c), error);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}));
|
|
532
|
-
routes.push(registerApiRoute("/web/gitlab/issues/:issueId", {
|
|
533
|
-
method: "GET",
|
|
534
|
-
requiresAuth: false,
|
|
535
|
-
handler: async (c) => {
|
|
536
|
-
const resolved = await resolveOrgTenant(loose(c), auth);
|
|
537
|
-
if ("response" in resolved) return resolved.response;
|
|
538
|
-
const factoryProjectId = c.req.query("factoryProjectId")?.trim();
|
|
539
|
-
if (!factoryProjectId) return c.json({ error: "invalid_factory_project_id" }, 400);
|
|
540
|
-
if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
|
|
541
|
-
const issueId = c.req.param("issueId")?.trim();
|
|
542
|
-
const issueReference = issueId ? decodeIssueReference(issueId) : null;
|
|
543
|
-
if (!issueReference) return c.json({ error: "invalid_gitlab_issue_id" }, 400);
|
|
544
|
-
const { host, connectionId, projectId, projectPath } = issueReference;
|
|
545
|
-
const sourceId = host ? encodeSourceId({
|
|
546
|
-
host,
|
|
547
|
-
projectId
|
|
548
|
-
}) : encodeSourceId({
|
|
549
|
-
connectionId,
|
|
550
|
-
projectId,
|
|
551
|
-
projectPath
|
|
416
|
+
if (gitlab && auth && intake) routes.push(registerApiRoute("/web/gitlab/issues/:issueId", {
|
|
417
|
+
method: "GET",
|
|
418
|
+
requiresAuth: false,
|
|
419
|
+
handler: async (c) => {
|
|
420
|
+
const resolved = await resolveOrgTenant(loose(c), auth);
|
|
421
|
+
if ("response" in resolved) return resolved.response;
|
|
422
|
+
const factoryProjectId = c.req.query("factoryProjectId")?.trim();
|
|
423
|
+
if (!factoryProjectId) return c.json({ error: "invalid_factory_project_id" }, 400);
|
|
424
|
+
if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
|
|
425
|
+
const issueId = c.req.param("issueId")?.trim();
|
|
426
|
+
const issueReference = issueId ? decodeIssueReference(issueId) : null;
|
|
427
|
+
if (!issueReference) return c.json({ error: "invalid_gitlab_issue_id" }, 400);
|
|
428
|
+
const { host, connectionId, projectId, projectPath } = issueReference;
|
|
429
|
+
const sourceId = host ? encodeSourceId({
|
|
430
|
+
host,
|
|
431
|
+
projectId
|
|
432
|
+
}) : encodeSourceId({
|
|
433
|
+
connectionId,
|
|
434
|
+
projectId,
|
|
435
|
+
projectPath
|
|
436
|
+
});
|
|
437
|
+
await intake.ensureReady();
|
|
438
|
+
const selection = (await intake.getConfig({
|
|
439
|
+
orgId: resolved.tenant.orgId,
|
|
440
|
+
integrationIds: ["gitlab"]
|
|
441
|
+
})).gitlab;
|
|
442
|
+
const selected = new Set(selection.sourceIds ?? []);
|
|
443
|
+
if (!(selection.enabled && selected.has(sourceId) && (await intake.listBindings({
|
|
444
|
+
orgId: resolved.tenant.orgId,
|
|
445
|
+
integrationId: "gitlab"
|
|
446
|
+
})).some((binding) => binding.factoryProjectId === factoryProjectId && binding.sourceId === sourceId))) return c.json({ error: "gitlab_issue_not_routed" }, 404);
|
|
447
|
+
try {
|
|
448
|
+
const issue = await gitlab.intake.getIssue({
|
|
449
|
+
connection: {
|
|
450
|
+
type: "oauth",
|
|
451
|
+
accessToken: "gitlab-route"
|
|
452
|
+
},
|
|
453
|
+
issueId
|
|
552
454
|
});
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
})).gitlab;
|
|
558
|
-
const selected = new Set(selection.sourceIds ?? []);
|
|
559
|
-
if (!(selection.enabled && selected.has(sourceId) && (await intake.listBindings({
|
|
560
|
-
orgId: resolved.tenant.orgId,
|
|
561
|
-
integrationId: "gitlab"
|
|
562
|
-
})).some((binding) => binding.factoryProjectId === factoryProjectId && binding.sourceId === sourceId))) return c.json({ error: "gitlab_issue_not_routed" }, 404);
|
|
563
|
-
try {
|
|
564
|
-
const issue = await gitlab.intake.getIssue({
|
|
565
|
-
connection: {
|
|
566
|
-
type: "oauth",
|
|
567
|
-
accessToken: "gitlab-route"
|
|
568
|
-
},
|
|
569
|
-
issueId
|
|
570
|
-
});
|
|
571
|
-
if (!issue) return c.json({ error: "gitlab_issue_not_found" }, 404);
|
|
572
|
-
return c.json(issue);
|
|
573
|
-
} catch (error) {
|
|
574
|
-
return gitlabFetchError(loose(c), error);
|
|
575
|
-
}
|
|
455
|
+
if (!issue) return c.json({ error: "gitlab_issue_not_found" }, 404);
|
|
456
|
+
return c.json(issue);
|
|
457
|
+
} catch (error) {
|
|
458
|
+
return gitlabFetchError(loose(c), error);
|
|
576
459
|
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
460
|
+
}
|
|
461
|
+
}));
|
|
579
462
|
if (gitlab && auth) routes.push(registerApiRoute("/web/gitlab/subscriptions", {
|
|
580
463
|
method: "GET",
|
|
581
464
|
requiresAuth: false,
|
|
@@ -602,6 +485,7 @@ function buildGitLabRoutes(options) {
|
|
|
602
485
|
repoFullName: subscription.data.projectPath,
|
|
603
486
|
pullRequestNumber: Number(subscription.data.changeRequestId),
|
|
604
487
|
status: subscription.status,
|
|
488
|
+
updatedAt: subscription.updatedAt.toISOString(),
|
|
605
489
|
url: mergeRequestUrl(subscription.data.host, subscription.data.projectPath, subscription.data.changeRequestId)
|
|
606
490
|
})) });
|
|
607
491
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","names":[],"sources":["../../../src/integrations/gitlab/routes.ts"],"sourcesContent":["import type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { FactorySandbox } from '@mastra/core/workspace';\nimport type { Context } from 'hono';\nimport type { IntakeIssue } from '../../capabilities/intake.js';\nimport type { PullRequest } from '../../capabilities/version-control.js';\nimport { loose } from '../../routes/route.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport { sanitizeSegment } from '../../sandbox/workdir.js';\nimport type { AuditEmitter } from '../../storage/domains/audit/domain.js';\nimport type { IntakeStorage } from '../../storage/domains/intake/base.js';\nimport { GitLabApiError } from './api.js';\nimport {\n decodeIssueReference,\n decodeSourceId,\n encodeIssueReference,\n encodeSourceId,\n gitlabConnection,\n} from './integration.js';\nimport type { GitLabIntegrationBase } from './integration.js';\nimport { listMergeRequestSubscriptionsForThread, mergeRequestUrl } from './subscriptions.js';\nimport { handleGitLabWebhook } from './webhook.js';\nimport type { GitLabWebhookHandlerOptions, ParsedGitLabWebhook } from './webhook.js';\n\ntype RouteContext = Context;\n\nexport interface BuildGitLabRoutesOptions {\n gitlab?: GitLabIntegrationBase;\n auth?: RouteAuth;\n intake?: IntakeStorage;\n sandbox?: FactorySandbox;\n emitAudit?: AuditEmitter['emit'];\n webhookSecret?: string;\n ingestFactoryEvent?: (event: ParsedGitLabWebhook) => Promise<unknown>;\n /** Mounted agent controller; enables webhook delivery to subscribed sessions. */\n controller?: GitLabWebhookHandlerOptions['controller'];\n}\n\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized', reason: 'auth_required' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'GitLab intake requires an organization. Personal accounts cannot use GitLab intake.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\nfunction gitlabFetchError(c: RouteContext, error: unknown) {\n if (error instanceof GitLabApiError && error.code === 'gitlab_auth_failed') {\n return c.json({ error: 'gitlab_auth_failed', message: error.message }, 409);\n }\n return c.json({ error: 'gitlab_fetch_failed', message: error instanceof Error ? error.message : String(error) }, 502);\n}\n\ntype GitLabSourceIdentityMigration = { from: string; to: string };\n\nfunction gitlabProjectPayload(source: { id: string; name: string; metadata?: Record<string, unknown> }) {\n const connectionId = typeof source.metadata?.connectionId === 'string' ? source.metadata.connectionId : null;\n const projectId = typeof source.metadata?.projectId === 'string' ? source.metadata.projectId : null;\n const projectPath = typeof source.metadata?.projectPath === 'string' ? source.metadata.projectPath : source.name;\n if (!connectionId || !projectId) return null;\n const repositoryName = projectPath.split('/').filter(Boolean).at(-1) ?? 'repo';\n return {\n id: source.id,\n name: source.name,\n projectId,\n projectPath,\n connectionId,\n accountLabel: typeof source.metadata?.accountLabel === 'string' ? source.metadata.accountLabel : null,\n defaultBranch: typeof source.metadata?.defaultBranch === 'string' ? source.metadata.defaultBranch : 'main',\n sandboxProvider: 'none',\n sandboxWorkdir: `~/${sanitizeSegment(repositoryName)}`,\n };\n}\n\nexport function positiveId(value: string | undefined): number | null {\n const number = Number(value);\n return value && /^[1-9]\\d*$/.test(value) && Number.isSafeInteger(number) ? number : null;\n}\n\nfunction mergeRequestSourceKey(host: string, projectId: number, mergeRequestIid: number): string {\n return `gitlab-pr:${Buffer.from(JSON.stringify({ version: 1, host, projectId, mergeRequestIid }), 'utf8').toString('base64url')}`;\n}\n\nexport const LINKED_BACKLOG_MAX_PAGES = 5;\nconst POLLED_ACTOR = '__factory_poll__';\n\nfunction listedMergeRequestEvent(\n project: { host: string; projectId: number; projectPath: string },\n pr: PullRequest,\n): ParsedGitLabWebhook {\n const iid = Number(pr.id);\n return {\n event: 'Merge Request Hook',\n deliveryId: `poll:merge-request:${project.host}:${project.projectId}:${iid}:${pr.createdAt}`,\n instanceHost: project.host,\n payload: {\n user_username: POLLED_ACTOR,\n project: { id: project.projectId, path_with_namespace: project.projectPath, web_url: `https://${project.host}/${project.projectPath}` },\n object_attributes: {\n iid,\n action: 'open',\n state: 'opened',\n title: pr.title,\n url: pr.url,\n created_at: pr.createdAt,\n updated_at: pr.updatedAt,\n source_branch: pr.headBranch,\n target_branch: pr.baseBranch,\n draft: pr.draft,\n author: pr.author ? { username: pr.author } : undefined,\n assignees: (pr.assignees ?? []).map(username => ({ username })),\n reviewers: (pr.requestedReviewers ?? []).map(username => ({ username })),\n labels: pr.labels ?? [],\n },\n },\n };\n}\n\nexport function listedMergeRequestEvents(\n project: { host: string; projectId: number; projectPath: string },\n pr: PullRequest,\n): ParsedGitLabWebhook[] {\n const opened = listedMergeRequestEvent(project, pr);\n if (!pr.headSha || pr.updatedAt === pr.createdAt) return [opened];\n return [\n opened,\n {\n ...opened,\n deliveryId: `poll:merge-request-head:${project.host}:${project.projectId}:${pr.id}:${pr.updatedAt}:${pr.headSha}`,\n payload: {\n ...opened.payload,\n object_attributes: {\n ...(opened.payload.object_attributes as Record<string, unknown>),\n action: 'update',\n last_commit: { id: pr.headSha },\n },\n },\n },\n ];\n}\n\nexport function listedIssueEvent(issue: IntakeIssue): ParsedGitLabWebhook | null {\n const source = decodeSourceId(issue.sourceId ?? '');\n const projectId = source && positiveId(source.projectId);\n const iid = positiveId(issue.id);\n const projectPath = issue.source || source?.projectPath;\n if (!source?.host || !projectId || !iid || !projectPath) return null;\n return {\n event: 'Issue Hook',\n deliveryId: `poll:issue:${source.host}:${projectId}:${iid}:${issue.createdAt}`,\n instanceHost: source.host,\n payload: {\n user_username: POLLED_ACTOR,\n project: { id: projectId, path_with_namespace: projectPath, web_url: `https://${source.host}/${projectPath}` },\n object_attributes: {\n iid,\n action: 'open',\n state: 'opened',\n title: issue.title,\n url: issue.url,\n created_at: issue.createdAt,\n updated_at: issue.updatedAt,\n author: issue.authorUsername ? { username: issue.authorUsername } : undefined,\n labels: issue.labels ?? [],\n },\n },\n };\n}\n\n/** Ingests listed events and returns the reasons of the ones the rules ingress rejected. */\nexport async function ingestListedEvents(\n events: Array<ParsedGitLabWebhook | null>,\n ingest?: BuildGitLabRoutesOptions['ingestFactoryEvent'],\n): Promise<unknown[]> {\n if (!ingest) return [];\n const listed = events.filter((event): event is ParsedGitLabWebhook => event !== null);\n const openings = listed.filter(event => !event.deliveryId.startsWith('poll:merge-request-head:'));\n const headUpdates = listed.filter(event => event.deliveryId.startsWith('poll:merge-request-head:'));\n const failures: unknown[] = [];\n for (const batch of [openings, headUpdates]) {\n const results = await Promise.allSettled(batch.map(event => ingest(event)));\n const rejected = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');\n if (rejected[0]) {\n console.warn('[Mastra Factory] Failed to ingest listed GitLab events', { error: rejected[0].reason });\n }\n failures.push(...rejected.map(result => result.reason));\n }\n return failures;\n}\n\nexport async function ingestLinkedGitLabRepositoryBacklog(args: {\n gitlab: GitLabIntegrationBase;\n orgId: string;\n projectRepositoryId: string;\n ingestFactoryEvent?: BuildGitLabRoutesOptions['ingestFactoryEvent'];\n}): Promise<void> {\n if (!args.ingestFactoryEvent) return;\n const storage = args.gitlab.sourceControlStorage;\n const link = await storage?.projectRepositories.get({ orgId: args.orgId, id: args.projectRepositoryId });\n if (!link) return;\n const connection = await storage!.connections.get({ orgId: args.orgId, id: link.connectionId });\n if (!connection || connection.integrationId !== 'gitlab') return;\n const linked = await args.gitlab.getLinkedRepository({\n orgId: args.orgId,\n factoryProjectId: connection.factoryProjectId,\n projectRepositoryId: link.id,\n });\n if (!linked) return;\n const projectId = positiveId(linked.repository.externalId);\n if (!projectId) return;\n const project = { host: linked.host, projectId, projectPath: linked.repository.slug };\n const target = await args.gitlab.versionControl.getRepositoryTarget({\n orgId: args.orgId,\n repositoryId: linked.repository.id,\n });\n for (let page = 1; page <= LINKED_BACKLOG_MAX_PAGES; page += 1) {\n const result = await args.gitlab.versionControl.listPullRequests({ ...target, includeDrafts: false, cursor: String(page) });\n await ingestListedEvents(result.pullRequests.flatMap(pr => listedMergeRequestEvents(project, pr)), args.ingestFactoryEvent);\n if (result.nextCursor === null) break;\n }\n const sourceId = encodeSourceId({ host: linked.host, projectId: String(projectId) });\n let cursor: string | undefined;\n for (let page = 1; page <= LINKED_BACKLOG_MAX_PAGES; page += 1) {\n const result = await args.gitlab.intake.listIssues({ connection: target.connection, sourceIds: [sourceId], cursor });\n await ingestListedEvents(result.issues.map(listedIssueEvent), args.ingestFactoryEvent);\n if (result.nextCursor === null) break;\n cursor = result.nextCursor;\n }\n}\n\n/** Selected GitLab sources routed to one Factory, or null when GitLab intake is turned off. */\nexport async function routedGitLabSourceIds(\n intake: IntakeStorage,\n { orgId, factoryProjectId }: { orgId: string; factoryProjectId: string },\n): Promise<string[] | null> {\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId, integrationIds: ['gitlab'] });\n const selection = config.gitlab!;\n if (!selection.enabled) return null;\n const selected = new Set(selection.sourceIds ?? []);\n return [\n ...new Set(\n (await intake.listBindings({ orgId, integrationId: 'gitlab' }))\n .filter(binding => binding.factoryProjectId === factoryProjectId && selected.has(binding.sourceId))\n .map(binding => binding.sourceId),\n ),\n ];\n}\n\nasync function reconcileGitLabSourceIdentity({\n intake,\n orgId,\n sources,\n}: {\n intake: IntakeStorage;\n orgId: string;\n sources: Array<{ id: string; metadata?: Record<string, unknown> }>;\n}): Promise<{ migrations: GitLabSourceIdentityMigration[]; conflicts: GitLabSourceIdentityMigration[] }> {\n await intake.ensureReady();\n const [config, bindings] = await Promise.all([\n intake.getConfig({ orgId }),\n intake.listBindings({ orgId, integrationId: 'gitlab' }),\n ]);\n const selected = config.gitlab?.sourceIds ?? [];\n const canonicalByProject = new Map<string, string[]>();\n for (const source of sources) {\n const reference = decodeSourceId(source.id);\n if (!reference?.host) continue;\n const ids = canonicalByProject.get(reference.projectId) ?? [];\n ids.push(source.id);\n canonicalByProject.set(reference.projectId, ids);\n }\n\n const migrations = new Map<string, string>();\n for (const sourceId of new Set([...selected, ...bindings.map(binding => binding.sourceId)])) {\n const reference = decodeSourceId(sourceId);\n if (!reference || reference.host) continue;\n const candidates = canonicalByProject.get(reference.projectId) ?? [];\n if (candidates.length === 1) migrations.set(sourceId, candidates[0]!);\n }\n return intake.migrateSourceIds({\n orgId,\n integrationId: 'gitlab',\n migrations: [...migrations].map(([from, to]) => ({ from, to })),\n });\n}\n\nexport function buildGitLabRoutes(options: BuildGitLabRoutesOptions): ApiRoute[] {\n const routes: ApiRoute[] = [];\n const { gitlab, auth, intake, emitAudit } = options;\n const enabled = Boolean(gitlab && auth?.enabled());\n\n if (gitlab && auth) {\n routes.push(\n registerApiRoute('/web/gitlab/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const diagnostics = gitlab.diagnostics();\n if (!enabled) {\n return c.json({ enabled: false, configured: true, reauthRequired: false, reason: 'missing_config' });\n }\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n configured: false,\n organizationRequired: true,\n connections: [],\n accounts: [],\n reauthRequired: false,\n reason: 'organization_required',\n });\n }\n\n try {\n await gitlab.verifyStatus();\n const connections = await gitlab.statusConnections();\n const active = connections?.filter(connection => connection.status === 'active');\n const direct = connections === undefined;\n const endpointHost = typeof diagnostics.endpointHost === 'string' ? diagnostics.endpointHost : null;\n const accounts = direct\n ? endpointHost\n ? [endpointHost]\n : []\n : (active ?? []).flatMap(connection => (connection.accountLabel ? [connection.accountLabel] : []));\n const configured = direct || (active?.length ?? 0) > 0;\n return c.json({\n enabled: true,\n configured,\n mode: direct ? 'direct' : 'platform',\n ...(connections ? { connections } : {}),\n accounts,\n reauthRequired: connections?.some(connection => connection.status === 'needs_reauth') ?? false,\n reason: configured ? 'ready' : 'not_connected',\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n try {\n const sources = await gitlab.intake.listSources(resolved.tenant);\n if (intake) {\n const identity = await reconcileGitLabSourceIdentity({\n intake,\n orgId: resolved.tenant.orgId,\n sources,\n });\n if (identity.conflicts.length > 0) {\n return c.json(\n {\n error: 'gitlab_source_identity_conflict',\n message: 'Conflicting routes exist for the same GitLab project. Resolve the duplicate bindings.',\n conflicts: identity.conflicts,\n },\n 409,\n );\n }\n if (identity.migrations.length > 0) {\n await emitAudit?.({\n context: loose(c),\n input: {\n action: 'factory.intake.config_updated',\n targets: identity.migrations.map(migration => ({ type: 'intake_source', id: migration.to })),\n metadata: { provider: 'gitlab', migrated: identity.migrations.length },\n },\n });\n }\n }\n return c.json({\n projects: sources.flatMap(source => {\n const project = gitlabProjectPayload(source);\n return project ? [{ ...project, sandboxProvider: options.sandbox ? 'custom' : 'none' }] : [];\n }),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/registration', {\n method: 'POST',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const input = (await c.req.json().catch(() => null)) as { sourceId?: unknown } | null;\n const sourceId = typeof input?.sourceId === 'string' ? input.sourceId.trim() : '';\n if (!sourceId) return c.json({ error: 'invalid_gitlab_source' }, 400);\n try {\n const source = (await gitlab.intake.listSources(resolved.tenant)).find(\n candidate => candidate.id === sourceId,\n );\n const project = source ? gitlabProjectPayload(source) : null;\n if (!project) return c.json({ error: 'gitlab_project_not_found' }, 404);\n const installation = await gitlab.versionControl.registerInstallation({\n orgId: resolved.tenant.orgId,\n userId: resolved.tenant.userId,\n installation: {\n externalId: project.connectionId,\n accountName: project.accountLabel ?? 'GitLab',\n accountType: 'GitLab',\n metadata: { connection: gitlabConnection(project.connectionId) },\n },\n });\n return c.json({\n project: {\n ...project,\n installationStorageId: installation.id,\n sandboxProvider: options.sandbox ? 'custom' : 'none',\n },\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/:id/prs', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n const page = positiveId(c.req.query('page') ?? '1');\n if (!factoryProjectId || !page) return c.json({ error: 'invalid_request' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId)\n return c.json({ error: 'factory_project_not_found' }, 404);\n const linked = await gitlab.getLinkedRepository({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n projectRepositoryId: c.req.param('id'),\n });\n if (!linked) return c.json({ error: 'project_repository_not_found' }, 404);\n const projectId = positiveId(linked.repository.externalId);\n if (!projectId) return c.json({ error: 'invalid_gitlab_project' }, 502);\n try {\n const target = await gitlab.versionControl.getRepositoryTarget({\n orgId: resolved.tenant.orgId,\n repositoryId: linked.repository.id,\n });\n const result = await gitlab.versionControl.listPullRequests({\n ...target,\n includeDrafts: false,\n cursor: String(page),\n });\n return c.json({\n pullRequests: result.pullRequests.map(pr => ({\n number: Number(pr.id),\n externalId: mergeRequestSourceKey(linked.host, projectId, Number(pr.id)),\n title: pr.title,\n url: pr.url,\n author: pr.author,\n assignees: pr.assignees ?? [],\n requestedReviewers: pr.requestedReviewers ?? [],\n labels: pr.labels ?? [],\n baseBranch: pr.baseBranch,\n headBranch: pr.headBranch,\n createdAt: pr.createdAt,\n updatedAt: pr.updatedAt,\n })),\n nextPage: result.nextCursor === null ? null : Number(result.nextCursor),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/:id/prs/:number', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n const number = positiveId(c.req.param('number'));\n if (!factoryProjectId || !number) return c.json({ error: 'invalid_request' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId)\n return c.json({ error: 'factory_project_not_found' }, 404);\n const linked = await gitlab.getLinkedRepository({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n projectRepositoryId: c.req.param('id'),\n });\n if (!linked) return c.json({ error: 'project_repository_not_found' }, 404);\n try {\n const target = await gitlab.versionControl.getRepositoryTarget({\n orgId: resolved.tenant.orgId,\n repositoryId: linked.repository.id,\n });\n const pr = await gitlab.versionControl.getPullRequest({ ...target, pullRequestId: String(number) });\n if (!pr) return c.json({ error: 'merge_request_not_found' }, 404);\n return c.json({\n number,\n title: pr.title,\n url: pr.url,\n author: pr.author,\n assignees: pr.assignees ?? [],\n requestedReviewers: pr.requestedReviewers ?? [],\n baseBranch: pr.baseBranch,\n headBranch: pr.headBranch,\n createdAt: pr.createdAt,\n updatedAt: pr.updatedAt,\n description: pr.body,\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n }\n\n if (gitlab && auth && intake) {\n routes.push(\n registerApiRoute('/web/gitlab/issues', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n if (!factoryProjectId) return c.json({ error: 'invalid_factory_project_id' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId) {\n return c.json({ error: 'factory_project_not_found' }, 404);\n }\n\n const sourceIds = await routedGitLabSourceIds(intake, { orgId: resolved.tenant.orgId, factoryProjectId });\n if (!sourceIds) {\n return c.json(\n { error: 'gitlab_intake_disabled', message: 'GitLab intake is turned off in Settings.' },\n 404,\n );\n }\n if (sourceIds.length === 0) return c.json({ issues: [], nextCursor: null });\n\n try {\n const result = await gitlab.intake.listIssues({\n connection: { type: 'oauth', accessToken: 'gitlab-route' },\n sourceIds,\n cursor: c.req.query('after')?.trim() || undefined,\n });\n return c.json({\n ...result,\n issues: result.issues.map(issue => {\n const source = decodeSourceId(issue.sourceId ?? '');\n const issueIid = Number(issue.id);\n if (!source || !Number.isSafeInteger(issueIid) || issueIid <= 0) {\n throw new Error('GitLab returned an invalid routed issue reference.');\n }\n return { ...issue, externalId: encodeIssueReference({ ...source, issueIid }) };\n }),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n\n routes.push(\n registerApiRoute('/web/gitlab/issues/:issueId', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n if (!factoryProjectId) return c.json({ error: 'invalid_factory_project_id' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId) {\n return c.json({ error: 'factory_project_not_found' }, 404);\n }\n const issueId = c.req.param('issueId')?.trim();\n const issueReference = issueId ? decodeIssueReference(issueId) : null;\n if (!issueReference) return c.json({ error: 'invalid_gitlab_issue_id' }, 400);\n\n const { host, connectionId, projectId, projectPath } = issueReference;\n const sourceId = host\n ? encodeSourceId({ host, projectId })\n : encodeSourceId({ connectionId, projectId, projectPath });\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['gitlab'] });\n const selection = config.gitlab!;\n const selected = new Set(selection.sourceIds ?? []);\n const routed =\n selection.enabled &&\n selected.has(sourceId) &&\n (await intake.listBindings({ orgId: resolved.tenant.orgId, integrationId: 'gitlab' })).some(\n binding => binding.factoryProjectId === factoryProjectId && binding.sourceId === sourceId,\n );\n if (!routed) return c.json({ error: 'gitlab_issue_not_routed' }, 404);\n\n try {\n const issue = await gitlab.intake.getIssue({\n connection: { type: 'oauth', accessToken: 'gitlab-route' },\n issueId,\n });\n if (!issue) return c.json({ error: 'gitlab_issue_not_found' }, 404);\n return c.json(issue);\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n }\n\n if (gitlab && auth) {\n routes.push(\n registerApiRoute('/web/gitlab/subscriptions', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n // Sessions read by session id; resourceId is the older address.\n const sessionId = c.req.query('sessionId');\n const resourceId = c.req.query('resourceId');\n const threadId = c.req.query('threadId');\n const target = !threadId\n ? null\n : sessionId\n ? { orgId: tenant.orgId, sessionId, threadId }\n : resourceId\n ? { orgId: tenant.orgId, resourceId, threadId }\n : null;\n if (!target) return c.json({ error: 'sessionId (or resourceId) and threadId are required' }, 400);\n\n const subscriptions = await listMergeRequestSubscriptionsForThread(target, gitlab.integrationStorage);\n return c.json({\n subscriptions: subscriptions.map(subscription => ({\n id: subscription.id,\n repoFullName: subscription.data.projectPath,\n pullRequestNumber: Number(subscription.data.changeRequestId),\n status: subscription.status,\n url: mergeRequestUrl(\n subscription.data.host,\n subscription.data.projectPath,\n subscription.data.changeRequestId,\n ),\n })),\n });\n },\n }),\n );\n }\n\n routes.push(\n registerApiRoute('/web/gitlab/webhook', {\n method: 'POST',\n requiresAuth: false,\n handler: async c => {\n const result = await handleGitLabWebhook(loose(c), {\n webhookSecret: options.webhookSecret,\n ingestFactoryEvent: options.ingestFactoryEvent,\n ...(options.controller && gitlab\n ? {\n controller: options.controller,\n gitlab,\n onTargetError: (subscription, error) => {\n console.warn(\n `[GitLab Webhook] Delivery failed for subscription ${subscription.id} (${subscription.resourceId}/${subscription.threadId}).`,\n error,\n );\n },\n }\n : {}),\n });\n return c.json(result.body, result.status);\n },\n }),\n );\n return routes;\n}\n"],"mappings":";;;;;;;;AAsCA,eAAe,iBACb,GACA,MACiF;CACjF,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5B,IAAI,CAAC,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK;EAAE,OAAO;EAAgB,QAAQ;CAAgB,GAAG,GAAG,EAAE;CAChG,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KACV;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF,EACF;CAEF,OAAO,EAAE,QAAQ;EAAE,OAAO,OAAO;EAAO,QAAQ,OAAO;CAAO,EAAE;AAClE;AAEA,SAAS,iBAAiB,GAAiB,OAAgB;CACzD,IAAI,iBAAiB,kBAAkB,MAAM,SAAS,sBACpD,OAAO,EAAE,KAAK;EAAE,OAAO;EAAsB,SAAS,MAAM;CAAQ,GAAG,GAAG;CAE5E,OAAO,EAAE,KAAK;EAAE,OAAO;EAAuB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAAE,GAAG,GAAG;AACtH;AAIA,SAAS,qBAAqB,QAA0E;CACtG,MAAM,eAAe,OAAO,OAAO,UAAU,iBAAiB,WAAW,OAAO,SAAS,eAAe;CACxG,MAAM,YAAY,OAAO,OAAO,UAAU,cAAc,WAAW,OAAO,SAAS,YAAY;CAC/F,MAAM,cAAc,OAAO,OAAO,UAAU,gBAAgB,WAAW,OAAO,SA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C,mBAAmB,OAAO,aAAa,KAAK,eAAe;IAC3D,QAAQ,aAAa;IACrB,KAAK,gBACH,aAAa,KAAK,MAClB,aAAa,KAAK,aAClB,aAAa,KAAK,eACpB;GACF,EAAE,EACJ,CAAC;EACH;CACF,CAAC,CACH;CAGF,OAAO,KACL,iBAAiB,uBAAuB;EACtC,QAAQ;EACR,cAAc;EACd,SAAS,OAAM,MAAK;GAClB,MAAM,SAAS,MAAM,oBAAoB,MAAM,CAAC,GAAG;IACjD,eAAe,QAAQ;IACvB,oBAAoB,QAAQ;IAC5B,GAAI,QAAQ,cAAc,SACtB;KACE,YAAY,QAAQ;KACpB;KACA,gBAAgB,cAAc,UAAU;MACtC,QAAQ,KACN,qDAAqD,aAAa,GAAG,IAAI,aAAa,WAAW,GAAG,aAAa,SAAS,KAC1H,KACF;KACF;IACF,IACA,CAAC;GACP,CAAC;GACD,OAAO,EAAE,KAAK,OAAO,MAAM,OAAO,MAAM;EAC1C;CACF,CAAC,CACH;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"routes.js","names":[],"sources":["../../../src/integrations/gitlab/routes.ts"],"sourcesContent":["import type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\nimport type { IntakeIssue } from '../../capabilities/intake.js';\nimport type { PullRequest } from '../../capabilities/version-control.js';\nimport { loose } from '../../routes/route.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { AuditEmitter } from '../../storage/domains/audit/domain.js';\nimport type { IntakeStorage } from '../../storage/domains/intake/base.js';\nimport { GitLabApiError } from './api.js';\nimport { decodeIssueReference, decodeSourceId, encodeSourceId, gitlabConnection } from './integration.js';\nimport type { GitLabIntegrationBase } from './integration.js';\nimport { listMergeRequestSubscriptionsForThread, mergeRequestUrl } from './subscriptions.js';\nimport { handleGitLabWebhook } from './webhook.js';\nimport type { GitLabWebhookHandlerOptions, ParsedGitLabWebhook } from './webhook.js';\n\ntype RouteContext = Context;\n\nexport interface BuildGitLabRoutesOptions {\n gitlab?: GitLabIntegrationBase;\n auth?: RouteAuth;\n intake?: IntakeStorage;\n emitAudit?: AuditEmitter['emit'];\n webhookSecret?: string;\n ingestFactoryEvent?: (event: ParsedGitLabWebhook) => Promise<unknown>;\n /** Mounted agent controller; enables webhook delivery to subscribed sessions. */\n controller?: GitLabWebhookHandlerOptions['controller'];\n}\n\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized', reason: 'auth_required' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'GitLab intake requires an organization. Personal accounts cannot use GitLab intake.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\nfunction gitlabFetchError(c: RouteContext, error: unknown) {\n if (error instanceof GitLabApiError && error.code === 'gitlab_auth_failed') {\n return c.json({ error: 'gitlab_auth_failed', message: error.message }, 409);\n }\n return c.json({ error: 'gitlab_fetch_failed', message: error instanceof Error ? error.message : String(error) }, 502);\n}\n\ntype GitLabSourceIdentityMigration = { from: string; to: string };\n\nfunction gitlabProjectPayload(source: { id: string; name: string; metadata?: Record<string, unknown> }) {\n const connectionId = typeof source.metadata?.connectionId === 'string' ? source.metadata.connectionId : null;\n const projectId = typeof source.metadata?.projectId === 'string' ? source.metadata.projectId : null;\n const projectPath = typeof source.metadata?.projectPath === 'string' ? source.metadata.projectPath : source.name;\n if (!connectionId || !projectId) return null;\n return {\n id: source.id,\n name: source.name,\n projectId,\n projectPath,\n connectionId,\n accountLabel: typeof source.metadata?.accountLabel === 'string' ? source.metadata.accountLabel : null,\n defaultBranch: typeof source.metadata?.defaultBranch === 'string' ? source.metadata.defaultBranch : 'main',\n };\n}\n\nexport function positiveId(value: string | undefined): number | null {\n const number = Number(value);\n return value && /^[1-9]\\d*$/.test(value) && Number.isSafeInteger(number) ? number : null;\n}\n\nexport const LINKED_BACKLOG_MAX_PAGES = 5;\nconst POLLED_ACTOR = '__factory_poll__';\n\nfunction listedMergeRequestEvent(\n project: { host: string; projectId: number; projectPath: string },\n pr: PullRequest,\n): ParsedGitLabWebhook {\n const iid = Number(pr.id);\n return {\n event: 'Merge Request Hook',\n deliveryId: `poll:merge-request:${project.host}:${project.projectId}:${iid}:${pr.createdAt}`,\n instanceHost: project.host,\n payload: {\n user_username: POLLED_ACTOR,\n project: {\n id: project.projectId,\n path_with_namespace: project.projectPath,\n web_url: `https://${project.host}/${project.projectPath}`,\n },\n object_attributes: {\n iid,\n action: 'open',\n state: 'opened',\n title: pr.title,\n url: pr.url,\n created_at: pr.createdAt,\n updated_at: pr.updatedAt,\n source_branch: pr.headBranch,\n target_branch: pr.baseBranch,\n draft: pr.draft,\n author: pr.author ? { username: pr.author } : undefined,\n assignees: (pr.assignees ?? []).map(username => ({ username })),\n reviewers: (pr.requestedReviewers ?? []).map(username => ({ username })),\n labels: pr.labels ?? [],\n },\n },\n };\n}\n\nexport function listedMergeRequestEvents(\n project: { host: string; projectId: number; projectPath: string },\n pr: PullRequest,\n): ParsedGitLabWebhook[] {\n const opened = listedMergeRequestEvent(project, pr);\n if (!pr.headSha || pr.updatedAt === pr.createdAt) return [opened];\n return [\n opened,\n {\n ...opened,\n deliveryId: `poll:merge-request-head:${project.host}:${project.projectId}:${pr.id}:${pr.updatedAt}:${pr.headSha}`,\n payload: {\n ...opened.payload,\n object_attributes: {\n ...(opened.payload.object_attributes as Record<string, unknown>),\n action: 'update',\n last_commit: { id: pr.headSha },\n },\n },\n },\n ];\n}\n\nexport function listedIssueEvent(issue: IntakeIssue): ParsedGitLabWebhook | null {\n const source = decodeSourceId(issue.sourceId ?? '');\n const projectId = source && positiveId(source.projectId);\n const iid = positiveId(issue.id);\n const projectPath = issue.source || source?.projectPath;\n if (!source?.host || !projectId || !iid || !projectPath) return null;\n return {\n event: 'Issue Hook',\n deliveryId: `poll:issue:${source.host}:${projectId}:${iid}:${issue.createdAt}`,\n instanceHost: source.host,\n payload: {\n user_username: POLLED_ACTOR,\n project: { id: projectId, path_with_namespace: projectPath, web_url: `https://${source.host}/${projectPath}` },\n object_attributes: {\n iid,\n action: 'open',\n state: 'opened',\n title: issue.title,\n url: issue.url,\n created_at: issue.createdAt,\n updated_at: issue.updatedAt,\n author: issue.authorUsername ? { username: issue.authorUsername } : undefined,\n labels: issue.labels ?? [],\n },\n },\n };\n}\n\n/** Ingests listed events and returns the reasons of the ones the rules ingress rejected. */\nexport async function ingestListedEvents(\n events: Array<ParsedGitLabWebhook | null>,\n ingest?: BuildGitLabRoutesOptions['ingestFactoryEvent'],\n): Promise<unknown[]> {\n if (!ingest) return [];\n const listed = events.filter((event): event is ParsedGitLabWebhook => event !== null);\n const openings = listed.filter(event => !event.deliveryId.startsWith('poll:merge-request-head:'));\n const headUpdates = listed.filter(event => event.deliveryId.startsWith('poll:merge-request-head:'));\n const failures: unknown[] = [];\n for (const batch of [openings, headUpdates]) {\n const results = await Promise.allSettled(batch.map(event => ingest(event)));\n const rejected = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');\n if (rejected[0]) {\n console.warn('[Mastra Factory] Failed to ingest listed GitLab events', { error: rejected[0].reason });\n }\n failures.push(...rejected.map(result => result.reason));\n }\n return failures;\n}\n\nexport async function ingestLinkedGitLabRepositoryBacklog(args: {\n gitlab: GitLabIntegrationBase;\n orgId: string;\n projectRepositoryId: string;\n ingestFactoryEvent?: BuildGitLabRoutesOptions['ingestFactoryEvent'];\n}): Promise<void> {\n if (!args.ingestFactoryEvent) return;\n const storage = args.gitlab.sourceControlStorage;\n const link = await storage?.projectRepositories.get({ orgId: args.orgId, id: args.projectRepositoryId });\n if (!link) return;\n const connection = await storage!.connections.get({ orgId: args.orgId, id: link.connectionId });\n if (!connection || connection.integrationId !== 'gitlab') return;\n const linked = await args.gitlab.getLinkedRepository({\n orgId: args.orgId,\n factoryProjectId: connection.factoryProjectId,\n projectRepositoryId: link.id,\n });\n if (!linked) return;\n const projectId = positiveId(linked.repository.externalId);\n if (!projectId) return;\n const project = { host: linked.host, projectId, projectPath: linked.repository.slug };\n const target = await args.gitlab.versionControl.getRepositoryTarget({\n orgId: args.orgId,\n repositoryId: linked.repository.id,\n });\n for (let page = 1; page <= LINKED_BACKLOG_MAX_PAGES; page += 1) {\n const result = await args.gitlab.versionControl.listPullRequests({\n ...target,\n includeDrafts: false,\n cursor: String(page),\n });\n await ingestListedEvents(\n result.pullRequests.flatMap(pr => listedMergeRequestEvents(project, pr)),\n args.ingestFactoryEvent,\n );\n if (result.nextCursor === null) break;\n }\n const sourceId = encodeSourceId({ host: linked.host, projectId: String(projectId) });\n let cursor: string | undefined;\n for (let page = 1; page <= LINKED_BACKLOG_MAX_PAGES; page += 1) {\n const result = await args.gitlab.intake.listIssues({\n connection: target.connection,\n sourceIds: [sourceId],\n cursor,\n });\n await ingestListedEvents(result.issues.map(listedIssueEvent), args.ingestFactoryEvent);\n if (result.nextCursor === null) break;\n cursor = result.nextCursor;\n }\n}\n\n/** Selected GitLab sources routed to one Factory, or null when GitLab intake is turned off. */\nexport async function routedGitLabSourceIds(\n intake: IntakeStorage,\n { orgId, factoryProjectId }: { orgId: string; factoryProjectId: string },\n): Promise<string[] | null> {\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId, integrationIds: ['gitlab'] });\n const selection = config.gitlab!;\n if (!selection.enabled) return null;\n const selected = new Set(selection.sourceIds ?? []);\n return [\n ...new Set(\n (await intake.listBindings({ orgId, integrationId: 'gitlab' }))\n .filter(binding => binding.factoryProjectId === factoryProjectId && selected.has(binding.sourceId))\n .map(binding => binding.sourceId),\n ),\n ];\n}\n\nasync function reconcileGitLabSourceIdentity({\n intake,\n orgId,\n sources,\n}: {\n intake: IntakeStorage;\n orgId: string;\n sources: Array<{ id: string; metadata?: Record<string, unknown> }>;\n}): Promise<{ migrations: GitLabSourceIdentityMigration[]; conflicts: GitLabSourceIdentityMigration[] }> {\n await intake.ensureReady();\n const [config, bindings] = await Promise.all([\n intake.getConfig({ orgId }),\n intake.listBindings({ orgId, integrationId: 'gitlab' }),\n ]);\n const selected = config.gitlab?.sourceIds ?? [];\n const canonicalByProject = new Map<string, string[]>();\n for (const source of sources) {\n const reference = decodeSourceId(source.id);\n if (!reference?.host) continue;\n const ids = canonicalByProject.get(reference.projectId) ?? [];\n ids.push(source.id);\n canonicalByProject.set(reference.projectId, ids);\n }\n\n const migrations = new Map<string, string>();\n for (const sourceId of new Set([...selected, ...bindings.map(binding => binding.sourceId)])) {\n const reference = decodeSourceId(sourceId);\n if (!reference || reference.host) continue;\n const candidates = canonicalByProject.get(reference.projectId) ?? [];\n if (candidates.length === 1) migrations.set(sourceId, candidates[0]!);\n }\n return intake.migrateSourceIds({\n orgId,\n integrationId: 'gitlab',\n migrations: [...migrations].map(([from, to]) => ({ from, to })),\n });\n}\n\nexport function buildGitLabRoutes(options: BuildGitLabRoutesOptions): ApiRoute[] {\n const routes: ApiRoute[] = [];\n const { gitlab, auth, intake, emitAudit } = options;\n const enabled = Boolean(gitlab && auth?.enabled());\n\n if (gitlab && auth) {\n routes.push(\n registerApiRoute('/web/gitlab/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const diagnostics = gitlab.diagnostics();\n if (!enabled) {\n return c.json({ enabled: false, configured: true, reauthRequired: false, reason: 'missing_config' });\n }\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n configured: false,\n organizationRequired: true,\n connections: [],\n accounts: [],\n reauthRequired: false,\n reason: 'organization_required',\n });\n }\n\n try {\n await gitlab.verifyStatus();\n const connections = await gitlab.statusConnections();\n const active = connections?.filter(connection => connection.status === 'active');\n const direct = connections === undefined;\n const endpointHost = typeof diagnostics.endpointHost === 'string' ? diagnostics.endpointHost : null;\n const accounts = direct\n ? endpointHost\n ? [endpointHost]\n : []\n : (active ?? []).flatMap(connection => (connection.accountLabel ? [connection.accountLabel] : []));\n const configured = direct || (active?.length ?? 0) > 0;\n return c.json({\n enabled: true,\n configured,\n mode: direct ? 'direct' : 'platform',\n ...(connections ? { connections } : {}),\n accounts,\n reauthRequired: connections?.some(connection => connection.status === 'needs_reauth') ?? false,\n reason: configured ? 'ready' : 'not_connected',\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n try {\n const sources = await gitlab.intake.listSources(resolved.tenant);\n if (intake) {\n const identity = await reconcileGitLabSourceIdentity({\n intake,\n orgId: resolved.tenant.orgId,\n sources,\n });\n if (identity.conflicts.length > 0) {\n return c.json(\n {\n error: 'gitlab_source_identity_conflict',\n message: 'Conflicting routes exist for the same GitLab project. Resolve the duplicate bindings.',\n conflicts: identity.conflicts,\n },\n 409,\n );\n }\n if (identity.migrations.length > 0) {\n await emitAudit?.({\n context: loose(c),\n input: {\n action: 'factory.intake.config_updated',\n targets: identity.migrations.map(migration => ({ type: 'intake_source', id: migration.to })),\n metadata: { provider: 'gitlab', migrated: identity.migrations.length },\n },\n });\n }\n }\n return c.json({\n projects: sources.flatMap(source => {\n const project = gitlabProjectPayload(source);\n return project ? [project] : [];\n }),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/registration', {\n method: 'POST',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const input = (await c.req.json().catch(() => null)) as { sourceId?: unknown } | null;\n const sourceId = typeof input?.sourceId === 'string' ? input.sourceId.trim() : '';\n if (!sourceId) return c.json({ error: 'invalid_gitlab_source' }, 400);\n try {\n const source = (await gitlab.intake.listSources(resolved.tenant)).find(\n candidate => candidate.id === sourceId,\n );\n const project = source ? gitlabProjectPayload(source) : null;\n if (!project) return c.json({ error: 'gitlab_project_not_found' }, 404);\n const installation = await gitlab.versionControl.registerInstallation({\n orgId: resolved.tenant.orgId,\n userId: resolved.tenant.userId,\n installation: {\n externalId: project.connectionId,\n accountName: project.accountLabel ?? 'GitLab',\n accountType: 'GitLab',\n metadata: { connection: gitlabConnection(project.connectionId) },\n },\n });\n return c.json({\n project: {\n ...project,\n installationStorageId: installation.id,\n },\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/:id/prs/:number', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n const number = positiveId(c.req.param('number'));\n if (!factoryProjectId || !number) return c.json({ error: 'invalid_request' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId)\n return c.json({ error: 'factory_project_not_found' }, 404);\n const linked = await gitlab.getLinkedRepository({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n projectRepositoryId: c.req.param('id'),\n });\n if (!linked) return c.json({ error: 'project_repository_not_found' }, 404);\n try {\n const target = await gitlab.versionControl.getRepositoryTarget({\n orgId: resolved.tenant.orgId,\n repositoryId: linked.repository.id,\n });\n const pr = await gitlab.versionControl.getPullRequest({ ...target, pullRequestId: String(number) });\n if (!pr) return c.json({ error: 'merge_request_not_found' }, 404);\n return c.json({\n number,\n title: pr.title,\n url: pr.url,\n author: pr.author,\n assignees: pr.assignees ?? [],\n requestedReviewers: pr.requestedReviewers ?? [],\n baseBranch: pr.baseBranch,\n headBranch: pr.headBranch,\n createdAt: pr.createdAt,\n updatedAt: pr.updatedAt,\n description: pr.body,\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n }\n\n if (gitlab && auth && intake) {\n routes.push(\n registerApiRoute('/web/gitlab/issues/:issueId', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n if (!factoryProjectId) return c.json({ error: 'invalid_factory_project_id' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId) {\n return c.json({ error: 'factory_project_not_found' }, 404);\n }\n const issueId = c.req.param('issueId')?.trim();\n const issueReference = issueId ? decodeIssueReference(issueId) : null;\n if (!issueReference) return c.json({ error: 'invalid_gitlab_issue_id' }, 400);\n\n const { host, connectionId, projectId, projectPath } = issueReference;\n const sourceId = host\n ? encodeSourceId({ host, projectId })\n : encodeSourceId({ connectionId, projectId, projectPath });\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['gitlab'] });\n const selection = config.gitlab!;\n const selected = new Set(selection.sourceIds ?? []);\n const routed =\n selection.enabled &&\n selected.has(sourceId) &&\n (await intake.listBindings({ orgId: resolved.tenant.orgId, integrationId: 'gitlab' })).some(\n binding => binding.factoryProjectId === factoryProjectId && binding.sourceId === sourceId,\n );\n if (!routed) return c.json({ error: 'gitlab_issue_not_routed' }, 404);\n\n try {\n const issue = await gitlab.intake.getIssue({\n connection: { type: 'oauth', accessToken: 'gitlab-route' },\n issueId,\n });\n if (!issue) return c.json({ error: 'gitlab_issue_not_found' }, 404);\n return c.json(issue);\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n }\n\n if (gitlab && auth) {\n routes.push(\n registerApiRoute('/web/gitlab/subscriptions', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n // Sessions read by session id; resourceId is the older address.\n const sessionId = c.req.query('sessionId');\n const resourceId = c.req.query('resourceId');\n const threadId = c.req.query('threadId');\n const target = !threadId\n ? null\n : sessionId\n ? { orgId: tenant.orgId, sessionId, threadId }\n : resourceId\n ? { orgId: tenant.orgId, resourceId, threadId }\n : null;\n if (!target) return c.json({ error: 'sessionId (or resourceId) and threadId are required' }, 400);\n\n const subscriptions = await listMergeRequestSubscriptionsForThread(target, gitlab.integrationStorage);\n return c.json({\n subscriptions: subscriptions.map(subscription => ({\n id: subscription.id,\n repoFullName: subscription.data.projectPath,\n pullRequestNumber: Number(subscription.data.changeRequestId),\n status: subscription.status,\n updatedAt: subscription.updatedAt.toISOString(),\n url: mergeRequestUrl(\n subscription.data.host,\n subscription.data.projectPath,\n subscription.data.changeRequestId,\n ),\n })),\n });\n },\n }),\n );\n }\n\n routes.push(\n registerApiRoute('/web/gitlab/webhook', {\n method: 'POST',\n requiresAuth: false,\n handler: async c => {\n const result = await handleGitLabWebhook(loose(c), {\n webhookSecret: options.webhookSecret,\n ingestFactoryEvent: options.ingestFactoryEvent,\n ...(options.controller && gitlab\n ? {\n controller: options.controller,\n gitlab,\n onTargetError: (subscription, error) => {\n console.warn(\n `[GitLab Webhook] Delivery failed for subscription ${subscription.id} (${subscription.resourceId}/${subscription.threadId}).`,\n error,\n );\n },\n }\n : {}),\n });\n return c.json(result.body, result.status);\n },\n }),\n );\n return routes;\n}\n"],"mappings":";;;;;;;AA6BA,eAAe,iBACb,GACA,MACiF;CACjF,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5B,IAAI,CAAC,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK;EAAE,OAAO;EAAgB,QAAQ;CAAgB,GAAG,GAAG,EAAE;CAChG,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KACV;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF,EACF;CAEF,OAAO,EAAE,QAAQ;EAAE,OAAO,OAAO;EAAO,QAAQ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MAAM,CAAC,GAAG;IACjD,eAAe,QAAQ;IACvB,oBAAoB,QAAQ;IAC5B,GAAI,QAAQ,cAAc,SACtB;KACE,YAAY,QAAQ;KACpB;KACA,gBAAgB,cAAc,UAAU;MACtC,QAAQ,KACN,qDAAqD,aAAa,GAAG,IAAI,aAAa,WAAW,GAAG,aAAa,SAAS,KAC1H,KACF;KACF;IACF,IACA,CAAC;GACP,CAAC;GACD,OAAO,EAAE,KAAK,OAAO,MAAM,OAAO,MAAM;EAC1C;CACF,CAAC,CACH;CACA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAepE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,KAAK,EAEV,wBAAwB,EAKxB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAepE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,KAAK,EAEV,wB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boards.js";
|
|
5
5
|
import { deploymentOwnsEvent, hasExplicitRuleOverride, routeEventDecision, selectEventRule, withoutRouteEvent } from "../../rules/event-rules.js";
|
|
6
6
|
import { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from "../../rules/validation.js";
|
|
7
|
-
import { WorkItemUpdateConflictError } from "../../storage/domains/work-items/base.js";
|
|
7
|
+
import { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, WorkItemUpdateConflictError } from "../../storage/domains/work-items/base.js";
|
|
8
8
|
import { closingIssueNumbers } from "../closing-references.js";
|
|
9
9
|
import { recordPullRequestHead } from "../pull-request-head.js";
|
|
10
10
|
import { decodeIssueReference, encodeIssueReference, encodeSourceId } from "./integration.js";
|
|
11
11
|
// src/integrations/gitlab/rules.ts
|
|
12
12
|
const RULE_TIMEOUT_MS = 5e3;
|
|
13
|
+
const CARD_SYNC_USER_ID = "factory-rule-dispatcher";
|
|
13
14
|
function settled(result) {
|
|
14
15
|
return result.settled ?? (result.status === "committed" || result.status === "replayed");
|
|
15
16
|
}
|
|
@@ -359,6 +360,22 @@ var GitLabRules = class {
|
|
|
359
360
|
}
|
|
360
361
|
});
|
|
361
362
|
}
|
|
363
|
+
if (event === "mergeRequestOpened" && string(attributes?.action)?.toLowerCase() === "reopen" && reviewItem) {
|
|
364
|
+
const metadata = {
|
|
365
|
+
...reviewItem.workItem.metadata,
|
|
366
|
+
...reviewItem.metadata
|
|
367
|
+
};
|
|
368
|
+
if (metadata.state === "closed") await this.options.storage.syncCard({
|
|
369
|
+
orgId: reviewItem.orgId,
|
|
370
|
+
id: reviewItem.id,
|
|
371
|
+
userId: CARD_SYNC_USER_ID,
|
|
372
|
+
patch: { metadata: {
|
|
373
|
+
state: "open",
|
|
374
|
+
merged: false,
|
|
375
|
+
...metadata["factoryPullRequestReconciliation"] === void 0 ? {} : { [FACTORY_PULL_REQUEST_RECONCILIATION_KEY]: null }
|
|
376
|
+
} }
|
|
377
|
+
});
|
|
378
|
+
}
|
|
362
379
|
const lastCommit = object(mergeRequest?.last_commit);
|
|
363
380
|
const headSha = string(lastCommit?.id)?.toLowerCase();
|
|
364
381
|
const headAt = timestamp(mergeRequest?.updated_at) ?? timestamp(lastCommit?.timestamp);
|
|
@@ -495,7 +512,7 @@ var GitLabRules = class {
|
|
|
495
512
|
await this.options.storage.update({
|
|
496
513
|
orgId: item.orgId,
|
|
497
514
|
id: item.id,
|
|
498
|
-
userId:
|
|
515
|
+
userId: CARD_SYNC_USER_ID,
|
|
499
516
|
expectedRevision: item.revision,
|
|
500
517
|
patch: { metadata: patch }
|
|
501
518
|
});
|
|
@@ -645,11 +662,7 @@ var GitLabRules = class {
|
|
|
645
662
|
orgId: input.orgId,
|
|
646
663
|
factoryProjectId: input.factoryProjectId,
|
|
647
664
|
workItemId: input.item?.id ?? null,
|
|
648
|
-
ingress: {
|
|
649
|
-
identity: input.ingressIdentity,
|
|
650
|
-
triggerType: `gitlab.${input.event}`
|
|
651
|
-
},
|
|
652
|
-
configVersion: this.options.configVersion,
|
|
665
|
+
ingress: { identity: input.ingressIdentity },
|
|
653
666
|
expectedRevision: input.item?.revision ?? null,
|
|
654
667
|
actor: { ...input.actor },
|
|
655
668
|
outcome,
|