@mastra/factory 0.28.0-alpha.9 → 0.29.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -46
- package/dist/boards/board-writes.d.ts +3 -3
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +24 -20
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/project-boards.d.ts +20 -0
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +35 -11
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/boards/registry.d.ts.map +1 -1
- package/dist/boards/registry.js +0 -3
- package/dist/boards/registry.js.map +1 -1
- package/dist/boards/reroute.d.ts +31 -0
- package/dist/boards/reroute.d.ts.map +1 -0
- package/dist/boards/reroute.js +71 -0
- package/dist/boards/reroute.js.map +1 -0
- package/dist/capabilities/version-control.d.ts +6 -1
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/environment/build-runner.d.ts +13 -2
- package/dist/environment/build-runner.d.ts.map +1 -1
- package/dist/environment/build-runner.js +42 -0
- package/dist/environment/build-runner.js.map +1 -1
- package/dist/environment/build-schedule.js +1 -1
- package/dist/environment/build-schedule.js.map +1 -1
- package/dist/environment/build-workflow.d.ts +6 -4
- package/dist/environment/build-workflow.d.ts.map +1 -1
- package/dist/environment/build-workflow.js +70 -66
- package/dist/environment/build-workflow.js.map +1 -1
- package/dist/environment/build.d.ts +22 -7
- package/dist/environment/build.d.ts.map +1 -1
- package/dist/environment/build.js +73 -15
- package/dist/environment/build.js.map +1 -1
- package/dist/environment/heads.d.ts +1 -1
- package/dist/environment/heads.d.ts.map +1 -1
- package/dist/environment/heads.js +4 -1
- package/dist/environment/heads.js.map +1 -1
- package/dist/environment/repository-access.d.ts +15 -0
- package/dist/environment/repository-access.d.ts.map +1 -0
- package/dist/environment/repository-access.js +60 -0
- package/dist/environment/repository-access.js.map +1 -0
- package/dist/factory.d.ts +5 -2
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +40 -30
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +8 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/default-rules.d.ts +38 -0
- package/dist/integrations/dependabot/default-rules.d.ts.map +1 -0
- package/dist/integrations/dependabot/default-rules.js +63 -0
- package/dist/integrations/dependabot/default-rules.js.map +1 -0
- package/dist/integrations/dependabot/rules.d.ts +42 -0
- package/dist/integrations/dependabot/rules.d.ts.map +1 -0
- package/dist/integrations/dependabot/rules.js +187 -0
- package/dist/integrations/dependabot/rules.js.map +1 -0
- package/dist/integrations/dependabot/sync.d.ts +76 -0
- package/dist/integrations/dependabot/sync.d.ts.map +1 -0
- package/dist/integrations/dependabot/sync.js +111 -0
- package/dist/integrations/dependabot/sync.js.map +1 -0
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +7 -2
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox-release.d.ts +12 -0
- package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
- package/dist/integrations/github/sandbox-release.js +16 -1
- package/dist/integrations/github/sandbox-release.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +12 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +22 -1
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +4 -0
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.d.ts +5 -0
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +33 -2
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +19 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +183 -105
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
- package/dist/integrations/platform/jira/integration.js +5 -1
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/vanta/integration.d.ts +33 -0
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -0
- package/dist/integrations/platform/vanta/integration.js +133 -0
- package/dist/integrations/platform/vanta/integration.js.map +1 -0
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +7 -4
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/vanta/default-rules.d.ts +34 -0
- package/dist/integrations/vanta/default-rules.d.ts.map +1 -0
- package/dist/integrations/vanta/default-rules.js +61 -0
- package/dist/integrations/vanta/default-rules.js.map +1 -0
- package/dist/integrations/vanta/rules.d.ts +40 -0
- package/dist/integrations/vanta/rules.d.ts.map +1 -0
- package/dist/integrations/vanta/rules.js +208 -0
- package/dist/integrations/vanta/rules.js.map +1 -0
- package/dist/integrations/vanta/sync.d.ts +36 -0
- package/dist/integrations/vanta/sync.d.ts.map +1 -0
- package/dist/integrations/vanta/sync.js +73 -0
- package/dist/integrations/vanta/sync.js.map +1 -0
- package/dist/mcp/routes.d.ts.map +1 -1
- package/dist/mcp/routes.js +3 -5
- package/dist/mcp/routes.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +24 -1
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +75 -7
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/boards.d.ts +2 -3
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/contracts.d.ts +307 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +253 -9
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake-routes.d.ts +3 -0
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +44 -0
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/knowledge.d.ts.map +1 -1
- package/dist/routes/knowledge.js +3 -2
- package/dist/routes/knowledge.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +5 -0
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/sandbox-envs.d.ts +2 -0
- package/dist/routes/sandbox-envs.d.ts.map +1 -1
- package/dist/routes/sandbox-envs.js +3 -0
- package/dist/routes/sandbox-envs.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +1 -1
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +109 -3
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/source-control-settings.d.ts +2 -0
- package/dist/routes/source-control-settings.d.ts.map +1 -1
- package/dist/routes/source-control-settings.js +5 -0
- package/dist/routes/source-control-settings.js.map +1 -1
- package/dist/routes/surface.d.ts +8 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +74 -10
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-item-activity.d.ts +11 -0
- package/dist/routes/work-item-activity.d.ts.map +1 -0
- package/dist/routes/work-item-activity.js +25 -0
- package/dist/routes/work-item-activity.js.map +1 -0
- package/dist/routes/work-item-selection.d.ts +14 -0
- package/dist/routes/work-item-selection.d.ts.map +1 -0
- package/dist/routes/work-item-selection.js +44 -0
- package/dist/routes/work-item-selection.js.map +1 -0
- package/dist/routes/work-item-starters.d.ts +29 -0
- package/dist/routes/work-item-starters.d.ts.map +1 -0
- package/dist/routes/work-item-starters.js +152 -0
- package/dist/routes/work-item-starters.js.map +1 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +239 -16
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatch-errors.d.ts +3 -0
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +9 -0
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +4 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +122 -33
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/index.d.ts +2 -2
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -2
- package/dist/rules/processor.d.ts +2 -0
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +18 -4
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +6 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +6 -2
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/transition-service.d.ts +20 -2
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +43 -20
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +71 -3
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +10 -2
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +5 -0
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/context-sandboxes.d.ts +70 -0
- package/dist/sandbox/context-sandboxes.d.ts.map +1 -0
- package/dist/sandbox/context-sandboxes.js +120 -0
- package/dist/sandbox/context-sandboxes.js.map +1 -0
- package/dist/sandbox/session-retirement.d.ts +11 -4
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +39 -13
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/session/factory-session.d.ts +20 -5
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +20 -6
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/live-sessions.d.ts +1 -1
- package/dist/session/live-sessions.d.ts.map +1 -1
- package/dist/session/live-sessions.js +12 -2
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +2 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/audit/actors.d.ts.map +1 -1
- package/dist/storage/domains/audit/actors.js +1 -1
- package/dist/storage/domains/audit/actors.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +25 -5
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +57 -20
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +1 -1
- package/dist/storage/domains/intake/base.js +2 -2
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts +16 -2
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +32 -5
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +60 -8
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +180 -18
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +1 -0
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +32 -8
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/legacy-review.d.ts +19 -1
- package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -1
- package/dist/storage/domains/work-items/legacy-review.js +62 -3
- package/dist/storage/domains/work-items/legacy-review.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +1 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +46 -18
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/tools/annotations.d.ts.map +1 -1
- package/dist/tools/annotations.js +4 -0
- package/dist/tools/annotations.js.map +1 -1
- package/dist/tools/approval-tools.d.ts +20 -0
- package/dist/tools/approval-tools.d.ts.map +1 -1
- package/dist/tools/approval-tools.js +79 -30
- package/dist/tools/approval-tools.js.map +1 -1
- package/dist/tools/audit-events-tool.d.ts +29 -0
- package/dist/tools/audit-events-tool.d.ts.map +1 -0
- package/dist/tools/audit-events-tool.js +180 -0
- package/dist/tools/audit-events-tool.js.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/messaging-tools.d.ts.map +1 -1
- package/dist/tools/messaging-tools.js +1 -1
- package/dist/tools/messaging-tools.js.map +1 -1
- package/dist/tools/permissions.d.ts.map +1 -1
- package/dist/tools/permissions.js +1 -0
- package/dist/tools/permissions.js.map +1 -1
- package/dist/tools/read-tools.d.ts +0 -2
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +2 -7
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/reports.d.ts +3 -0
- package/dist/tools/reports.d.ts.map +1 -1
- package/dist/tools/reports.js +3 -3
- package/dist/tools/reports.js.map +1 -1
- package/dist/tools/run-watch.d.ts +14 -2
- package/dist/tools/run-watch.d.ts.map +1 -1
- package/dist/tools/run-watch.js +24 -4
- package/dist/tools/run-watch.js.map +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +17 -6
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/sessions-state-processor.js +1 -1
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js +1 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +12 -2
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +1 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +2 -0
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/board-check.d.ts +11 -0
- package/dist/work-items/board-check.d.ts.map +1 -0
- package/dist/work-items/board-check.js +20 -0
- package/dist/work-items/board-check.js.map +1 -0
- package/dist/work-items/board-filter-options.d.ts +5 -0
- package/dist/work-items/board-filter-options.d.ts.map +1 -0
- package/dist/work-items/board-filter-options.js +27 -0
- package/dist/work-items/board-filter-options.js.map +1 -0
- package/dist/work-items/board-phases.d.ts +28 -0
- package/dist/work-items/board-phases.d.ts.map +1 -0
- package/dist/work-items/board-phases.js +165 -0
- package/dist/work-items/board-phases.js.map +1 -0
- package/dist/work-items/card-facts.d.ts +24 -0
- package/dist/work-items/card-facts.d.ts.map +1 -0
- package/dist/work-items/card-facts.js +75 -0
- package/dist/work-items/card-facts.js.map +1 -0
- package/dist/work-items/card-labels.d.ts +5 -0
- package/dist/work-items/card-labels.d.ts.map +1 -0
- package/dist/work-items/card-labels.js +13 -0
- package/dist/work-items/card-labels.js.map +1 -0
- package/dist/work-items/card-number.d.ts +10 -0
- package/dist/work-items/card-number.d.ts.map +1 -0
- package/dist/work-items/card-number.js +15 -0
- package/dist/work-items/card-number.js.map +1 -0
- package/dist/work-items/card-people.d.ts +25 -0
- package/dist/work-items/card-people.d.ts.map +1 -0
- package/dist/work-items/card-people.js +100 -0
- package/dist/work-items/card-people.js.map +1 -0
- package/dist/work-items/card-search-text.d.ts +4 -0
- package/dist/work-items/card-search-text.d.ts.map +1 -0
- package/dist/work-items/card-search-text.js +15 -0
- package/dist/work-items/card-search-text.js.map +1 -0
- package/dist/work-items/card-source-filters.d.ts +23 -0
- package/dist/work-items/card-source-filters.d.ts.map +1 -0
- package/dist/work-items/card-source-filters.js +25 -0
- package/dist/work-items/card-source-filters.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +0 -6
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +2 -7
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/list-related-cards.d.ts +4 -0
- package/dist/work-items/list-related-cards.d.ts.map +1 -0
- package/dist/work-items/list-related-cards.js +24 -0
- package/dist/work-items/list-related-cards.js.map +1 -0
- package/dist/work-items/related-cards.d.ts +21 -0
- package/dist/work-items/related-cards.d.ts.map +1 -0
- package/dist/work-items/related-cards.js +45 -0
- package/dist/work-items/related-cards.js.map +1 -0
- package/dist/work-items/search-words.d.ts +5 -0
- package/dist/work-items/search-words.d.ts.map +1 -0
- package/dist/work-items/search-words.js +12 -0
- package/dist/work-items/search-words.js.map +1 -0
- package/dist/work-items/split-migration.d.ts.map +1 -1
- package/dist/work-items/split-migration.js +6 -2
- package/dist/work-items/split-migration.js.map +1 -1
- package/dist/workspace.d.ts +0 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +140 -78
- package/dist/workspace.js.map +1 -1
- package/factory-skills/factory-build/SKILL.md +1 -1
- package/factory-skills/factory-self-review/SKILL.md +1 -1
- package/factory-skills/factory-triage/SKILL.md +4 -4
- package/package.json +17 -16
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { loose } from "../../../routes/route.js";
|
|
2
|
+
import { attachDependabotRules } from "../../dependabot/rules.js";
|
|
3
|
+
import { createDependabotSync } from "../../dependabot/sync.js";
|
|
2
4
|
import { GithubAppIdentity } from "../../github/app-identity.js";
|
|
3
5
|
import { resolveGithubRules } from "../../github/default-rules.js";
|
|
4
6
|
import { attachGithubIssueReconciler } from "../../github/issue-reconciler.js";
|
|
@@ -13,9 +15,19 @@ import { PlatformGithubEventWorker } from "./event-worker.js";
|
|
|
13
15
|
import { registerApiRoute } from "@mastra/core/server";
|
|
14
16
|
import { Octokit } from "@octokit/rest";
|
|
15
17
|
// src/integrations/platform/github/integration.ts
|
|
18
|
+
/**
|
|
19
|
+
* Status reason for a settled installation list. A personal install Platform withholds would otherwise
|
|
20
|
+
* read as "nothing installed", so say so; any usable installation still means ready.
|
|
21
|
+
*/
|
|
22
|
+
function githubStatusReason(hasUsableInstallation, hiddenPersonalInstallReason) {
|
|
23
|
+
if (hasUsableInstallation) return "ready";
|
|
24
|
+
return hiddenPersonalInstallReason ? "personal_install_hidden" : "not_connected";
|
|
25
|
+
}
|
|
16
26
|
const PAGE_SIZE = 30;
|
|
17
27
|
const OPEN_ISSUE_DISCOVERY_MAX_PAGES = 5;
|
|
18
28
|
const API_PREFIX = "/v1/server";
|
|
29
|
+
/** Intake config id that opts repositories into Dependabot alert sync. */
|
|
30
|
+
const DEPENDABOT_INTAKE_ID = "dependabot";
|
|
19
31
|
const CHECK_TITLE_LIMIT = 255;
|
|
20
32
|
const CHECK_TEXT_LIMIT = 65535;
|
|
21
33
|
/**
|
|
@@ -33,10 +45,11 @@ const PLATFORM_GITHUB_APP_SLUG = "mastra-platform";
|
|
|
33
45
|
const INSTALLATION_REPOS_CACHE_TTL_MS = 3e4;
|
|
34
46
|
/**
|
|
35
47
|
* How long a minted repository-scoped token may be reused. GitHub
|
|
36
|
-
* installation tokens live ~60 minutes
|
|
37
|
-
*
|
|
48
|
+
* installation tokens live ~60 minutes. A session re-mints the token it
|
|
49
|
+
* installed after `GITHUB_TOKEN_REFRESH_AFTER_MS` (30 minutes), so a token
|
|
50
|
+
* served from this cache is at most 50 minutes old when it is replaced.
|
|
38
51
|
*/
|
|
39
|
-
const REPOSITORY_ACCESS_CACHE_TTL_MS =
|
|
52
|
+
const REPOSITORY_ACCESS_CACHE_TTL_MS = 12e5;
|
|
40
53
|
/**
|
|
41
54
|
* How long a collaborator permission lookup may be reused. The reconcile
|
|
42
55
|
* sweep re-stamps every open card's author and the event tail gates every
|
|
@@ -109,10 +122,37 @@ var PlatformGithubIntegration = class {
|
|
|
109
122
|
#installationReposCache = /* @__PURE__ */ new Map();
|
|
110
123
|
/** `orgId:repositoryId` → cached repository access (TTL-bounded). */
|
|
111
124
|
#repositoryAccessCache = /* @__PURE__ */ new Map();
|
|
125
|
+
/**
|
|
126
|
+
* In-flight mints by the same key as `#repositoryAccessCache`. Sessions that
|
|
127
|
+
* boot together all miss the cache at once; without this each one minted its
|
|
128
|
+
* own token and drained the Platform's per-installation mint budget.
|
|
129
|
+
*/
|
|
130
|
+
#repositoryAccessInFlight = /* @__PURE__ */ new Map();
|
|
131
|
+
#mintOnce(cacheKey, mint) {
|
|
132
|
+
const cached = this.#repositoryAccessCache.get(cacheKey);
|
|
133
|
+
if (cached && cached.expiresAt > Date.now()) return Promise.resolve(cached.access);
|
|
134
|
+
this.#repositoryAccessCache.delete(cacheKey);
|
|
135
|
+
const inFlight = this.#repositoryAccessInFlight.get(cacheKey);
|
|
136
|
+
if (inFlight) return inFlight;
|
|
137
|
+
const pending = mint().finally(() => this.#repositoryAccessInFlight.delete(cacheKey));
|
|
138
|
+
this.#repositoryAccessInFlight.set(cacheKey, pending);
|
|
139
|
+
return pending;
|
|
140
|
+
}
|
|
112
141
|
/** `owner/repo:login` → cached collaborator permission (TTL-bounded). */
|
|
113
142
|
#collaboratorPermissionCache = /* @__PURE__ */ new Map();
|
|
114
143
|
/** Same key → lookup already in flight, so overlapping callers share one request. */
|
|
115
144
|
#collaboratorPermissionInFlight = /* @__PURE__ */ new Map();
|
|
145
|
+
/** Dependabot opt-in: its sources are the same repositories; cards arrive through the alert sync, not intake items. */
|
|
146
|
+
additionalIntakes = [{
|
|
147
|
+
id: DEPENDABOT_INTAKE_ID,
|
|
148
|
+
intake: {
|
|
149
|
+
listSources: (input) => this.intake.listSources(input),
|
|
150
|
+
listItems: async () => ({
|
|
151
|
+
items: [],
|
|
152
|
+
nextCursor: null
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}];
|
|
116
156
|
intake = {
|
|
117
157
|
resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
|
|
118
158
|
listSources: async ({ orgId, userId }) => {
|
|
@@ -201,6 +241,7 @@ var PlatformGithubIntegration = class {
|
|
|
201
241
|
sourceId,
|
|
202
242
|
title: pullRequest.title,
|
|
203
243
|
status: pullRequest.state,
|
|
244
|
+
labels: pullRequest.labels,
|
|
204
245
|
createdAt: pullRequest.createdAt,
|
|
205
246
|
updatedAt: pullRequest.updatedAt,
|
|
206
247
|
metadata: {
|
|
@@ -273,68 +314,30 @@ var PlatformGithubIntegration = class {
|
|
|
273
314
|
},
|
|
274
315
|
getRepositoryAccess: async ({ orgId, repositoryId }) => {
|
|
275
316
|
const cacheKey = `${orgId}:${repositoryId}`;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
orgId,
|
|
281
|
-
id: repositoryId
|
|
282
|
-
});
|
|
283
|
-
if (!repository) throw new Error("Version-control repository not found.");
|
|
284
|
-
const cloneUrl = `https://github.com/${repository.slug}.git`;
|
|
285
|
-
const installation = await this.storage.installations.get({
|
|
286
|
-
orgId,
|
|
287
|
-
id: repository.installationId
|
|
288
|
-
});
|
|
289
|
-
if (!installation) throw new Error("Version-control installation not found.");
|
|
290
|
-
const installationId = parsePositiveInteger(installation.externalId);
|
|
291
|
-
if (installationId === null) throw new Error("GitHub installation id is invalid.");
|
|
292
|
-
const repositoryName = splitRepository(repository.slug).repo;
|
|
293
|
-
try {
|
|
294
|
-
const access = {
|
|
295
|
-
cloneUrl,
|
|
296
|
-
authorization: {
|
|
297
|
-
scheme: "bearer",
|
|
298
|
-
token: (await this.#client.request("POST", `${API_PREFIX}/github-app/installations/${installationId}/token`, {
|
|
299
|
-
repositories: [repositoryName],
|
|
300
|
-
permissions: REPOSITORY_TOKEN_PERMISSIONS
|
|
301
|
-
})).token
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
setBounded(this.#repositoryAccessCache, cacheKey, {
|
|
305
|
-
access,
|
|
306
|
-
expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS
|
|
317
|
+
return this.#mintOnce(cacheKey, async () => {
|
|
318
|
+
const repository = await this.storage.repositories.get({
|
|
319
|
+
orgId,
|
|
320
|
+
id: repositoryId
|
|
307
321
|
});
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
token = await this.#client.request("POST", `${API_PREFIX}/github-app/installations/${candidateInstallationId}/token`, {
|
|
321
|
-
repositories: [repositoryName],
|
|
322
|
-
permissions: REPOSITORY_TOKEN_PERMISSIONS
|
|
323
|
-
});
|
|
324
|
-
} catch (candidateErr) {
|
|
325
|
-
if (isDeadInstallation(candidateErr)) continue;
|
|
326
|
-
throw candidateErr;
|
|
327
|
-
}
|
|
328
|
-
await this.storage.repositories.migrateInstallation({
|
|
329
|
-
orgId,
|
|
330
|
-
id: repositoryId,
|
|
331
|
-
newInstallationId: candidate.id
|
|
332
|
-
});
|
|
322
|
+
if (!repository) throw new Error("Version-control repository not found.");
|
|
323
|
+
const cloneUrl = `https://github.com/${repository.slug}.git`;
|
|
324
|
+
const installation = await this.storage.installations.get({
|
|
325
|
+
orgId,
|
|
326
|
+
id: repository.installationId
|
|
327
|
+
});
|
|
328
|
+
if (!installation) throw new Error("Version-control installation not found.");
|
|
329
|
+
const installationId = parsePositiveInteger(installation.externalId);
|
|
330
|
+
if (installationId === null) throw new Error("GitHub installation id is invalid.");
|
|
331
|
+
const repositoryName = splitRepository(repository.slug).repo;
|
|
332
|
+
try {
|
|
333
333
|
const access = {
|
|
334
334
|
cloneUrl,
|
|
335
335
|
authorization: {
|
|
336
336
|
scheme: "bearer",
|
|
337
|
-
token:
|
|
337
|
+
token: (await this.#client.request("POST", `${API_PREFIX}/github-app/installations/${installationId}/token`, {
|
|
338
|
+
repositories: [repositoryName],
|
|
339
|
+
permissions: REPOSITORY_TOKEN_PERMISSIONS
|
|
340
|
+
})).token
|
|
338
341
|
}
|
|
339
342
|
};
|
|
340
343
|
setBounded(this.#repositoryAccessCache, cacheKey, {
|
|
@@ -342,47 +345,88 @@ var PlatformGithubIntegration = class {
|
|
|
342
345
|
expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS
|
|
343
346
|
});
|
|
344
347
|
return access;
|
|
348
|
+
} catch (err) {
|
|
349
|
+
if (!isDeadInstallation(err) || !installation.accountName) throw err;
|
|
350
|
+
const candidates = (await this.storage.installations.list({ orgId })).map((inst, index) => ({
|
|
351
|
+
inst,
|
|
352
|
+
index
|
|
353
|
+
})).filter(({ inst }) => inst.accountName === installation.accountName && inst.id !== installation.id).sort((a, b) => b.inst.createdAt.getTime() - a.inst.createdAt.getTime() || b.index - a.index).map(({ inst }) => inst);
|
|
354
|
+
for (const candidate of candidates) {
|
|
355
|
+
const candidateInstallationId = parsePositiveInteger(candidate.externalId);
|
|
356
|
+
if (candidateInstallationId === null) continue;
|
|
357
|
+
let token;
|
|
358
|
+
try {
|
|
359
|
+
token = await this.#client.request("POST", `${API_PREFIX}/github-app/installations/${candidateInstallationId}/token`, {
|
|
360
|
+
repositories: [repositoryName],
|
|
361
|
+
permissions: REPOSITORY_TOKEN_PERMISSIONS
|
|
362
|
+
});
|
|
363
|
+
} catch (candidateErr) {
|
|
364
|
+
if (isDeadInstallation(candidateErr)) continue;
|
|
365
|
+
throw candidateErr;
|
|
366
|
+
}
|
|
367
|
+
await this.storage.repositories.migrateInstallation({
|
|
368
|
+
orgId,
|
|
369
|
+
id: repositoryId,
|
|
370
|
+
newInstallationId: candidate.id
|
|
371
|
+
});
|
|
372
|
+
const access = {
|
|
373
|
+
cloneUrl,
|
|
374
|
+
authorization: {
|
|
375
|
+
scheme: "bearer",
|
|
376
|
+
token: token.token
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
setBounded(this.#repositoryAccessCache, cacheKey, {
|
|
380
|
+
access,
|
|
381
|
+
expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS
|
|
382
|
+
});
|
|
383
|
+
return access;
|
|
384
|
+
}
|
|
385
|
+
throw err;
|
|
345
386
|
}
|
|
346
|
-
|
|
347
|
-
}
|
|
387
|
+
});
|
|
348
388
|
},
|
|
349
389
|
getRepositoriesAccess: async ({ orgId, repositoryIds }) => {
|
|
350
390
|
const ids = [...new Set(repositoryIds)];
|
|
351
391
|
if (ids.length === 0 || ids.length > MAX_REPOSITORIES_PER_TOKEN) return void 0;
|
|
352
392
|
const cacheKey = `${orgId}:${[...ids].sort().join(",")}`;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (installationId === null) throw new Error("GitHub installation id is invalid.");
|
|
370
|
-
const token = await this.#client.request("POST", `${API_PREFIX}/github-app/installations/${installationId}/token`, {
|
|
371
|
-
repositories: found.map((repository) => splitRepository(repository.slug).repo),
|
|
372
|
-
permissions: REPOSITORY_TOKEN_PERMISSIONS
|
|
373
|
-
});
|
|
374
|
-
const access = {
|
|
375
|
-
cloneUrl: `https://github.com/${found[0].slug}.git`,
|
|
376
|
-
authorization: {
|
|
393
|
+
return this.#mintOnce(cacheKey, async () => {
|
|
394
|
+
const repositories = await Promise.all(ids.map((id) => this.storage.repositories.get({
|
|
395
|
+
orgId,
|
|
396
|
+
id
|
|
397
|
+
})));
|
|
398
|
+
if (repositories.some((repository) => !repository)) throw new Error("Version-control repository not found.");
|
|
399
|
+
const found = repositories;
|
|
400
|
+
if (new Set(found.map((repository) => repository.installationId)).size !== 1) return void 0;
|
|
401
|
+
const installation = await this.storage.installations.get({
|
|
402
|
+
orgId,
|
|
403
|
+
id: found[0].installationId
|
|
404
|
+
});
|
|
405
|
+
if (!installation) throw new Error("Version-control installation not found.");
|
|
406
|
+
const installationId = parsePositiveInteger(installation.externalId);
|
|
407
|
+
if (installationId === null) throw new Error("GitHub installation id is invalid.");
|
|
408
|
+
const authorization = {
|
|
377
409
|
scheme: "bearer",
|
|
378
|
-
token:
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
expiresAt
|
|
410
|
+
token: (await this.#client.request("POST", `${API_PREFIX}/github-app/installations/${installationId}/token`, {
|
|
411
|
+
repositories: found.map((repository) => splitRepository(repository.slug).repo),
|
|
412
|
+
permissions: REPOSITORY_TOKEN_PERMISSIONS
|
|
413
|
+
})).token
|
|
414
|
+
};
|
|
415
|
+
const expiresAt = Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS;
|
|
416
|
+
const access = {
|
|
417
|
+
cloneUrl: `https://github.com/${found[0].slug}.git`,
|
|
418
|
+
authorization,
|
|
419
|
+
repositories: Object.fromEntries(found.map((repository) => [repository.id, {
|
|
420
|
+
cloneUrl: `https://github.com/${repository.slug}.git`,
|
|
421
|
+
authorization
|
|
422
|
+
}]))
|
|
423
|
+
};
|
|
424
|
+
setBounded(this.#repositoryAccessCache, cacheKey, {
|
|
425
|
+
access,
|
|
426
|
+
expiresAt
|
|
427
|
+
});
|
|
428
|
+
return access;
|
|
384
429
|
});
|
|
385
|
-
return access;
|
|
386
430
|
},
|
|
387
431
|
listPullRequests: (input) => this.#listPullRequests(input),
|
|
388
432
|
getPullRequest: (input) => this.#getPullRequest(input),
|
|
@@ -538,7 +582,7 @@ var PlatformGithubIntegration = class {
|
|
|
538
582
|
reason: "organization_required",
|
|
539
583
|
diagnostics: this.diagnostics()
|
|
540
584
|
});
|
|
541
|
-
const [installations, userConnection] = await Promise.all([this.#syncInstallations(tenant.orgId, tenant.userId), this.#fetchUserConnection(tenant.userId)]);
|
|
585
|
+
const [{ installations, hiddenPersonalInstallReason }, userConnection] = await Promise.all([this.#syncInstallations(tenant.orgId, tenant.userId), this.#fetchUserConnection(tenant.userId)]);
|
|
542
586
|
return c.json({
|
|
543
587
|
enabled: true,
|
|
544
588
|
sandboxEnabled: !!ctx.sandbox,
|
|
@@ -550,7 +594,7 @@ var PlatformGithubIntegration = class {
|
|
|
550
594
|
})),
|
|
551
595
|
userConnected: userConnection.connected,
|
|
552
596
|
userGithubUsername: userConnection.githubUsername,
|
|
553
|
-
reason: installations.length > 0
|
|
597
|
+
reason: githubStatusReason(installations.length > 0, hiddenPersonalInstallReason),
|
|
554
598
|
diagnostics: this.diagnostics()
|
|
555
599
|
});
|
|
556
600
|
}
|
|
@@ -626,16 +670,20 @@ var PlatformGithubIntegration = class {
|
|
|
626
670
|
}
|
|
627
671
|
}
|
|
628
672
|
async #syncInstallations(orgId, userId) {
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
673
|
+
const result = await this.#client.request("GET", `${API_PREFIX}/github-app/installations`);
|
|
674
|
+
const usableInstallations = result.installations.filter((installation) => installation.usable && !installation.suspendedAt);
|
|
675
|
+
return {
|
|
676
|
+
installations: await Promise.all(usableInstallations.map((installation) => this.versionControl.registerInstallation({
|
|
677
|
+
orgId,
|
|
678
|
+
userId,
|
|
679
|
+
installation: {
|
|
680
|
+
externalId: String(installation.installationId),
|
|
681
|
+
accountName: installation.accountLogin,
|
|
682
|
+
accountType: installation.accountType
|
|
683
|
+
}
|
|
684
|
+
}))),
|
|
685
|
+
hiddenPersonalInstallReason: result.hiddenPersonalInstallReason ?? void 0
|
|
686
|
+
};
|
|
639
687
|
}
|
|
640
688
|
workers(ctx) {
|
|
641
689
|
if (!this.#pollingEnabled && !this.#pullRequestReconcileEnabled && !this.#issueReconcileEnabled) return [];
|
|
@@ -648,6 +696,7 @@ var PlatformGithubIntegration = class {
|
|
|
648
696
|
ingestFactoryEvent: attachGithubRules(this, ctx),
|
|
649
697
|
reconcileFactoryState: this.#pullRequestReconcileEnabled ? attachGithubReconciler(this, ctx, (input) => this.fetchPullRequestState(input)) : void 0,
|
|
650
698
|
discoverPullRequests: this.#pullRequestReconcileEnabled ? attachGithubPullRequestDiscovery(this, ctx, openPullRequestLister(this.versionControl)) : void 0,
|
|
699
|
+
syncDependabotAlerts: this.#issueReconcileEnabled ? this.#dependabotSync(ctx) : void 0,
|
|
651
700
|
reconcileIssuesFactoryState: this.#issueReconcileEnabled ? attachGithubIssueReconciler(this, ctx, (input) => this.fetchIssueState(input), (input) => this.listOpenIssueStates(input)) : void 0,
|
|
652
701
|
pollEventsEnabled: this.#pollingEnabled,
|
|
653
702
|
intervalMs: this.#pollingIntervalMs,
|
|
@@ -663,6 +712,35 @@ var PlatformGithubIntegration = class {
|
|
|
663
712
|
}
|
|
664
713
|
})];
|
|
665
714
|
}
|
|
715
|
+
#dependabotSync(ctx) {
|
|
716
|
+
const ingest = attachDependabotRules(ctx);
|
|
717
|
+
if (!ingest) return void 0;
|
|
718
|
+
return createDependabotSync({
|
|
719
|
+
listAlerts: (input) => this.listDependabotAlerts(input),
|
|
720
|
+
listProjects: (args) => this.storage.projectRepositories.listByExternalRepository(args),
|
|
721
|
+
repositoryEnabled: async ({ orgId, repository }) => {
|
|
722
|
+
const config = (await ctx.storage.intake.getConfig({
|
|
723
|
+
orgId,
|
|
724
|
+
integrationIds: [DEPENDABOT_INTAKE_ID]
|
|
725
|
+
}))[DEPENDABOT_INTAKE_ID];
|
|
726
|
+
return Boolean(config?.enabled && config.sourceIds?.includes(repository));
|
|
727
|
+
},
|
|
728
|
+
ingest,
|
|
729
|
+
userId: "factory-rule-dispatcher"
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
/** Lists a repository's Dependabot alerts in one state through the Platform GitHub proxy. */
|
|
733
|
+
async listDependabotAlerts(input) {
|
|
734
|
+
const { owner, repo } = splitRepository(input.repository);
|
|
735
|
+
const state = input.state === "open" ? "open" : "fixed,dismissed,auto_dismissed";
|
|
736
|
+
const query = new URLSearchParams({
|
|
737
|
+
state,
|
|
738
|
+
per_page: "100",
|
|
739
|
+
sort: "updated",
|
|
740
|
+
direction: "desc"
|
|
741
|
+
});
|
|
742
|
+
return (await this.#client.request("GET", `${API_PREFIX}/github/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/dependabot/alerts?${query}`)).alerts;
|
|
743
|
+
}
|
|
666
744
|
/**
|
|
667
745
|
* Reads live PR state through the Platform GitHub proxy for the merge
|
|
668
746
|
* reconciler. Returns undefined when the PR cannot be resolved (missing,
|