@mastra/factory 0.29.0-alpha.4 → 0.29.0-alpha.6
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 +172 -89
- package/dist/boards/board-events.d.ts +89 -9
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +176 -13
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +14 -1
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/busy-card.d.ts +11 -0
- package/dist/boards/busy-card.d.ts.map +1 -0
- package/dist/boards/busy-card.js +15 -0
- package/dist/boards/busy-card.js.map +1 -0
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +18 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/index.d.ts +2 -1
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +3 -2
- package/dist/boards/intake-dry-run.d.ts +109 -0
- package/dist/boards/intake-dry-run.d.ts.map +1 -0
- package/dist/boards/intake-dry-run.js +158 -0
- package/dist/boards/intake-dry-run.js.map +1 -0
- package/dist/boards/intake-lookup.d.ts +32 -0
- package/dist/boards/intake-lookup.d.ts.map +1 -0
- package/dist/boards/intake-lookup.js +12 -0
- package/dist/boards/intake-lookup.js.map +1 -0
- package/dist/boards/intake-order.d.ts +32 -0
- package/dist/boards/intake-order.d.ts.map +1 -0
- package/dist/boards/intake-order.js +60 -0
- package/dist/boards/intake-order.js.map +1 -0
- package/dist/boards/intake-routing.d.ts +246 -35
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +437 -52
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/reroute.d.ts +7 -3
- package/dist/boards/reroute.d.ts.map +1 -1
- package/dist/boards/reroute.js +21 -4
- package/dist/boards/reroute.js.map +1 -1
- package/dist/boards/semantics.d.ts +8 -28
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +14 -40
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work-routes.d.ts +31 -11
- package/dist/boards/work-routes.d.ts.map +1 -1
- package/dist/boards/work-routes.js +104 -20
- package/dist/boards/work-routes.js.map +1 -1
- package/dist/factory.d.ts +37 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +127 -48
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +9 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +1 -1
- package/dist/integrations/dependabot/rules.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +22 -1
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +23 -5
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/intake-lookup.d.ts +16 -0
- package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/github/intake-lookup.js +76 -0
- package/dist/integrations/github/intake-lookup.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +19 -5
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +21 -6
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/issue-intake.d.ts +15 -0
- package/dist/integrations/github/issue-intake.d.ts.map +1 -0
- package/dist/integrations/github/issue-intake.js +50 -0
- package/dist/integrations/github/issue-intake.js.map +1 -0
- package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +10 -1
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/review-status-reporter.js +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +14 -2
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +14 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +221 -30
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +30 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +19 -3
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
- package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/gitlab/intake-lookup.js +85 -0
- package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
- package/dist/integrations/gitlab/integration.d.ts +5 -0
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +21 -1
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +20 -0
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +108 -12
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +14 -4
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +12 -2
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +13 -2
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +43 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +82 -7
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
- package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
- package/dist/integrations/platform/connect/session-tools.js +28 -10
- package/dist/integrations/platform/connect/session-tools.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +9 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +6 -6
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +22 -3
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
- package/dist/integrations/platform/vanta/integration.js +3 -3
- package/dist/integrations/platform/vanta/integration.js.map +1 -1
- package/dist/integrations/pull-request-head.d.ts +1 -1
- package/dist/integrations/pull-request-head.d.ts.map +1 -1
- package/dist/integrations/pull-request-head.js +5 -0
- package/dist/integrations/pull-request-head.js.map +1 -1
- package/dist/integrations/vanta/rules.js +1 -1
- package/dist/integrations/vanta/rules.js.map +1 -1
- package/dist/integrations/vanta/sync.d.ts +9 -0
- package/dist/integrations/vanta/sync.d.ts.map +1 -1
- package/dist/integrations/vanta/sync.js +10 -1
- package/dist/integrations/vanta/sync.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +13 -6
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +42 -20
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts +17 -2
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +247 -77
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +1294 -7
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +603 -20
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/custom-endpoint-url.d.ts +8 -0
- package/dist/routes/custom-endpoint-url.d.ts.map +1 -0
- package/dist/routes/custom-endpoint-url.js +45 -0
- package/dist/routes/custom-endpoint-url.js.map +1 -0
- package/dist/routes/custom-provider-source.d.ts +24 -8
- package/dist/routes/custom-provider-source.d.ts.map +1 -1
- package/dist/routes/custom-provider-source.js +93 -43
- package/dist/routes/custom-provider-source.js.map +1 -1
- package/dist/routes/intake-check.d.ts +92 -0
- package/dist/routes/intake-check.d.ts.map +1 -0
- package/dist/routes/intake-check.js +322 -0
- package/dist/routes/intake-check.js.map +1 -0
- package/dist/routes/intake-routes.d.ts +10 -2
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +292 -11
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/intake.d.ts +6 -0
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +20 -0
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/mastra-gateway.d.ts.map +1 -1
- package/dist/routes/mastra-gateway.js +3 -2
- package/dist/routes/mastra-gateway.js.map +1 -1
- package/dist/routes/project-sessions.d.ts +61 -0
- package/dist/routes/project-sessions.d.ts.map +1 -0
- package/dist/routes/project-sessions.js +135 -0
- package/dist/routes/project-sessions.js.map +1 -0
- package/dist/routes/projects.d.ts +6 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +19 -3
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts +10 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +13 -16
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/run-queue.d.ts +6 -6
- package/dist/routes/run-queue.d.ts.map +1 -1
- package/dist/routes/run-queue.js +28 -8
- package/dist/routes/run-queue.js.map +1 -1
- package/dist/routes/session-rows.d.ts +30 -0
- package/dist/routes/session-rows.d.ts.map +1 -0
- package/dist/routes/session-rows.js +94 -0
- package/dist/routes/session-rows.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +4 -5
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +8 -87
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +16 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +41 -30
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/tenant-credentials.d.ts.map +1 -1
- package/dist/routes/tenant-credentials.js +4 -4
- package/dist/routes/tenant-credentials.js.map +1 -1
- package/dist/routes/work-item-starters.d.ts +1 -0
- package/dist/routes/work-item-starters.d.ts.map +1 -1
- package/dist/routes/work-item-starters.js +14 -2
- package/dist/routes/work-item-starters.js.map +1 -1
- package/dist/routes/work-items.d.ts +22 -3
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +124 -48
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.d.ts +5 -0
- package/dist/rules/binding-context.d.ts.map +1 -1
- package/dist/rules/binding-context.js +51 -5
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatch-errors.js +1 -1
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +39 -7
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +363 -123
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +69 -1
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +151 -5
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/review-source-tool.js +1 -1
- package/dist/rules/rule-group.d.ts +18 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +52 -8
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/run-bearing.d.ts +8 -0
- package/dist/rules/run-bearing.d.ts.map +1 -0
- package/dist/rules/run-bearing.js +11 -0
- package/dist/rules/run-bearing.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +2 -3
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +25 -38
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.js +2 -1
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +16 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +34 -10
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +18 -5
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/update-fold.d.ts +32 -0
- package/dist/rules/update-fold.d.ts.map +1 -0
- package/dist/rules/update-fold.js +60 -0
- package/dist/rules/update-fold.js.map +1 -0
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +54 -6
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts +6 -0
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +17 -0
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +2 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/live-sessions.d.ts +6 -1
- package/dist/session/live-sessions.d.ts.map +1 -1
- package/dist/session/live-sessions.js +4 -0
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/session/resource-migration.d.ts.map +1 -1
- package/dist/session/resource-migration.js +2 -3
- package/dist/session/resource-migration.js.map +1 -1
- package/dist/session/run-audit.d.ts +10 -1
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +9 -1
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +26 -2
- package/dist/session/self-review-gate.d.ts.map +1 -1
- package/dist/session/self-review-gate.js +60 -10
- package/dist/session/self-review-gate.js.map +1 -1
- package/dist/session/session-row-query.d.ts +25 -0
- package/dist/session/session-row-query.d.ts.map +1 -0
- package/dist/session/session-row-query.js +47 -0
- package/dist/session/session-row-query.js.map +1 -0
- package/dist/session/session-row-status.d.ts +16 -0
- package/dist/session/session-row-status.d.ts.map +1 -0
- package/dist/session/session-row-status.js +14 -0
- package/dist/session/session-row-status.js.map +1 -0
- package/dist/session/session-row-view.d.ts +13 -0
- package/dist/session/session-row-view.d.ts.map +1 -0
- package/dist/session/session-row-view.js +118 -0
- package/dist/session/session-row-view.js.map +1 -0
- package/dist/session/session-rows.d.ts +60 -0
- package/dist/session/session-rows.d.ts.map +1 -0
- package/dist/session/session-rows.js +307 -0
- package/dist/session/session-rows.js.map +1 -0
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js +1 -0
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/session-unloader.d.ts +101 -0
- package/dist/session/session-unloader.d.ts.map +1 -0
- package/dist/session/session-unloader.js +278 -0
- package/dist/session/session-unloader.js.map +1 -0
- package/dist/session/source-control-tools.d.ts +14 -7
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +10 -2
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/work-item-repository.d.ts +49 -1
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +118 -15
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/session/work-item-state-processor.d.ts.map +1 -1
- package/dist/session/work-item-state-processor.js +44 -8
- package/dist/session/work-item-state-processor.js.map +1 -1
- package/dist/session-list-changes.d.ts +9 -0
- package/dist/session-list-changes.d.ts.map +1 -0
- package/dist/session-list-changes.js +54 -0
- package/dist/session-list-changes.js.map +1 -0
- package/dist/storage/announced-lists.d.ts +14 -0
- package/dist/storage/announced-lists.d.ts.map +1 -0
- package/dist/storage/announced-lists.js +78 -0
- package/dist/storage/announced-lists.js.map +1 -0
- package/dist/storage/domains/audit/actions.d.ts +2 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +3 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +163 -15
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +440 -48
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts +6 -0
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +95 -1
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.d.ts +62 -19
- package/dist/storage/domains/custom-providers/base.d.ts.map +1 -1
- package/dist/storage/domains/custom-providers/base.js +131 -100
- package/dist/storage/domains/custom-providers/base.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +25 -7
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +83 -19
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +19 -10
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +8 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +110 -61
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +4 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +8 -5
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +57 -18
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +168 -83
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +3 -2
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +4 -2
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/tools/audit-events-tool.d.ts +2 -2
- package/dist/tools/read-tools.d.ts +9 -5
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +61 -54
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/session-tools.d.ts +0 -13
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +128 -341
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts +3 -0
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +99 -27
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +4 -0
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +7 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-context-sessions.d.ts +50 -0
- package/dist/work-items/card-context-sessions.d.ts.map +1 -0
- package/dist/work-items/card-context-sessions.js +84 -0
- package/dist/work-items/card-context-sessions.js.map +1 -0
- package/dist/work-items/card-reference.d.ts +21 -0
- package/dist/work-items/card-reference.d.ts.map +1 -0
- package/dist/work-items/card-reference.js +58 -0
- package/dist/work-items/card-reference.js.map +1 -0
- package/dist/work-items/change-requests.d.ts +87 -0
- package/dist/work-items/change-requests.d.ts.map +1 -0
- package/dist/work-items/change-requests.js +134 -0
- package/dist/work-items/change-requests.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +7 -2
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +44 -13
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/list-related-cards.d.ts.map +1 -1
- package/dist/work-items/list-related-cards.js +1 -1
- package/dist/work-items/list-related-cards.js.map +1 -1
- package/dist/work-items/providers/github.d.ts.map +1 -1
- package/dist/work-items/providers/github.js +1 -0
- package/dist/work-items/providers/github.js.map +1 -1
- package/factory-skills/factory-build/SKILL.md +1 -1
- package/factory-skills/factory-plan/SKILL.md +5 -3
- package/factory-skills/factory-self-review/SKILL.md +2 -0
- package/factory-skills/factory-triage/SKILL.md +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/gitlab/default-rules.ts"],"sourcesContent":["import {\n isPullRequestCard,\n newestOpenPullRequestNumber,\n pullRequestSources,\n reviewedPullRequest,\n reviewsPullRequest,\n sourceExternalId,\n} from '../../boards/index.js';\nimport {\n closedByRoutes,\n pullRequestMoveByRoutes,\n recordExplicitRuleOverrides,\n routedOnly,\n unreviewedPullRequestCard,\n} from '../../rules/event-rules.js';\nimport type { FactoryGitLabEventName, FactoryGitLabRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';\n\nexport type GitLabRuleOverrides = Partial<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null | undefined>\n>;\nexport type GitLabEventRules = Readonly<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null>\n>;\n\nfunction actorUsername(context: Pick<FactoryGitLabRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'gitlab' ? context.actor.username : undefined;\n}\n\nfunction trustedGitLabActor(context: Pick<FactoryGitLabRuleContext, 'actor'>): boolean {\n return context.actor.type === 'gitlab' && context.actor.trusted;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * The card whose session authored the merge request, as opposed to the merge request's own card,\n * on a board that reviews merge requests.\n */\nfunction authoringCard(context: FactoryGitLabRuleContext): boolean {\n return (\n context.flow?.pullRequestReview !== undefined && context.item !== undefined && !isPullRequestCard(context.item)\n );\n}\n\n/** Whether the card sits in its board's pull request review phase, alone. */\nfunction inPullRequestReview(context: FactoryGitLabRuleContext): boolean {\n const phase = context.flow?.pullRequestReview;\n return phase !== undefined && context.item?.stages.length === 1 && context.item.stages[0] === phase;\n}\n\n/** Whether the rule's card carries the event's merge request as one of its sources, attached to its issue. */\nfunction attachedMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const { item, mergeRequest } = context;\n if (!item || !mergeRequest || isPullRequestCard(item)) return false;\n return pullRequestSources(item).some(source => isEventMergeRequest(context, source));\n}\n\n/**\n * Whether a source row is the event's merge request. Iids repeat across GitLab projects, so\n * the row's full key (host, project and iid) has to match, not the iid alone.\n */\nfunction isEventMergeRequest(context: FactoryGitLabRuleContext, source: WorkItemSourceRow): boolean {\n return (\n context.mergeRequest !== undefined &&\n source.integrationId === 'gitlab' &&\n sourceExternalId(source) === context.mergeRequest.sourceKey\n );\n}\n\n/** Whether the merge request the card's PR review covers is the event's merge request. */\nfunction reviewsThisMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const reviewed = context.item ? reviewedPullRequest(context.item) : undefined;\n return reviewed !== undefined && isEventMergeRequest(context, reviewed);\n}\n\nfunction issueOpened(context: FactoryGitLabRuleContext) {\n if (!context.issue || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake.board,\n source: 'gitlab-issue',\n sourceKey: context.issue.sourceKey,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake.initialPhase,\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabIssueIid: context.issue.number,\n identifier: `${context.repository.fullName}#${context.issue.number}`,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...((context.issue.author ?? actorUsername(context))\n ? { author: context.issue.author ?? actorUsername(context) }\n : {}),\n authorTrusted: context.issue.authorTrusted,\n autoStartCandidate:\n trustedGitLabActor(context) &&\n context.issue.authorTrusted &&\n createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n labelColors: context.issue.labelColors ?? {},\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || context.item.source !== 'gitlab-issue') return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // GitLab reports no close reason, so every closure counts as completed.\n return closedByRoutes(false, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: closure.completed.phase,\n message: {\n text: `GitLab issue #${context.issue?.number ?? ''} was closed; this ${closure.boardTitle} card was moved to ${closure.completed.title}.`,\n },\n });\n}\n\nfunction materializeMergeRequest(context: FactoryGitLabRuleContext) {\n if (!context.mergeRequest || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:merge-request-intake`,\n board: context.intake.board,\n source: 'gitlab-pr',\n sourceKey: context.mergeRequest.sourceKey,\n title: context.mergeRequest.title,\n url: context.mergeRequest.url,\n stage: context.intake.initialPhase,\n // A merge request for a card already on the board is filed on that card. For one that closes\n // an issue on the board, the project's intake routes decide whether it joins that card.\n ...(context.pullRequestHome\n ? context.pullRequestHome.reason === 'closes'\n ? { closesIssue: { workItemId: context.pullRequestHome.workItemId } }\n : { attachTo: { workItemId: context.pullRequestHome.workItemId } }\n : {}),\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabMergeRequestIid: context.mergeRequest.number,\n ...(context.mergeRequest.createdAt ? { sourceCreatedAt: context.mergeRequest.createdAt } : {}),\n factoryAuthored: context.mergeRequest.factoryAuthored,\n authorTrusted: context.mergeRequest.authorTrusted,\n autoStartCandidate:\n ((trustedGitLabActor(context) && context.mergeRequest.authorTrusted) || context.mergeRequest.factoryAuthored) &&\n createdAfterFactory(context.mergeRequest.createdAt, context.factory.createdAt),\n state: context.mergeRequest.state,\n draft: context.mergeRequest.draft,\n merged: context.mergeRequest.merged,\n assignees: context.mergeRequest.assignees ?? [],\n requestedReviewers: context.mergeRequest.reviewers ?? [],\n labels: context.mergeRequest.labels ?? [],\n labelColors: context.mergeRequest.labelColors ?? {},\n headBranch: context.mergeRequest.headBranch,\n baseBranch: context.mergeRequest.baseBranch,\n ...(context.mergeRequest.author ? { author: context.mergeRequest.author } : {}),\n },\n } as const;\n}\n\nfunction mergeRequestUpdated(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !reviewsPullRequest(context)) return;\n if (!context.mergeRequest || context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n const stage = context.flow?.pullRequestReview;\n if (!stage) return;\n const reviewing = inPullRequestReview(context);\n // An issue card re-reviews only while its PR review covers this merge request.\n if (\n context.item.source !== 'gitlab-pr' &&\n !(\n attachedMergeRequest(context) &&\n reviewing &&\n reviewsThisMergeRequest(context)\n )\n )\n return;\n // A resting card has not started a review pass yet.\n if (context.phase?.kind === 'resting') return;\n // An untrusted push must not start review passes on demand.\n if (!trustedGitLabActor(context) && !context.mergeRequest.factoryAuthored) return;\n return pullRequestMoveByRoutes('pull_request.synchronized', {\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: context.board,\n stage,\n ...(reviewing ? { reenter: true } : {}),\n });\n}\n\nfunction mergeRequestCommented(context: FactoryGitLabRuleContext) {\n const role = context.flow?.buildRole;\n if (!context.item || !context.mergeRequest || !context.note || !authoringCard(context) || !role) return;\n // Someone else's merge request attached to the issue is not the builder's to fix.\n if (attachedMergeRequest(context) && !context.mergeRequest.factoryAuthored) return;\n if (context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n if (context.actor.type === 'gitlab' && context.actor.factoryAuthored) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-merge-request-comment`,\n role,\n priority: 'high',\n message:\n `${context.note.author ?? 'Someone'} commented on GitLab merge request !${context.mergeRequest.number} ` +\n `(${context.note.url ?? context.mergeRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the merge-request branch. Reply in GitLab to anything you are deliberately not changing.',\n } as const;\n}\n\nfunction mergeRequestMerged(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest?.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.merged');\n const done = context.boardClosure?.completed ?? context.flow?.completed;\n if (isPullRequestCard(context.item) && reviewsPullRequest(context)) {\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:merge-request-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this merge request card was moved to ${done.title}.`,\n },\n });\n }\n if (!authoringCard(context)) return;\n const role = context.flow?.buildRole;\n // A merge request on the card itself finishes the work, unless another one it carries is still out.\n if (attachedMergeRequest(context)) {\n const recorded = context.item.metadata?.openPullRequestNumber;\n const open =\n typeof recorded === 'number' && recorded !== context.mergeRequest.number\n ? recorded\n : newestOpenPullRequestNumber(context.item, context.mergeRequest.number);\n if (typeof open === 'number' && open !== context.mergeRequest.number) {\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Merge request !${open} is still open, ` +\n 'so this card stays where it is until it merges.',\n } as const;\n }\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this card was moved to ${done.title}.`,\n },\n });\n }\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:assess-work-completion`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Assess whether the linked work item is complete. ` +\n 'Do not move it to a finished phase solely because this merge request merged.',\n } as const;\n}\n\nfunction mergeRequestClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest || context.mergeRequest.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.closed');\n if (!reviewsPullRequest(context)) return;\n if (!isPullRequestCard(context.item)) {\n // An issue card waiting in pull request review on its last open merge request goes back to\n // where its board's cards rest.\n const initialPhase = context.flow?.initialPhase;\n if (!initialPhase || !attachedMergeRequest(context) || !inPullRequestReview(context)) return;\n if (newestOpenPullRequestNumber(context.item, context.mergeRequest.number) !== null) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: initialPhase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} was closed without merging; this card was moved back to ${initialPhase}.`,\n },\n });\n }\n const canceled = context.boardClosure?.canceled ?? context.flow?.canceled;\n if (!canceled) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: canceled.phase,\n message: {\n text:\n `GitLab merge request !${context.mergeRequest.number} was closed without merging; ` +\n `this merge request card was moved to ${canceled.title}.`,\n },\n });\n}\n\nexport const defaultGitLabRules = Object.freeze({\n issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueUpdated: null,\n issueClosed,\n // A reopen files a card when the issue has none, as an open does. A card the issue already has\n // is left to the project's intake routes.\n issueReopened: context => (context.item ? undefined : issueOpened(context)),\n issueCommented: null,\n mergeRequestOpened: materializeMergeRequest,\n mergeRequestUpdated,\n mergeRequestCommented,\n mergeRequestMerged,\n mergeRequestClosed,\n} satisfies GitLabEventRules);\n\nexport function resolveGitLabRules(overrides?: GitLabRuleOverrides): GitLabEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitLab rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGitLabRuleContext> | null> = { ...defaultGitLabRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGitLabRules, key)) {\n throw new Error(`Unknown GitLab rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGitLabEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitLab rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GitLabEventRules, overrides);\n}\n"],"mappings":";;;;;AAyBA,SAAS,cAAc,SAAsE;CAC3F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,WAAW,KAAA;AACpE;AAEA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,oBAAoB,WAA+B,kBAAmC;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,kBAAkB,KAAK,MAAM,SAAS;CAC5C,MAAM,mBAAmB,KAAK,MAAM,gBAAgB;CACpD,OAAO,OAAO,SAAS,eAAe,KAAK,OAAO,SAAS,gBAAgB,KAAK,kBAAkB;AACpG;;;;;AAMA,SAAS,cAAc,SAA4C;CACjE,OACE,QAAQ,MAAM,sBAAsB,KAAA,KAAa,QAAQ,SAAS,KAAA,KAAa,CAAC,kBAAkB,QAAQ,IAAI;AAElH;;AAGA,SAAS,oBAAoB,SAA4C;CACvE,MAAM,QAAQ,QAAQ,MAAM;CAC5B,OAAO,UAAU,KAAA,KAAa,QAAQ,MAAM,OAAO,WAAW,KAAK,QAAQ,KAAK,OAAO,OAAO;AAChG;;AAGA,SAAS,qBAAqB,SAA4C;CACxE,MAAM,EAAE,MAAM,iBAAiB;CAC/B,IAAI,CAAC,QAAQ,CAAC,gBAAgB,kBAAkB,IAAI,GAAG,OAAO;CAC9D,OAAO,mBAAmB,IAAI,CAAC,CAAC,MAAK,WAAU,oBAAoB,SAAS,MAAM,CAAC;AACrF;;;;;AAMA,SAAS,oBAAoB,SAAmC,QAAoC;CAClG,OACE,QAAQ,iBAAiB,KAAA,KACzB,OAAO,kBAAkB,YACzB,iBAAiB,MAAM,MAAM,QAAQ,aAAa;AAEtD;;AAGA,SAAS,wBAAwB,SAA4C;CAC3E,M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4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
|
|
1
|
+
{"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/gitlab/default-rules.ts"],"sourcesContent":["import {\n isPullRequestCard,\n isOpenPullRequestSource,\n pullRequestSourceNumber,\n workingPullRequest,\n pullRequestSources,\n reviewedPullRequest,\n reviewsPullRequest,\n sourceExternalId,\n trustedPullRequestSource,\n} from '../../boards/index.js';\nimport {\n closedByRoutes,\n pullRequestMoveByRoutes,\n recordExplicitRuleOverrides,\n routedOnly,\n unreviewedPullRequestCard,\n} from '../../rules/event-rules.js';\nimport type { FactoryGitLabEventName, FactoryGitLabRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';\n\nexport type GitLabRuleOverrides = Partial<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null | undefined>\n>;\nexport type GitLabEventRules = Readonly<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null>\n>;\n\nfunction actorUsername(context: Pick<FactoryGitLabRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'gitlab' ? context.actor.username : undefined;\n}\n\nfunction trustedGitLabActor(context: Pick<FactoryGitLabRuleContext, 'actor'>): boolean {\n return context.actor.type === 'gitlab' && context.actor.trusted;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * The card whose session authored the merge request, as opposed to the merge request's own card,\n * on a board that reviews merge requests.\n */\nfunction authoringCard(context: FactoryGitLabRuleContext): boolean {\n return (\n context.flow?.pullRequestReview !== undefined && context.item !== undefined && !isPullRequestCard(context.item)\n );\n}\n\n/** Whether the card sits in its board's pull request review phase, alone. */\nfunction inPullRequestReview(context: FactoryGitLabRuleContext): boolean {\n const phase = context.flow?.pullRequestReview;\n return phase !== undefined && context.item?.stages.length === 1 && context.item.stages[0] === phase;\n}\n\n/** Whether the rule's card carries the event's merge request as one of its sources, attached to its issue. */\nfunction attachedMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const { item, mergeRequest } = context;\n if (!item || !mergeRequest || isPullRequestCard(item)) return false;\n return pullRequestSources(item).some(source => isEventMergeRequest(context, source));\n}\n\n/**\n * Whether the event's merge request is an outsider's linked to the card that no person picked as\n * its working merge request: what happens to it settles nothing about the card.\n */\nfunction unpickedOutsiderMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const { item } = context;\n if (!item || !attachedMergeRequest(context) || context.mergeRequest?.factoryAuthored) return false;\n const source = pullRequestSources(item).find(candidate => isEventMergeRequest(context, candidate))!;\n if (trustedPullRequestSource(item, source)) return false;\n const working = workingPullRequest(item);\n return working === undefined || !isEventMergeRequest(context, working);\n}\n\n/**\n * Whether a source row is the event's merge request. Iids repeat across GitLab projects, so\n * the row's full key (host, project and iid) has to match, not the iid alone.\n */\nfunction isEventMergeRequest(context: FactoryGitLabRuleContext, source: WorkItemSourceRow): boolean {\n return (\n context.mergeRequest !== undefined &&\n source.integrationId === 'gitlab' &&\n sourceExternalId(source) === context.mergeRequest.sourceKey\n );\n}\n\n/** Whether the merge request the card's PR review covers is the event's merge request. */\nfunction reviewsThisMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const reviewed = context.item ? reviewedPullRequest(context.item) : undefined;\n return reviewed !== undefined && isEventMergeRequest(context, reviewed);\n}\n\nfunction issueOpened(context: FactoryGitLabRuleContext) {\n if (!context.issue || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake.board,\n source: 'gitlab-issue',\n sourceKey: context.issue.sourceKey,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake.initialPhase,\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabIssueIid: context.issue.number,\n identifier: `${context.repository.fullName}#${context.issue.number}`,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...((context.issue.author ?? actorUsername(context))\n ? { author: context.issue.author ?? actorUsername(context) }\n : {}),\n authorTrusted: context.issue.authorTrusted,\n autoStartCandidate:\n trustedGitLabActor(context) &&\n context.issue.authorTrusted &&\n createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n labelColors: context.issue.labelColors ?? {},\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || context.item.source !== 'gitlab-issue') return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // GitLab reports no close reason, so every closure counts as completed.\n return closedByRoutes(false, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: closure.completed.phase,\n message: {\n text: `GitLab issue #${context.issue?.number ?? ''} was closed; this ${closure.boardTitle} card was moved to ${closure.completed.title}.`,\n },\n });\n}\n\nfunction materializeMergeRequest(context: FactoryGitLabRuleContext) {\n if (!context.mergeRequest || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:merge-request-intake`,\n board: context.intake.board,\n source: 'gitlab-pr',\n sourceKey: context.mergeRequest.sourceKey,\n title: context.mergeRequest.title,\n url: context.mergeRequest.url,\n stage: context.intake.initialPhase,\n // A merge request for a card already on the board is filed on that card. One that closes an\n // issue on the board links to that card.\n ...(context.pullRequestHome\n ? context.pullRequestHome.reason === 'closes'\n ? { closesIssue: { workItemId: context.pullRequestHome.workItemId } }\n : { attachTo: { workItemId: context.pullRequestHome.workItemId } }\n : {}),\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabMergeRequestIid: context.mergeRequest.number,\n ...(context.mergeRequest.createdAt ? { sourceCreatedAt: context.mergeRequest.createdAt } : {}),\n factoryAuthored: context.mergeRequest.factoryAuthored,\n authorTrusted: context.mergeRequest.authorTrusted,\n autoStartCandidate:\n ((trustedGitLabActor(context) && context.mergeRequest.authorTrusted) || context.mergeRequest.factoryAuthored) &&\n createdAfterFactory(context.mergeRequest.createdAt, context.factory.createdAt),\n state: context.mergeRequest.state,\n draft: context.mergeRequest.draft,\n merged: context.mergeRequest.merged,\n assignees: context.mergeRequest.assignees ?? [],\n requestedReviewers: context.mergeRequest.reviewers ?? [],\n labels: context.mergeRequest.labels ?? [],\n labelColors: context.mergeRequest.labelColors ?? {},\n headBranch: context.mergeRequest.headBranch,\n baseBranch: context.mergeRequest.baseBranch,\n ...(context.mergeRequest.author ? { author: context.mergeRequest.author } : {}),\n },\n } as const;\n}\n\nfunction mergeRequestUpdated(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !reviewsPullRequest(context)) return;\n if (!context.mergeRequest || context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n const stage = context.flow?.pullRequestReview;\n if (!stage) return;\n const reviewing = inPullRequestReview(context);\n // An issue card re-reviews only while its PR review covers this merge request.\n if (\n context.item.source !== 'gitlab-pr' &&\n !(\n attachedMergeRequest(context) &&\n reviewing &&\n reviewsThisMergeRequest(context)\n )\n )\n return;\n // A resting card has not started a review pass yet.\n if (context.phase?.kind === 'resting') return;\n // An untrusted push must not start review passes on demand.\n if (!trustedGitLabActor(context) && !context.mergeRequest.factoryAuthored) return;\n return pullRequestMoveByRoutes('pull_request.synchronized', {\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: context.board,\n stage,\n ...(reviewing ? { reenter: true } : {}),\n });\n}\n\nfunction mergeRequestCommented(context: FactoryGitLabRuleContext) {\n const role = context.flow?.buildRole;\n if (!context.item || !context.mergeRequest || !context.note || !authoringCard(context) || !role) return;\n // Someone else's merge request attached to the issue is not the builder's to fix.\n if (attachedMergeRequest(context) && !context.mergeRequest.factoryAuthored) return;\n if (context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n if (context.actor.type === 'gitlab' && context.actor.factoryAuthored) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-merge-request-comment`,\n role,\n priority: 'high',\n message:\n `${context.note.author ?? 'Someone'} commented on GitLab merge request !${context.mergeRequest.number} ` +\n `(${context.note.url ?? context.mergeRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the merge-request branch. Reply in GitLab to anything you are deliberately not changing.',\n } as const;\n}\n\nfunction mergeRequestMerged(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest?.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.merged');\n const done = context.boardClosure?.completed ?? context.flow?.completed;\n if (isPullRequestCard(context.item) && reviewsPullRequest(context)) {\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:merge-request-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this merge request card was moved to ${done.title}.`,\n },\n });\n }\n if (!authoringCard(context)) return;\n const role = context.flow?.buildRole;\n // A merge request on the card itself finishes the work, unless another one it carries is still out.\n if (attachedMergeRequest(context)) {\n const recorded = context.item.metadata?.openPullRequestNumber;\n const working = workingPullRequest(context.item);\n const open =\n typeof recorded === 'number' && recorded !== context.mergeRequest.number\n ? recorded\n : working && isOpenPullRequestSource(working)\n ? pullRequestSourceNumber(working)\n : undefined;\n if (typeof open === 'number' && open !== context.mergeRequest.number) {\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Merge request !${open} is still open, ` +\n 'so this card stays where it is until it merges.',\n } as const;\n }\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this card was moved to ${done.title}.`,\n },\n });\n }\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:assess-work-completion`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Assess whether the linked work item is complete. ` +\n 'Do not move it to a finished phase solely because this merge request merged.',\n } as const;\n}\n\nfunction mergeRequestClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest || context.mergeRequest.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.closed');\n if (!reviewsPullRequest(context)) return;\n if (!isPullRequestCard(context.item)) {\n // An issue card waiting in pull request review on its last open merge request goes back to\n // where its board's cards rest.\n const initialPhase = context.flow?.initialPhase;\n if (!initialPhase || !attachedMergeRequest(context) || !inPullRequestReview(context)) return;\n if (unpickedOutsiderMergeRequest(context)) return;\n const other = workingPullRequest(context.item, context.mergeRequest.number);\n if (other && isOpenPullRequestSource(other)) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: initialPhase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} was closed without merging; this card was moved back to ${initialPhase}.`,\n },\n });\n }\n const canceled = context.boardClosure?.canceled ?? context.flow?.canceled;\n if (!canceled) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: canceled.phase,\n message: {\n text:\n `GitLab merge request !${context.mergeRequest.number} was closed without merging; ` +\n `this merge request card was moved to ${canceled.title}.`,\n },\n });\n}\n\nexport const defaultGitLabRules = Object.freeze({\n issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueUpdated: null,\n issueClosed,\n // A reopen files a card when the issue has none, as an open does. A card the issue already has\n // is left to the project's intake routes.\n issueReopened: context => (context.item ? undefined : issueOpened(context)),\n issueCommented: null,\n mergeRequestOpened: materializeMergeRequest,\n mergeRequestUpdated,\n mergeRequestCommented,\n mergeRequestMerged,\n mergeRequestClosed,\n} satisfies GitLabEventRules);\n\nexport function resolveGitLabRules(overrides?: GitLabRuleOverrides): GitLabEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitLab rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGitLabRuleContext> | null> = { ...defaultGitLabRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGitLabRules, key)) {\n throw new Error(`Unknown GitLab rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGitLabEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitLab rule ${key} must be a function, null, or undefined.`);\n }\n if (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,WAAW,QAAQ,cAAc,YAAY,QAAQ,MAAM;CACjE,IAAI,CAAC,UAAU;CACf,OAAO,wBAAwB,uBAAuB;EACpD,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,QAAQ;EACf,OAAO,SAAS;EAChB,SAAS,EACP,MACE,yBAAyB,QAAQ,aAAa,OAAO,oEACb,SAAS,MAAM,GAC3D;CACF,CAAC;AACH;AAEA,MAAa,qBAAqB,OAAO,OAAO;CAC9C;CAGA,cAAc;CACd;CAGA,gBAAe,YAAY,QAAQ,OAAO,KAAA,IAAY,YAAY,OAAO;CACzE,gBAAgB;CAChB,oBAAoB;CACpB;CACA;CACA;CACA;AACF,CAA4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IntakeItemLookup } from '../../boards/intake-lookup.js';
|
|
2
|
+
import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
|
|
3
|
+
import type { GitLabIssue, GitLabMergeRequest } from './api.js';
|
|
4
|
+
export interface GitLabIntakeLookupDeps {
|
|
5
|
+
sourceControl(): SourceControlStorageHandle | undefined;
|
|
6
|
+
readWorkItem(connectionId: string, projectId: string, kind: 'issue' | 'merge_request', iid: number): Promise<GitLabIssue | GitLabMergeRequest>;
|
|
7
|
+
getProjectMemberAccessLevel(connectionId: string, projectId: string, username: string): Promise<number | undefined>;
|
|
8
|
+
/** The connection to read `host` through: in direct-token mode, the direct one rather than the link's stored id. */
|
|
9
|
+
resolveConnection(storedConnectionId: string, host: string): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Reads a GitLab issue or merge request for the intake tester, only from a project linked to the
|
|
13
|
+
* Factory project on the URL's host and only through that link's connection. It builds the facts
|
|
14
|
+
* the webhook arrival would carry, with author trust from the author's project access.
|
|
15
|
+
*/
|
|
16
|
+
export declare function gitlabIntakeLookup(deps: GitLabIntakeLookupDeps): IntakeItemLookup;
|
|
17
|
+
//# sourceMappingURL=intake-lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intake-lookup.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/intake-lookup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMhE,MAAM,WAAW,sBAAsB;IACrC,aAAa,IAAI,0BAA0B,GAAG,SAAS,CAAC;IACxD,YAAY,CACV,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,OAAO,GAAG,eAAe,EAC/B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,WAAW,GAAG,kBAAkB,CAAC,CAAC;IAC7C,2BAA2B,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACpH,oHAAoH;IACpH,iBAAiB,CAAC,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9E;AAMD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,CA8EjF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { cardRuleFacts } from "../../boards/card-facts.js";
|
|
2
|
+
import { externalSourceForWorkItem } from "../../rules/types.js";
|
|
3
|
+
import { encodeIssueReference, normalizeGitLabHost } from "./integration.js";
|
|
4
|
+
import { mergeRequestSourceKey } from "./rules.js";
|
|
5
|
+
// src/integrations/gitlab/intake-lookup.ts
|
|
6
|
+
const GITLAB_ITEM_URL = /^https?:\/\/([^/]+)\/(.+?)\/-\/(issues|work_items|merge_requests)\/(\d+)(?:[/?#].*)?$/i;
|
|
7
|
+
function usernames(users) {
|
|
8
|
+
return (users ?? []).map((user) => user.username).filter((name) => Boolean(name));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reads a GitLab issue or merge request for the intake tester, only from a project linked to the
|
|
12
|
+
* Factory project on the URL's host and only through that link's connection. It builds the facts
|
|
13
|
+
* the webhook arrival would carry, with author trust from the author's project access.
|
|
14
|
+
*/
|
|
15
|
+
function gitlabIntakeLookup(deps) {
|
|
16
|
+
return { async lookup(scope, url) {
|
|
17
|
+
const match = GITLAB_ITEM_URL.exec(url.trim());
|
|
18
|
+
if (!match) return void 0;
|
|
19
|
+
const [, rawHost = "", rawPath = "", type = "", digits = ""] = match;
|
|
20
|
+
const host = normalizeGitLabHost(rawHost);
|
|
21
|
+
const path = rawPath.toLowerCase();
|
|
22
|
+
const kind = type.toLowerCase() === "merge_requests" ? "merge_request" : "issue";
|
|
23
|
+
const iid = Number(digits);
|
|
24
|
+
const sourceControl = deps.sourceControl();
|
|
25
|
+
const linked = (sourceControl ? await sourceControl.connections.listWithRepositories({
|
|
26
|
+
orgId: scope.orgId,
|
|
27
|
+
factoryProjectIds: [scope.factoryProjectId]
|
|
28
|
+
}) : []).filter((connection) => {
|
|
29
|
+
const linkedHost = connection.installation.providerMetadata.host;
|
|
30
|
+
return typeof linkedHost === "string" && normalizeGitLabHost(linkedHost) === host;
|
|
31
|
+
}).flatMap((connection) => connection.repositories.map((link) => ({
|
|
32
|
+
installation: connection.installation,
|
|
33
|
+
repository: link.repository
|
|
34
|
+
}))).find(({ repository }) => repository?.slug.toLowerCase() === path);
|
|
35
|
+
if (!linked?.repository) return { status: "not_linked" };
|
|
36
|
+
const connectionId = await deps.resolveConnection(linked.installation.externalId, host);
|
|
37
|
+
const projectId = linked.repository.externalId;
|
|
38
|
+
const item = await deps.readWorkItem(connectionId, projectId, kind, iid).catch(() => void 0);
|
|
39
|
+
if (!item) return { status: "not_found" };
|
|
40
|
+
const author = item.author?.username;
|
|
41
|
+
const trusted = author ? (await deps.getProjectMemberAccessLevel(connectionId, projectId, author).catch(() => void 0) ?? 0) >= 30 : false;
|
|
42
|
+
const shared = {
|
|
43
|
+
gitlabHost: host,
|
|
44
|
+
gitlabProjectId: Number(projectId),
|
|
45
|
+
...author ? { author } : {},
|
|
46
|
+
authorTrusted: trusted,
|
|
47
|
+
assignees: usernames(item.assignees),
|
|
48
|
+
labels: item.labels ?? []
|
|
49
|
+
};
|
|
50
|
+
const mergeRequest = "source_branch" in item ? item : null;
|
|
51
|
+
const metadata = mergeRequest ? {
|
|
52
|
+
...shared,
|
|
53
|
+
gitlabMergeRequestIid: iid,
|
|
54
|
+
state: mergeRequest.state === "opened" || mergeRequest.state === "locked" ? "open" : "closed",
|
|
55
|
+
draft: mergeRequest.draft ?? mergeRequest.work_in_progress ?? false,
|
|
56
|
+
merged: mergeRequest.state === "merged",
|
|
57
|
+
requestedReviewers: usernames(mergeRequest.reviewers),
|
|
58
|
+
headBranch: mergeRequest.source_branch,
|
|
59
|
+
baseBranch: mergeRequest.target_branch
|
|
60
|
+
} : {
|
|
61
|
+
...shared,
|
|
62
|
+
gitlabIssueIid: iid,
|
|
63
|
+
identifier: `${linked.repository.slug}#${iid}`,
|
|
64
|
+
state: item.state === "closed" ? "closed" : "open"
|
|
65
|
+
};
|
|
66
|
+
const sourceKey = mergeRequest ? mergeRequestSourceKey(host, Number(projectId), iid) : encodeIssueReference({
|
|
67
|
+
host,
|
|
68
|
+
projectId,
|
|
69
|
+
issueIid: iid
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
status: "found",
|
|
73
|
+
title: item.title,
|
|
74
|
+
url: item.web_url,
|
|
75
|
+
facts: cardRuleFacts({
|
|
76
|
+
title: item.title,
|
|
77
|
+
metadata,
|
|
78
|
+
externalSource: externalSourceForWorkItem(mergeRequest ? "gitlab-pr" : "gitlab-issue", sourceKey, item.web_url)
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
} };
|
|
82
|
+
}
|
|
83
|
+
export { gitlabIntakeLookup };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=intake-lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intake-lookup.js","names":[],"sources":["../../../src/integrations/gitlab/intake-lookup.ts"],"sourcesContent":["import { cardRuleFacts } from '../../boards/card-facts.js';\nimport type { IntakeItemLookup } from '../../boards/intake-lookup.js';\nimport { externalSourceForWorkItem } from '../../rules/types.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { GitLabIssue, GitLabMergeRequest } from './api.js';\nimport { encodeIssueReference, GITLAB_TRUSTED_ACCESS_LEVEL, normalizeGitLabHost } from './integration.js';\nimport { mergeRequestSourceKey } from './rules.js';\n\nconst GITLAB_ITEM_URL = /^https?:\\/\\/([^/]+)\\/(.+?)\\/-\\/(issues|work_items|merge_requests)\\/(\\d+)(?:[/?#].*)?$/i;\n\nexport interface GitLabIntakeLookupDeps {\n sourceControl(): SourceControlStorageHandle | undefined;\n readWorkItem(\n connectionId: string,\n projectId: string,\n kind: 'issue' | 'merge_request',\n iid: number,\n ): Promise<GitLabIssue | GitLabMergeRequest>;\n getProjectMemberAccessLevel(connectionId: string, projectId: string, username: string): Promise<number | undefined>;\n /** The connection to read `host` through: in direct-token mode, the direct one rather than the link's stored id. */\n resolveConnection(storedConnectionId: string, host: string): Promise<string>;\n}\n\nfunction usernames(users: ReadonlyArray<{ username?: string }> | undefined): string[] {\n return (users ?? []).map(user => user.username).filter((name): name is string => Boolean(name));\n}\n\n/**\n * Reads a GitLab issue or merge request for the intake tester, only from a project linked to the\n * Factory project on the URL's host and only through that link's connection. It builds the facts\n * the webhook arrival would carry, with author trust from the author's project access.\n */\nexport function gitlabIntakeLookup(deps: GitLabIntakeLookupDeps): IntakeItemLookup {\n return {\n async lookup(scope, url) {\n const match = GITLAB_ITEM_URL.exec(url.trim());\n if (!match) return undefined;\n const [, rawHost = '', rawPath = '', type = '', digits = ''] = match;\n const host = normalizeGitLabHost(rawHost);\n const path = rawPath.toLowerCase();\n const kind = type.toLowerCase() === 'merge_requests' ? 'merge_request' : 'issue';\n const iid = Number(digits);\n const sourceControl = deps.sourceControl();\n const connections = sourceControl\n ? await sourceControl.connections.listWithRepositories({\n orgId: scope.orgId,\n factoryProjectIds: [scope.factoryProjectId],\n })\n : [];\n const linked = connections\n .filter(connection => {\n const linkedHost = connection.installation.providerMetadata.host;\n return typeof linkedHost === 'string' && normalizeGitLabHost(linkedHost) === host;\n })\n .flatMap(connection =>\n connection.repositories.map(link => ({ installation: connection.installation, repository: link.repository })),\n )\n .find(({ repository }) => repository?.slug.toLowerCase() === path);\n if (!linked?.repository) return { status: 'not_linked' };\n const connectionId = await deps.resolveConnection(linked.installation.externalId, host);\n const projectId = linked.repository.externalId;\n\n const item = await deps.readWorkItem(connectionId, projectId, kind, iid).catch(() => undefined);\n if (!item) return { status: 'not_found' };\n const author = item.author?.username;\n const trusted = author\n ? ((await deps.getProjectMemberAccessLevel(connectionId, projectId, author).catch(() => undefined)) ?? 0) >=\n GITLAB_TRUSTED_ACCESS_LEVEL\n : false;\n const shared = {\n gitlabHost: host,\n gitlabProjectId: Number(projectId),\n ...(author ? { author } : {}),\n authorTrusted: trusted,\n assignees: usernames(item.assignees),\n labels: item.labels ?? [],\n };\n const mergeRequest = 'source_branch' in item ? item : null;\n const metadata: Record<string, unknown> = mergeRequest\n ? {\n ...shared,\n gitlabMergeRequestIid: iid,\n state: mergeRequest.state === 'opened' || mergeRequest.state === 'locked' ? 'open' : 'closed',\n draft: mergeRequest.draft ?? mergeRequest.work_in_progress ?? false,\n merged: mergeRequest.state === 'merged',\n requestedReviewers: usernames(mergeRequest.reviewers),\n headBranch: mergeRequest.source_branch,\n baseBranch: mergeRequest.target_branch,\n }\n : {\n ...shared,\n gitlabIssueIid: iid,\n identifier: `${linked.repository.slug}#${iid}`,\n state: item.state === 'closed' ? 'closed' : 'open',\n };\n const sourceKey = mergeRequest\n ? mergeRequestSourceKey(host, Number(projectId), iid)\n : encodeIssueReference({ host, projectId, issueIid: iid });\n return {\n status: 'found',\n title: item.title,\n url: item.web_url,\n facts: cardRuleFacts({\n title: item.title,\n metadata,\n externalSource: externalSourceForWorkItem(mergeRequest ? 'gitlab-pr' : 'gitlab-issue', sourceKey, item.web_url),\n }),\n };\n },\n };\n}\n"],"mappings":";;;;;AAQA,MAAM,kBAAkB;AAexB,SAAS,UAAU,OAAmE;CACpF,QAAQ,SAAS,CAAC,EAAA,CAAG,KAAI,SAAQ,KAAK,QAAQ,CAAC,CAAC,QAAQ,SAAyB,QAAQ,IAAI,CAAC;AAChG;;;;;;AAOA,SAAgB,mBAAmB,MAAgD;CACjF,OAAO,EACL,MAAM,OAAO,OAAO,KAAK;EACvB,MAAM,QAAQ,gBAAgB,KAAK,IAAI,KAAK,CAAC;EAC7C,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,MAAM,GAAG,UAAU,IAAI,UAAU,IAAI,OAAO,IAAI,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,eAAe,mBAAmB,OAAO,OAAO;EACtD,MAAM,WAAoC,eACtC;GACE,GAAG;GACH,uBAAuB;GACvB,OAAO,aAAa,UAAU,YAAY,aAAa,UAAU,WAAW,SAAS;GACrF,OAAO,aAAa,SAAS,aAAa,oBAAoB;GAC9D,QAAQ,aAAa,UAAU;GAC/B,oBAAoB,UAAU,aAAa,SAAS;GACpD,YAAY,aAAa;GACzB,YAAY,aAAa;EAC3B,IACA;GACE,GAAG;GACH,gBAAgB;GAChB,YAAY,GAAG,OAAO,WAAW,KAAK,GAAG;GACzC,OAAO,KAAK,UAAU,WAAW,WAAW;EAC9C;EACJ,MAAM,YAAY,eACd,sBAAsB,MAAM,OAAO,SAAS,GAAG,GAAG,IAClD,qBAAqB;GAAE;GAAM;GAAW,UAAU;EAAI,CAAC;EAC3D,OAAO;GACL,QAAQ;GACR,OAAO,KAAK;GACZ,KAAK,KAAK;GACV,OAAO,cAAc;IACnB,OAAO,KAAK;IACZ;IACA,gBAAgB,0BAA0B,eAAe,cAAc,gBAAgB,WAAW,KAAK,OAAO;GAChH,CAAC;EACH;CACF,EACF;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
2
2
|
import type { ApiRoute } from '@mastra/core/server';
|
|
3
3
|
import type { MastraWorker } from '@mastra/core/worker';
|
|
4
|
+
import type { IntakeItemLookup } from '../../boards/intake-lookup.js';
|
|
4
5
|
import type { IntegrationConnection } from '../../capabilities/connection.js';
|
|
5
6
|
import type { Intake, IntakeIssueDetail } from '../../capabilities/intake.js';
|
|
6
7
|
import type { RouteAuth } from '../../routes/route.js';
|
|
@@ -9,6 +10,7 @@ import type { FactoryProjectsStorage } from '../../storage/domains/projects/base
|
|
|
9
10
|
import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
|
|
10
11
|
import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';
|
|
11
12
|
import { GitLabApiClient } from './api.js';
|
|
13
|
+
import type { GitLabIssue, GitLabMergeRequest } from './api.js';
|
|
12
14
|
import type { GitLabEventRules, GitLabRuleOverrides } from './default-rules.js';
|
|
13
15
|
import type { GitLabSubscriptionStorage } from './subscriptions.js';
|
|
14
16
|
interface GitLabConnectionContext {
|
|
@@ -52,6 +54,7 @@ export declare abstract class GitLabIntegrationBase implements FactoryIntegratio
|
|
|
52
54
|
readonly rules: GitLabEventRules;
|
|
53
55
|
constructor(rules?: GitLabRuleOverrides);
|
|
54
56
|
readonly intake: Intake;
|
|
57
|
+
readonly intakeLookup: IntakeItemLookup;
|
|
55
58
|
readonly versionControl: import("../../capabilities/version-control.js").VersionControl;
|
|
56
59
|
initialize({ storage, projects, auth, sourceControl, }: {
|
|
57
60
|
storage?: IntegrationStorageHandle;
|
|
@@ -82,6 +85,8 @@ export declare abstract class GitLabIntegrationBase implements FactoryIntegratio
|
|
|
82
85
|
} | null>;
|
|
83
86
|
getProjectMemberAccessLevel(connectionId: string, projectId: string, username: string): Promise<number | undefined>;
|
|
84
87
|
getWorkItemAuthorUsername(connectionId: string, projectId: string, kind: 'issue' | 'merge_request', iid: number): Promise<string | undefined>;
|
|
88
|
+
readWorkItem(connectionId: string, projectId: string, kind: 'issue' | 'merge_request', iid: number): Promise<GitLabIssue | GitLabMergeRequest>;
|
|
89
|
+
getCurrentUsername(connectionId: string): Promise<string | undefined>;
|
|
85
90
|
isProjectMemberTrustedForSource(sourceId: string, username: string): Promise<boolean>;
|
|
86
91
|
getIssueForFactoryProject(input: {
|
|
87
92
|
orgId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,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IAAI,OAAO,CAAC,OAAO,CAAC,CAE7C;IAEc,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3C;IAED,kBAAkB,IAAI,MAAM,CAE3B;IAED,UAAgB,cAAc,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAEnE;IAED,UAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAKlF;IAED,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQrC;CACF;AAQD,wBAAgB,cAAc,CAAC,SAAS,EAAE,qBAAqB,GAAG,MAAM,CAYvE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAE1E;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAa5E;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAE/E;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,2BAA2B,GAAG,IAAI,CAE7F;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,qBAAqB,CAE5E;AAqBD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -2,6 +2,7 @@ import { IssueReconcileWorker } from "../issue-reconcile-worker.js";
|
|
|
2
2
|
import { buildGitLabAgentTools } from "./agent-tools.js";
|
|
3
3
|
import { GitLabApiClient, GitLabApiError } from "./api.js";
|
|
4
4
|
import { resolveGitLabRules } from "./default-rules.js";
|
|
5
|
+
import { gitlabIntakeLookup } from "./intake-lookup.js";
|
|
5
6
|
import { attachGitLabReconciler } from "./reconciler.js";
|
|
6
7
|
import { gitlabReconciliationInterval } from "./reconciliation-config.js";
|
|
7
8
|
import { buildGitLabRoutes, ingestLinkedGitLabRepositoryBacklog } from "./routes.js";
|
|
@@ -25,6 +26,7 @@ var GitLabIntegrationBase = class {
|
|
|
25
26
|
#auth;
|
|
26
27
|
#ingestFactoryEvent;
|
|
27
28
|
#orgIdByResourceId = /* @__PURE__ */ new Map();
|
|
29
|
+
#currentUsernames = /* @__PURE__ */ new Map();
|
|
28
30
|
rules;
|
|
29
31
|
constructor(rules) {
|
|
30
32
|
this.rules = resolveGitLabRules(rules);
|
|
@@ -38,6 +40,12 @@ var GitLabIntegrationBase = class {
|
|
|
38
40
|
createComment: (input) => this.#createComment(input),
|
|
39
41
|
updateIssue: (input) => this.#updateIssue(input)
|
|
40
42
|
};
|
|
43
|
+
intakeLookup = gitlabIntakeLookup({
|
|
44
|
+
sourceControl: () => this.#sourceControl,
|
|
45
|
+
readWorkItem: (connectionId, projectId, kind, iid) => this.readWorkItem(connectionId, projectId, kind, iid),
|
|
46
|
+
getProjectMemberAccessLevel: (connectionId, projectId, username) => this.getProjectMemberAccessLevel(connectionId, projectId, username),
|
|
47
|
+
resolveConnection: (storedConnectionId, host) => this.resolveActiveConnectionForHost(storedConnectionId, host)
|
|
48
|
+
});
|
|
41
49
|
versionControl = buildGitLabVersionControl({
|
|
42
50
|
contextForConnection: (connection) => this.#versionControlContext(connection),
|
|
43
51
|
contextForStoredInstallation: (connection, host) => this.#versionControlContextForInstallation(connection, host)
|
|
@@ -121,8 +129,20 @@ var GitLabIntegrationBase = class {
|
|
|
121
129
|
return (await (await this.contextById(connectionId)).api.listProjectMembers(projectId, { query: username })).find((candidate) => candidate.username.toLowerCase() === normalized && candidate.state !== "blocked")?.access_level;
|
|
122
130
|
}
|
|
123
131
|
async getWorkItemAuthorUsername(connectionId, projectId, kind, iid) {
|
|
132
|
+
return (await this.readWorkItem(connectionId, projectId, kind, iid)).author?.username;
|
|
133
|
+
}
|
|
134
|
+
async readWorkItem(connectionId, projectId, kind, iid) {
|
|
124
135
|
const api = (await this.contextById(connectionId)).api;
|
|
125
|
-
return
|
|
136
|
+
return kind === "issue" ? api.getIssue(projectId, iid) : api.getMergeRequest(projectId, iid);
|
|
137
|
+
}
|
|
138
|
+
async getCurrentUsername(connectionId) {
|
|
139
|
+
let username = this.#currentUsernames.get(connectionId);
|
|
140
|
+
if (!username) {
|
|
141
|
+
username = (async () => (await (await this.contextById(connectionId)).api.getCurrentUser()).username)();
|
|
142
|
+
this.#currentUsernames.set(connectionId, username);
|
|
143
|
+
username.catch(() => this.#currentUsernames.delete(connectionId));
|
|
144
|
+
}
|
|
145
|
+
return username;
|
|
126
146
|
}
|
|
127
147
|
async isProjectMemberTrustedForSource(sourceId, username) {
|
|
128
148
|
const reference = decodeSourceId(sourceId);
|