@mastra/factory 0.29.0-alpha.2 → 0.29.0-alpha.3
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 +40 -1
- package/dist/factory.d.ts +8 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +26 -2
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +30 -1
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +17 -3
- 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 +11 -2
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +11 -0
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/metrics/collectors/postgres.d.ts +29 -0
- package/dist/metrics/collectors/postgres.d.ts.map +1 -0
- package/dist/metrics/collectors/postgres.js +121 -0
- package/dist/metrics/collectors/postgres.js.map +1 -0
- package/dist/metrics/collectors/probe.d.ts +22 -0
- package/dist/metrics/collectors/probe.d.ts.map +1 -0
- package/dist/metrics/collectors/probe.js +69 -0
- package/dist/metrics/collectors/probe.js.map +1 -0
- package/dist/metrics/collectors/process.d.ts +13 -0
- package/dist/metrics/collectors/process.d.ts.map +1 -0
- package/dist/metrics/collectors/process.js +85 -0
- package/dist/metrics/collectors/process.js.map +1 -0
- package/dist/metrics/collectors/redis.d.ts +29 -0
- package/dist/metrics/collectors/redis.d.ts.map +1 -0
- package/dist/metrics/collectors/redis.js +97 -0
- package/dist/metrics/collectors/redis.js.map +1 -0
- package/dist/metrics/config.d.ts +33 -0
- package/dist/metrics/config.d.ts.map +1 -0
- package/dist/metrics/config.js +65 -0
- package/dist/metrics/config.js.map +1 -0
- package/dist/metrics/index.d.ts +20 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +65 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/intake.d.ts +28 -0
- package/dist/metrics/intake.d.ts.map +1 -0
- package/dist/metrics/intake.js +76 -0
- package/dist/metrics/intake.js.map +1 -0
- package/dist/metrics/metrics.d.ts +60 -0
- package/dist/metrics/metrics.d.ts.map +1 -0
- package/dist/metrics/metrics.js +182 -0
- package/dist/metrics/metrics.js.map +1 -0
- package/dist/metrics/sandbox.d.ts +35 -0
- package/dist/metrics/sandbox.d.ts.map +1 -0
- package/dist/metrics/sandbox.js +156 -0
- package/dist/metrics/sandbox.js.map +1 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -0
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +1 -0
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +26 -8
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +1 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +1 -0
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +22 -14
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/sandbox/session-sandbox.d.ts +2 -0
- package/dist/sandbox/session-sandbox.d.ts.map +1 -1
- package/dist/sandbox/session-sandbox.js +7 -1
- package/dist/sandbox/session-sandbox.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +5 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +18 -1
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/timing.d.ts +4 -1
- package/dist/timing.d.ts.map +1 -1
- package/dist/timing.js +12 -4
- package/dist/timing.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +7 -1
- package/dist/workspace.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type { RuleCondition, RuleGroup, RuleOperator } from './rules/rule-group.
|
|
|
8
8
|
export { MastraFactory } from './factory.js';
|
|
9
9
|
export { waitForPendingFilesystemCapture } from './session/filesystem-capture.js';
|
|
10
10
|
export type { FactoryTools, MastraArgs, MastraFactoryConfig, MastraFactorySandboxConfig, MastraFactorySandboxOption, FactorySandboxStart, } from './factory.js';
|
|
11
|
+
export type { FactoryMetricsOptions, MetricGroup } from './metrics/index.js';
|
|
11
12
|
export { LocalFactorySandbox, type LocalFactorySandboxOptions } from './sandbox/local-factory-sandbox.js';
|
|
12
13
|
export type { GithubRuleOverrides } from './integrations/github/default-rules.js';
|
|
13
14
|
export type { FactorySandboxContext, SessionSetupGate, SessionSetupRun } from './sandbox/session-sandbox.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,SAAS,GACV,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,4BAA4B,EAC5B,2BAA2B,EAC3B,cAAc,EACd,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,w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MAAM,wBAAwB,CAAC;AAC/G,YAAY,EACV,sBAAsB,EACtB,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAChH,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile-worker.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/reconcile-worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"reconcile-worker.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/reconcile-worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,KAAK,EACV,+BAA+B,EAC/B,+BAA+B,EAC/B,uBAAuB,EACxB,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,2BAA2B,EAAuB,MAAM,YAAY,CAAC;AAG/G,eAAO,MAAM,oCAAoC,QAAc,CAAC;AAGhE,eAAO,MAAM,uCAAuC,QAAa,CAAC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ted } from "../../metrics/intake.js";
|
|
1
2
|
import { NoopLeaseProvider, isLeaseProvider } from "@mastra/core/events";
|
|
2
3
|
import { MastraWorker } from "@mastra/core/worker";
|
|
3
4
|
// src/integrations/github/reconcile-worker.ts
|
|
@@ -58,6 +59,8 @@ var GithubReconcileWorker = class extends MastraWorker {
|
|
|
58
59
|
issueIntervalMs: this.#reconcileIssues ? this.#issueIntervalMs : void 0,
|
|
59
60
|
pullRequestDiscoveryIntervalMs: this.#discover ? this.#discoveryIntervalMs : void 0
|
|
60
61
|
});
|
|
62
|
+
if (this.#reconcile) recordSweepWorkerStarted("github", "merge_close");
|
|
63
|
+
if (this.#discover) recordSweepWorkerStarted("github", "open");
|
|
61
64
|
this.#schedule(0);
|
|
62
65
|
}
|
|
63
66
|
async stop() {
|
|
@@ -118,11 +121,25 @@ var GithubReconcileWorker = class extends MastraWorker {
|
|
|
118
121
|
renewalTimer.unref?.();
|
|
119
122
|
try {
|
|
120
123
|
const targets = await this.#targets();
|
|
121
|
-
if (targets.length === 0)
|
|
124
|
+
if (targets.length === 0) {
|
|
125
|
+
if (reconcilePullRequests) recordReconcileSweep("github", "merge_close", {
|
|
126
|
+
replayed: 0,
|
|
127
|
+
ok: true
|
|
128
|
+
});
|
|
129
|
+
if (discoverPullRequests) recordReconcileSweep("github", "open", {
|
|
130
|
+
replayed: 0,
|
|
131
|
+
ok: true
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
122
135
|
if (reconcilePullRequests && this.#reconcile) {
|
|
123
136
|
const startedAt = Date.now();
|
|
124
137
|
try {
|
|
125
138
|
const { errors, ...counts } = await this.#reconcile(targets);
|
|
139
|
+
recordReconcileSweep("github", "merge_close", {
|
|
140
|
+
replayed: counts.merged + counts.closed,
|
|
141
|
+
ok: counts.failed === 0
|
|
142
|
+
});
|
|
126
143
|
const context = {
|
|
127
144
|
...counts,
|
|
128
145
|
candidateRepositories: targets.length,
|
|
@@ -135,6 +152,10 @@ var GithubReconcileWorker = class extends MastraWorker {
|
|
|
135
152
|
else if (counts.merged > 0 || counts.closed > 0) this.deps?.logger.info("GitHub pull request reconcile replayed missed merges/closes", context);
|
|
136
153
|
else this.deps?.logger.debug("GitHub pull request reconcile sweep completed", context);
|
|
137
154
|
} catch (error) {
|
|
155
|
+
recordReconcileSweep("github", "merge_close", {
|
|
156
|
+
replayed: 0,
|
|
157
|
+
ok: false
|
|
158
|
+
});
|
|
138
159
|
this.deps?.logger.warn("GitHub pull request reconcile sweep failed", { error: error instanceof Error ? error.message : String(error) });
|
|
139
160
|
}
|
|
140
161
|
}
|
|
@@ -142,6 +163,10 @@ var GithubReconcileWorker = class extends MastraWorker {
|
|
|
142
163
|
const startedAt = Date.now();
|
|
143
164
|
try {
|
|
144
165
|
const { errors, ...counts } = await this.#discover(targets);
|
|
166
|
+
recordReconcileSweep("github", "open", {
|
|
167
|
+
replayed: counts.created + counts.repaired,
|
|
168
|
+
ok: counts.failed === 0
|
|
169
|
+
});
|
|
145
170
|
const context = {
|
|
146
171
|
...counts,
|
|
147
172
|
candidateRepositories: targets.length,
|
|
@@ -154,6 +179,10 @@ var GithubReconcileWorker = class extends MastraWorker {
|
|
|
154
179
|
else if (counts.created > 0 || counts.repaired > 0) this.deps?.logger.info("GitHub pull request discovery replayed missed opens", context);
|
|
155
180
|
else this.deps?.logger.debug("GitHub pull request discovery completed", context);
|
|
156
181
|
} catch (error) {
|
|
182
|
+
recordReconcileSweep("github", "open", {
|
|
183
|
+
replayed: 0,
|
|
184
|
+
ok: false
|
|
185
|
+
});
|
|
157
186
|
this.deps?.logger.warn("GitHub pull request discovery failed", { error: error instanceof Error ? error.message : String(error) });
|
|
158
187
|
}
|
|
159
188
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile-worker.js","names":[],"sources":["../../../src/integrations/github/reconcile-worker.ts"],"sourcesContent":["import { isLeaseProvider, NoopLeaseProvider } from '@mastra/core/events';\nimport type { LeaseProvider, PubSub } from '@mastra/core/events';\nimport { MastraWorker } from '@mastra/core/worker';\nimport type { WorkerDeps } from '@mastra/core/worker';\n\nimport type {\n ConfiguredExternalRepositoryKey,\n ExternalRepositoryProjectTarget,\n SourceControlRepository,\n} from '../../storage/domains/source-control/base.js';\nimport type { GithubIssueReconciler } from './issue-reconciler.js';\nimport type { GithubPullRequestDiscovery, GithubPullRequestReconciler, ReconcileRepository } from './rules.js';\n\n// Webhooks are the primary sync; the sweeps only catch drift, so hourly.\nexport const DEFAULT_GITHUB_RECONCILE_INTERVAL_MS = 60 * 60_000;\n// Missed-open discovery costs one listing per repository, not a fetch per card,\n// so it runs at the issue sweep's cadence: a lost `opened` webhook surfaces in minutes.\nexport const DEFAULT_GITHUB_PR_DISCOVERY_INTERVAL_MS = 5 * 60_000;\nconst MIN_LEASE_TTL_MS = 30_000;\nconst LEASE_KEY = 'github:pull-request-reconcile';\n\n/** Storage slice the sweep needs to turn configured repositories into targets. */\nexport interface GithubReconcileRepositorySource {\n projectRepositories: {\n listConfiguredExternalKeys(): Promise<ConfiguredExternalRepositoryKey[]>;\n listByExternalRepository(args: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]>;\n };\n repositories: {\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlRepository | null>;\n };\n}\n\nexport interface GithubReconcileWorkerConfig {\n reconcile?: GithubPullRequestReconciler;\n reconcileIssues?: GithubIssueReconciler;\n discover?: GithubPullRequestDiscovery;\n sourceControl: GithubReconcileRepositorySource;\n intervalMs?: number;\n issueIntervalMs?: number;\n /** Defaults to five minutes, or the pull request interval when that is shorter. */\n discoveryIntervalMs?: number;\n now?: () => number;\n}\n\n/**\n * Periodic GitHub state sweeps for the self-hosted integration. Pull requests\n * drive review cards and issues drive work cards, but both share discovery and\n * a lease so replicas never sweep the same configured repositories together.\n */\nexport class GithubReconcileWorker extends MastraWorker {\n readonly name = 'github-pull-request-reconcile';\n\n readonly #reconcile: GithubPullRequestReconciler | undefined;\n readonly #reconcileIssues: GithubIssueReconciler | undefined;\n readonly #discover: GithubPullRequestDiscovery | undefined;\n readonly #sourceControl: GithubReconcileRepositorySource;\n readonly #intervalMs: number;\n readonly #issueIntervalMs: number;\n readonly #discoveryIntervalMs: number;\n readonly #leaseTtlMs: number;\n readonly #leaseOwner = globalThis.crypto.randomUUID();\n readonly #now: () => number;\n\n #running = false;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #inFlight: Promise<void> | undefined;\n #leaseProvider: LeaseProvider = NoopLeaseProvider;\n #nextPullRequestReconcileAt = 0;\n #nextIssueReconcileAt = 0;\n #nextDiscoveryAt = 0;\n\n constructor(config: GithubReconcileWorkerConfig) {\n super();\n if (!config.reconcile && !config.reconcileIssues && !config.discover) {\n throw new Error('GitHub reconcile worker requires a pull request or issue reconciler.');\n }\n this.#reconcile = config.reconcile;\n this.#reconcileIssues = config.reconcileIssues;\n this.#discover = config.discover;\n this.#sourceControl = config.sourceControl;\n this.#intervalMs = config.intervalMs ?? DEFAULT_GITHUB_RECONCILE_INTERVAL_MS;\n this.#issueIntervalMs = config.issueIntervalMs ?? this.#intervalMs;\n this.#discoveryIntervalMs =\n config.discoveryIntervalMs ?? Math.min(DEFAULT_GITHUB_PR_DISCOVERY_INTERVAL_MS, this.#intervalMs);\n if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {\n throw new Error('GitHub pull request reconcile interval must be a positive number.');\n }\n if (!Number.isFinite(this.#issueIntervalMs) || this.#issueIntervalMs <= 0) {\n throw new Error('GitHub issue reconcile interval must be a positive number.');\n }\n if (!Number.isFinite(this.#discoveryIntervalMs) || this.#discoveryIntervalMs <= 0) {\n throw new Error('GitHub pull request discovery interval must be a positive number.');\n }\n this.#leaseTtlMs = Math.max(\n MIN_LEASE_TTL_MS,\n Math.min(this.#intervalMs, this.#issueIntervalMs, this.#discoveryIntervalMs) * 3,\n );\n this.#now = config.now ?? Date.now;\n }\n\n async init(deps: WorkerDeps): Promise<void> {\n await super.init(deps);\n this.#leaseProvider = getLeaseProvider(deps.pubsub);\n }\n\n async start(): Promise<void> {\n if (this.#running) return;\n if (!this.deps) throw new Error('GithubReconcileWorker: call init() before start()');\n this.#running = true;\n this.deps.logger.debug('GitHub reconcile worker started', {\n pullRequestIntervalMs: this.#reconcile ? this.#intervalMs : undefined,\n issueIntervalMs: this.#reconcileIssues ? this.#issueIntervalMs : undefined,\n pullRequestDiscoveryIntervalMs: this.#discover ? this.#discoveryIntervalMs : undefined,\n });\n // Sweep on boot: a restart is exactly when webhooks were most likely missed.\n this.#schedule(0);\n }\n\n async stop(): Promise<void> {\n if (!this.#running) return;\n this.#running = false;\n if (this.#timer) clearTimeout(this.#timer);\n this.#timer = undefined;\n await this.#inFlight;\n }\n\n get isRunning(): boolean {\n return this.#running;\n }\n\n #schedule(delayMs: number): void {\n if (!this.#running) return;\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n const run = this.#tick().finally(() => {\n this.#inFlight = undefined;\n this.#schedule(this.#nextDelay());\n });\n this.#inFlight = run;\n }, delayMs);\n this.#timer.unref?.();\n }\n\n #nextDelay(): number {\n const now = this.#now();\n const due = [\n this.#reconcile ? this.#nextPullRequestReconcileAt : undefined,\n this.#reconcileIssues ? this.#nextIssueReconcileAt : undefined,\n this.#discover ? this.#nextDiscoveryAt : undefined,\n ].filter((at): at is number => at !== undefined);\n return Math.max(0, Math.min(...due) - now);\n }\n\n async #tick(): Promise<void> {\n const now = this.#now();\n const reconcilePullRequests = Boolean(this.#reconcile && now >= this.#nextPullRequestReconcileAt);\n const reconcileIssues = Boolean(this.#reconcileIssues && now >= this.#nextIssueReconcileAt);\n const discoverPullRequests = Boolean(this.#discover && now >= this.#nextDiscoveryAt);\n if (!reconcilePullRequests && !reconcileIssues && !discoverPullRequests) return;\n if (reconcilePullRequests) this.#nextPullRequestReconcileAt = now + this.#intervalMs;\n if (reconcileIssues) this.#nextIssueReconcileAt = now + this.#issueIntervalMs;\n if (discoverPullRequests) this.#nextDiscoveryAt = now + this.#discoveryIntervalMs;\n\n // Replicas share one sweep: the ingress dedupes duplicate writes, but the\n // reads still burn the installation's rate limit.\n const lease = await this.#leaseProvider\n .acquireLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .catch(() => ({ acquired: false }));\n if (!lease.acquired) return;\n\n let hasLease = true;\n const renewalTimer = setInterval(\n () => {\n void this.#leaseProvider\n .renewLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .then(renewed => {\n if (!renewed) {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease was lost mid-sweep; aborting further writes');\n }\n })\n .catch(error => {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease renewal failed; aborting further writes', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n },\n Math.max(1_000, Math.floor(this.#leaseTtlMs / 3)),\n );\n renewalTimer.unref?.();\n\n try {\n const targets = await this.#targets();\n if (targets.length === 0) return;\n\n if (reconcilePullRequests && this.#reconcile) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcile(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep completed with failures', {\n ...context,\n errors,\n });\n } else if (counts.merged > 0 || counts.closed > 0) {\n this.deps?.logger.info('GitHub pull request reconcile replayed missed merges/closes', context);\n } else {\n this.deps?.logger.debug('GitHub pull request reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n if (discoverPullRequests && this.#discover && hasLease) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#discover(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub pull request discovery completed with failures', { ...context, errors });\n } else if (counts.created > 0 || counts.repaired > 0) {\n this.deps?.logger.info('GitHub pull request discovery replayed missed opens', context);\n } else {\n this.deps?.logger.debug('GitHub pull request discovery completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub pull request discovery failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n if (reconcileIssues && this.#reconcileIssues && hasLease) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcileIssues(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub issue reconcile sweep completed with failures', { ...context, errors });\n } else if (counts.closed > 0) {\n this.deps?.logger.info('GitHub issue reconcile replayed closed work items', context);\n } else if (counts.relabeled > 0) {\n this.deps?.logger.info('GitHub issue reconcile re-applied label routing', context);\n } else if (counts.updated > 0) {\n this.deps?.logger.info('GitHub issue reconcile patched stale metadata', context);\n } else {\n this.deps?.logger.debug('GitHub issue reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub issue reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n } else if (reconcileIssues && this.#reconcileIssues && !hasLease) {\n this.deps?.logger.debug('GitHub issue reconcile skipped: lease lost during pull-request sweep');\n }\n } finally {\n clearInterval(renewalTimer);\n if (hasLease) {\n await this.#leaseProvider.releaseLease(LEASE_KEY, this.#leaseOwner).catch(() => undefined);\n }\n }\n }\n\n /**\n * Configured (installation, repository) pairs resolved to the numeric ids and\n * slug the sweep addresses GitHub with. A pair whose repository row is gone\n * is skipped rather than failing the sweep for the others.\n */\n async #targets(): Promise<ReconcileRepository[]> {\n const keys = await this.#sourceControl.projectRepositories.listConfiguredExternalKeys();\n const targets: ReconcileRepository[] = [];\n for (const key of keys) {\n const installationId = Number(key.installationExternalId);\n const repositoryId = Number(key.repositoryExternalId);\n if (!Number.isSafeInteger(installationId) || !Number.isSafeInteger(repositoryId)) continue;\n const projects = await this.#sourceControl.projectRepositories.listByExternalRepository(key);\n const orgId = projects[0]?.orgId;\n if (!orgId) continue;\n const repository = await this.#sourceControl.repositories.findByExternalId({\n orgId,\n externalId: key.repositoryExternalId,\n });\n if (!repository?.slug) continue;\n targets.push({ id: repositoryId, fullName: repository.slug, installationId });\n }\n return targets;\n }\n}\n\nfunction getLeaseProvider(pubsub: PubSub): LeaseProvider {\n const getProvider = (pubsub as PubSub & { getLeaseProvider?: () => LeaseProvider | undefined }).getLeaseProvider;\n if (typeof getProvider === 'function') return getProvider.call(pubsub) ?? NoopLeaseProvider;\n return isLeaseProvider(pubsub) ? pubsub : NoopLeaseProvider;\n}\n"],"mappings":";;;AAcA,MAAa,uCAAuC;AAGpD,MAAa,0CAA0C;AACvD,MAAM,mBAAmB;AACzB,MAAM,YAAY;;;;;;AAiClB,IAAa,wBAAb,cAA2C,aAAa;CACtD,OAAgB;CAEhB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,cAAuB,WAAW,OAAO,WAAW;CACpD;CAEA,WAAW;CACX;CACA;CACA,iBAAgC;CAChC,8BAA8B;CAC9B,wBAAwB;CACxB,mBAAmB;CAEnB,YAAY,QAAqC;EAC/C,MAAM;EACN,IAAI,CAAC,OAAO,aAAa,CAAC,OAAO,mBAAmB,CAAC,OAAO,UAC1D,MAAM,IAAI,MAAM,sEAAsE;EAExF,KAAK,aAAa,OAAO;EACzB,KAAK,mBAAmB,OAAO;EAC/B,KAAK,YAAY,OAAO;EACxB,KAAK,iBAAiB,OAAO;EAC7B,KAAK,cAAc,OAAO,cAAA;EAC1B,KAAK,mBAAmB,OAAO,mBAAmB,KAAK;EACvD,KAAK,uBACH,OAAO,uBAAuB,KAAK,IAAA,KAA6C,KAAK,WAAW;EAClG,IAAI,CAAC,OAAO,SAAS,KAAK,WAAW,KAAK,KAAK,eAAe,GAC5D,MAAM,IAAI,MAAM,mEAAmE;EAErF,IAAI,CAAC,OAAO,SAAS,KAAK,gBAAgB,KAAK,KAAK,oBAAoB,GAC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,OAAO,IAAI,oBAAoB;GACpD,IAAI,CAAC,OAAO,cAAc,cAAc,KAAK,CAAC,OAAO,cAAc,YAAY,GAAG;GAElF,MAAM,SAAQ,MADS,KAAK,eAAe,oBAAoB,yBAAyB,GAAG,EAAA,CACpE,EAAE,EAAE;GAC3B,IAAI,CAAC,OAAO;GACZ,MAAM,aAAa,MAAM,KAAK,eAAe,aAAa,iBAAiB;IACzE;IACA,YAAY,IAAI;GAClB,CAAC;GACD,IAAI,CAAC,YAAY,MAAM;GACvB,QAAQ,KAAK;IAAE,IAAI;IAAc,UAAU,WAAW;IAAM;GAAe,CAAC;EAC9E;EACA,OAAO;CACT;AACF;AAEA,SAAS,iBAAiB,QAA+B;CACvD,MAAM,cAAe,OAA2E;CAChG,IAAI,OAAO,gBAAgB,YAAY,OAAO,YAAY,KAAK,MAAM,KAAK;CAC1E,OAAO,gBAAgB,MAAM,IAAI,SAAS;AAC5C"}
|
|
1
|
+
{"version":3,"file":"reconcile-worker.js","names":[],"sources":["../../../src/integrations/github/reconcile-worker.ts"],"sourcesContent":["import { isLeaseProvider, NoopLeaseProvider } from '@mastra/core/events';\nimport type { LeaseProvider, PubSub } from '@mastra/core/events';\nimport { MastraWorker } from '@mastra/core/worker';\nimport type { WorkerDeps } from '@mastra/core/worker';\n\nimport { recordReconcileSweep, recordSweepWorkerStarted } from '../../metrics/intake.js';\nimport type {\n ConfiguredExternalRepositoryKey,\n ExternalRepositoryProjectTarget,\n SourceControlRepository,\n} from '../../storage/domains/source-control/base.js';\nimport type { GithubIssueReconciler } from './issue-reconciler.js';\nimport type { GithubPullRequestDiscovery, GithubPullRequestReconciler, ReconcileRepository } from './rules.js';\n\n// Webhooks are the primary sync; the sweeps only catch drift, so hourly.\nexport const DEFAULT_GITHUB_RECONCILE_INTERVAL_MS = 60 * 60_000;\n// Missed-open discovery costs one listing per repository, not a fetch per card,\n// so it runs at the issue sweep's cadence: a lost `opened` webhook surfaces in minutes.\nexport const DEFAULT_GITHUB_PR_DISCOVERY_INTERVAL_MS = 5 * 60_000;\nconst MIN_LEASE_TTL_MS = 30_000;\nconst LEASE_KEY = 'github:pull-request-reconcile';\n\n/** Storage slice the sweep needs to turn configured repositories into targets. */\nexport interface GithubReconcileRepositorySource {\n projectRepositories: {\n listConfiguredExternalKeys(): Promise<ConfiguredExternalRepositoryKey[]>;\n listByExternalRepository(args: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]>;\n };\n repositories: {\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlRepository | null>;\n };\n}\n\nexport interface GithubReconcileWorkerConfig {\n reconcile?: GithubPullRequestReconciler;\n reconcileIssues?: GithubIssueReconciler;\n discover?: GithubPullRequestDiscovery;\n sourceControl: GithubReconcileRepositorySource;\n intervalMs?: number;\n issueIntervalMs?: number;\n /** Defaults to five minutes, or the pull request interval when that is shorter. */\n discoveryIntervalMs?: number;\n now?: () => number;\n}\n\n/**\n * Periodic GitHub state sweeps for the self-hosted integration. Pull requests\n * drive review cards and issues drive work cards, but both share discovery and\n * a lease so replicas never sweep the same configured repositories together.\n */\nexport class GithubReconcileWorker extends MastraWorker {\n readonly name = 'github-pull-request-reconcile';\n\n readonly #reconcile: GithubPullRequestReconciler | undefined;\n readonly #reconcileIssues: GithubIssueReconciler | undefined;\n readonly #discover: GithubPullRequestDiscovery | undefined;\n readonly #sourceControl: GithubReconcileRepositorySource;\n readonly #intervalMs: number;\n readonly #issueIntervalMs: number;\n readonly #discoveryIntervalMs: number;\n readonly #leaseTtlMs: number;\n readonly #leaseOwner = globalThis.crypto.randomUUID();\n readonly #now: () => number;\n\n #running = false;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #inFlight: Promise<void> | undefined;\n #leaseProvider: LeaseProvider = NoopLeaseProvider;\n #nextPullRequestReconcileAt = 0;\n #nextIssueReconcileAt = 0;\n #nextDiscoveryAt = 0;\n\n constructor(config: GithubReconcileWorkerConfig) {\n super();\n if (!config.reconcile && !config.reconcileIssues && !config.discover) {\n throw new Error('GitHub reconcile worker requires a pull request or issue reconciler.');\n }\n this.#reconcile = config.reconcile;\n this.#reconcileIssues = config.reconcileIssues;\n this.#discover = config.discover;\n this.#sourceControl = config.sourceControl;\n this.#intervalMs = config.intervalMs ?? DEFAULT_GITHUB_RECONCILE_INTERVAL_MS;\n this.#issueIntervalMs = config.issueIntervalMs ?? this.#intervalMs;\n this.#discoveryIntervalMs =\n config.discoveryIntervalMs ?? Math.min(DEFAULT_GITHUB_PR_DISCOVERY_INTERVAL_MS, this.#intervalMs);\n if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {\n throw new Error('GitHub pull request reconcile interval must be a positive number.');\n }\n if (!Number.isFinite(this.#issueIntervalMs) || this.#issueIntervalMs <= 0) {\n throw new Error('GitHub issue reconcile interval must be a positive number.');\n }\n if (!Number.isFinite(this.#discoveryIntervalMs) || this.#discoveryIntervalMs <= 0) {\n throw new Error('GitHub pull request discovery interval must be a positive number.');\n }\n this.#leaseTtlMs = Math.max(\n MIN_LEASE_TTL_MS,\n Math.min(this.#intervalMs, this.#issueIntervalMs, this.#discoveryIntervalMs) * 3,\n );\n this.#now = config.now ?? Date.now;\n }\n\n async init(deps: WorkerDeps): Promise<void> {\n await super.init(deps);\n this.#leaseProvider = getLeaseProvider(deps.pubsub);\n }\n\n async start(): Promise<void> {\n if (this.#running) return;\n if (!this.deps) throw new Error('GithubReconcileWorker: call init() before start()');\n this.#running = true;\n this.deps.logger.debug('GitHub reconcile worker started', {\n pullRequestIntervalMs: this.#reconcile ? this.#intervalMs : undefined,\n issueIntervalMs: this.#reconcileIssues ? this.#issueIntervalMs : undefined,\n pullRequestDiscoveryIntervalMs: this.#discover ? this.#discoveryIntervalMs : undefined,\n });\n // Sweep on boot: a restart is exactly when webhooks were most likely missed.\n if (this.#reconcile) recordSweepWorkerStarted('github', 'merge_close');\n if (this.#discover) recordSweepWorkerStarted('github', 'open');\n this.#schedule(0);\n }\n\n async stop(): Promise<void> {\n if (!this.#running) return;\n this.#running = false;\n if (this.#timer) clearTimeout(this.#timer);\n this.#timer = undefined;\n await this.#inFlight;\n }\n\n get isRunning(): boolean {\n return this.#running;\n }\n\n #schedule(delayMs: number): void {\n if (!this.#running) return;\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n const run = this.#tick().finally(() => {\n this.#inFlight = undefined;\n this.#schedule(this.#nextDelay());\n });\n this.#inFlight = run;\n }, delayMs);\n this.#timer.unref?.();\n }\n\n #nextDelay(): number {\n const now = this.#now();\n const due = [\n this.#reconcile ? this.#nextPullRequestReconcileAt : undefined,\n this.#reconcileIssues ? this.#nextIssueReconcileAt : undefined,\n this.#discover ? this.#nextDiscoveryAt : undefined,\n ].filter((at): at is number => at !== undefined);\n return Math.max(0, Math.min(...due) - now);\n }\n\n async #tick(): Promise<void> {\n const now = this.#now();\n const reconcilePullRequests = Boolean(this.#reconcile && now >= this.#nextPullRequestReconcileAt);\n const reconcileIssues = Boolean(this.#reconcileIssues && now >= this.#nextIssueReconcileAt);\n const discoverPullRequests = Boolean(this.#discover && now >= this.#nextDiscoveryAt);\n if (!reconcilePullRequests && !reconcileIssues && !discoverPullRequests) return;\n if (reconcilePullRequests) this.#nextPullRequestReconcileAt = now + this.#intervalMs;\n if (reconcileIssues) this.#nextIssueReconcileAt = now + this.#issueIntervalMs;\n if (discoverPullRequests) this.#nextDiscoveryAt = now + this.#discoveryIntervalMs;\n\n // Replicas share one sweep: the ingress dedupes duplicate writes, but the\n // reads still burn the installation's rate limit.\n const lease = await this.#leaseProvider\n .acquireLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .catch(() => ({ acquired: false }));\n if (!lease.acquired) return;\n\n let hasLease = true;\n const renewalTimer = setInterval(\n () => {\n void this.#leaseProvider\n .renewLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .then(renewed => {\n if (!renewed) {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease was lost mid-sweep; aborting further writes');\n }\n })\n .catch(error => {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease renewal failed; aborting further writes', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n },\n Math.max(1_000, Math.floor(this.#leaseTtlMs / 3)),\n );\n renewalTimer.unref?.();\n\n try {\n const targets = await this.#targets();\n if (targets.length === 0) {\n // Nothing to sweep is a clean sweep, not a stalled one.\n if (reconcilePullRequests) recordReconcileSweep('github', 'merge_close', { replayed: 0, ok: true });\n if (discoverPullRequests) recordReconcileSweep('github', 'open', { replayed: 0, ok: true });\n return;\n }\n\n if (reconcilePullRequests && this.#reconcile) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcile(targets);\n recordReconcileSweep('github', 'merge_close', {\n replayed: counts.merged + counts.closed,\n ok: counts.failed === 0,\n });\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep completed with failures', {\n ...context,\n errors,\n });\n } else if (counts.merged > 0 || counts.closed > 0) {\n this.deps?.logger.info('GitHub pull request reconcile replayed missed merges/closes', context);\n } else {\n this.deps?.logger.debug('GitHub pull request reconcile sweep completed', context);\n }\n } catch (error) {\n recordReconcileSweep('github', 'merge_close', { replayed: 0, ok: false });\n this.deps?.logger.warn('GitHub pull request reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n if (discoverPullRequests && this.#discover && hasLease) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#discover(targets);\n recordReconcileSweep('github', 'open', {\n replayed: counts.created + counts.repaired,\n ok: counts.failed === 0,\n });\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub pull request discovery completed with failures', { ...context, errors });\n } else if (counts.created > 0 || counts.repaired > 0) {\n this.deps?.logger.info('GitHub pull request discovery replayed missed opens', context);\n } else {\n this.deps?.logger.debug('GitHub pull request discovery completed', context);\n }\n } catch (error) {\n recordReconcileSweep('github', 'open', { replayed: 0, ok: false });\n this.deps?.logger.warn('GitHub pull request discovery failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n if (reconcileIssues && this.#reconcileIssues && hasLease) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcileIssues(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub issue reconcile sweep completed with failures', { ...context, errors });\n } else if (counts.closed > 0) {\n this.deps?.logger.info('GitHub issue reconcile replayed closed work items', context);\n } else if (counts.relabeled > 0) {\n this.deps?.logger.info('GitHub issue reconcile re-applied label routing', context);\n } else if (counts.updated > 0) {\n this.deps?.logger.info('GitHub issue reconcile patched stale metadata', context);\n } else {\n this.deps?.logger.debug('GitHub issue reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub issue reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n } else if (reconcileIssues && this.#reconcileIssues && !hasLease) {\n this.deps?.logger.debug('GitHub issue reconcile skipped: lease lost during pull-request sweep');\n }\n } finally {\n clearInterval(renewalTimer);\n if (hasLease) {\n await this.#leaseProvider.releaseLease(LEASE_KEY, this.#leaseOwner).catch(() => undefined);\n }\n }\n }\n\n /**\n * Configured (installation, repository) pairs resolved to the numeric ids and\n * slug the sweep addresses GitHub with. A pair whose repository row is gone\n * is skipped rather than failing the sweep for the others.\n */\n async #targets(): Promise<ReconcileRepository[]> {\n const keys = await this.#sourceControl.projectRepositories.listConfiguredExternalKeys();\n const targets: ReconcileRepository[] = [];\n for (const key of keys) {\n const installationId = Number(key.installationExternalId);\n const repositoryId = Number(key.repositoryExternalId);\n if (!Number.isSafeInteger(installationId) || !Number.isSafeInteger(repositoryId)) continue;\n const projects = await this.#sourceControl.projectRepositories.listByExternalRepository(key);\n const orgId = projects[0]?.orgId;\n if (!orgId) continue;\n const repository = await this.#sourceControl.repositories.findByExternalId({\n orgId,\n externalId: key.repositoryExternalId,\n });\n if (!repository?.slug) continue;\n targets.push({ id: repositoryId, fullName: repository.slug, installationId });\n }\n return targets;\n }\n}\n\nfunction getLeaseProvider(pubsub: PubSub): LeaseProvider {\n const getProvider = (pubsub as PubSub & { getLeaseProvider?: () => LeaseProvider | undefined }).getLeaseProvider;\n if (typeof getProvider === 'function') return getProvider.call(pubsub) ?? NoopLeaseProvider;\n return isLeaseProvider(pubsub) ? pubsub : NoopLeaseProvider;\n}\n"],"mappings":";;;;AAeA,MAAa,uCAAuC;AAGpD,MAAa,0CAA0C;AACvD,MAAM,mBAAmB;AACzB,MAAM,YAAY;;;;;;AAiClB,IAAa,wBAAb,cAA2C,aAAa;CACtD,OAAgB;CAEhB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,cAAuB,WAAW,OAAO,WAAW;CACpD;CAEA,WAAW;CACX;CACA;CACA,iBAAgC;CAChC,8BAA8B;CAC9B,wBAAwB;CACxB,mBAAmB;CAEnB,YAAY,QAAqC;EAC/C,MAAM;EACN,IAAI,CAAC,OAAO,aAAa,CAAC,OAAO,mBAAmB,CAAC,OAAO,UAC1D,MAAM,IAAI,MAAM,sEAAsE;EAExF,KAAK,aAAa,OAAO;EACzB,KAAK,mBAAmB,OAAO;EAC/B,KAAK,YAAY,OAAO;EACxB,KAAK,iBAAiB,OAAO;EAC7B,KAAK,cAAc,OAAO,cAAA;EAC1B,KAAK,mBAAmB,OAAO,mBAAmB,KAAK;EACvD,KAAK,uBACH,OAAO,uBAAuB,KAAK,IAAA,KAA6C,KAAK,WAAW;EAClG,IAAI,CAAC,OAAO,SAAS,KAAK,WAAW,KAAK,KAAK,eAAe,GAC5D,MAAM,IAAI,MAAM,mEAAmE;EAErF,IAAI,CAAC,OAAO,SAAS,KAAK,gBAAgB,KAAK,KAAK,oBAAoB,GACtE,MAAM,IAAI,MA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O,EAAE,kBAAkB,EAC3B,oBAAoB,EAAE,2BAA2B,GAChD,0BAA0B,GAAG,SAAS,CAIxC;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,GAC1B,kBAAkB,GAAG,SAAS,CAYhC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,GAC1B,CAAC,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAKhE;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,EAC3B,gBAAgB,EAAE,wBAAwB,GACzC,2BAA2B,GAAG,SAAS,CAIzC"}
|
|
@@ -3,6 +3,7 @@ import "../../boards/index.js";
|
|
|
3
3
|
import { toBoardSource } from "../../boards/project-boards.js";
|
|
4
4
|
import { cardLabels } from "../../boards/relocate.js";
|
|
5
5
|
import { boardEventHandlers, boardForWorkItem, cardBoardFlow, cardOwnsBranch, eventBoardId, intakeTarget, isTerminalWorkItem, newestOwnedOpenPullRequestNumber, pullRequestSources, rulePhaseField, withBoardClosure, withBoardFlow, workItemPhaseSemantics } from "../../boards/semantics.js";
|
|
6
|
+
import { recordIntakeEvent } from "../../metrics/intake.js";
|
|
6
7
|
import { requestsChangesVerdict } from "../../review-verdict.js";
|
|
7
8
|
import { deploymentOwnsEvent, routeEventDecision, selectEventRule, withoutRouteEvent } from "../../rules/event-rules.js";
|
|
8
9
|
import { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from "../../rules/validation.js";
|
|
@@ -378,6 +379,16 @@ var GithubRules = class {
|
|
|
378
379
|
}
|
|
379
380
|
}
|
|
380
381
|
async ingest(parsed) {
|
|
382
|
+
try {
|
|
383
|
+
const result = await this.#ingest(parsed);
|
|
384
|
+
recordIntakeEvent("github", result.status);
|
|
385
|
+
return result;
|
|
386
|
+
} catch (error) {
|
|
387
|
+
recordIntakeEvent("github", "error");
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async #ingest(parsed) {
|
|
381
392
|
const event = eventName(parsed);
|
|
382
393
|
const repository = object(parsed.payload.repository);
|
|
383
394
|
const installationId = number(object(parsed.payload.installation)?.id);
|
|
@@ -781,8 +792,11 @@ var GithubRules = class {
|
|
|
781
792
|
}
|
|
782
793
|
/**
|
|
783
794
|
* The existing card a pull request opened for the first time belongs with, or undefined when it
|
|
784
|
-
* gets a card of its own. The card must be open
|
|
785
|
-
*
|
|
795
|
+
* gets a card of its own. The card must be open and own an issue: a pull request's own card never
|
|
796
|
+
* takes another, and a card from an integration whose merge requests are its own (GitLab) keeps to
|
|
797
|
+
* those. A GitHub card must also belong to this repository; a card from another integration (Jira,
|
|
798
|
+
* Linear, incident.io) carries no repository of its own to match against, so it is taken as it is.
|
|
799
|
+
* In order: the card that authored it (on a board that reviews pull requests), by provenance or session branch,
|
|
786
800
|
* when the pull request is Factory-authored or its author is trusted; it is filed there. Then,
|
|
787
801
|
* for a trusted author only, the card of the first issue its description says it closes; an
|
|
788
802
|
* intake route decides whether it joins that one. An untrusted author's pull request never
|
|
@@ -795,7 +809,7 @@ var GithubRules = class {
|
|
|
795
809
|
factoryProjectId: input.factoryProjectId
|
|
796
810
|
});
|
|
797
811
|
if (items.some((item) => attachedPullRequestSource(item, input.repositoryId, input.repositoryName, input.pullRequestNumber) || item.externalSource?.type === "pull-request" && (item.externalSource.externalId === canonicalSourceKey("pull-request", input.pullRequestNumber) || item.externalSource.externalId === legacySourceKey(input.repositoryId, "pull-request", input.pullRequestNumber)) && cardBelongsToRepository(item, input.repositoryId, input.repositoryName))) return void 0;
|
|
798
|
-
const eligible = (card) => card.externalSource
|
|
812
|
+
const eligible = (card) => card.externalSource != null && card.externalSource.type !== "pull-request" && card.externalSource.integrationId !== "gitlab" && !isTerminalWorkItem(this.#boards(input), card) && (card.externalSource.integrationId !== "github" || cardBelongsToRepository(card, input.repositoryId, input.repositoryName));
|
|
799
813
|
if (input.matchedItem && eligible(input.matchedItem) && cardBoardFlow(this.#boards(input), input.matchedItem).pullRequestReview !== void 0) return {
|
|
800
814
|
card: input.matchedItem,
|
|
801
815
|
reason: "authored"
|