@mastra/factory 0.12.1-alpha.0 → 0.13.0-alpha.2
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 +10 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +90 -9
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/provenance.d.ts +2 -0
- package/dist/integrations/github/provenance.d.ts.map +1 -1
- package/dist/integrations/github/provenance.js +3 -2
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +12 -39
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +33 -4
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/webhook.d.ts.map +1 -1
- package/dist/integrations/github/webhook.js +34 -2
- package/dist/integrations/github/webhook.js.map +1 -1
- package/dist/routes/attention-providers.d.ts +17 -0
- package/dist/routes/attention-providers.d.ts.map +1 -1
- package/dist/routes/attention-providers.js +128 -2
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/attention.d.ts.map +1 -1
- package/dist/routes/attention.js +11 -4
- package/dist/routes/attention.js.map +1 -1
- package/dist/routes/projects.d.ts +9 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +26 -5
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/supervisor.d.ts +23 -0
- package/dist/routes/supervisor.d.ts.map +1 -0
- package/dist/routes/supervisor.js +34 -0
- package/dist/routes/supervisor.js.map +1 -0
- package/dist/routes/surface.js +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +5 -0
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/defaults.d.ts.map +1 -1
- package/dist/rules/defaults.js +20 -8
- package/dist/rules/defaults.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 +81 -23
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/terminal-cleanup.d.ts +3 -1
- package/dist/rules/terminal-cleanup.d.ts.map +1 -1
- package/dist/rules/terminal-cleanup.js +5 -0
- package/dist/rules/terminal-cleanup.js.map +1 -1
- package/dist/rules/transition-service.d.ts +1 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +2 -1
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +7 -0
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/sandbox/session-retirement.js +1 -1
- package/dist/storage/domains/work-items/base.d.ts +36 -1
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +144 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/supervisor/health-worker.d.ts +17 -0
- package/dist/supervisor/health-worker.d.ts.map +1 -0
- package/dist/supervisor/health-worker.js +72 -0
- package/dist/supervisor/health-worker.js.map +1 -0
- package/dist/supervisor/health.d.ts +81 -0
- package/dist/supervisor/health.d.ts.map +1 -0
- package/dist/supervisor/health.js +245 -0
- package/dist/supervisor/health.js.map +1 -0
- package/dist/supervisor/instructions.d.ts +6 -0
- package/dist/supervisor/instructions.d.ts.map +1 -0
- package/dist/supervisor/instructions.js +64 -0
- package/dist/supervisor/instructions.js.map +1 -0
- package/dist/supervisor/read-tools.d.ts +41 -0
- package/dist/supervisor/read-tools.d.ts.map +1 -0
- package/dist/supervisor/read-tools.js +338 -0
- package/dist/supervisor/read-tools.js.map +1 -0
- package/dist/supervisor/session.d.ts +38 -0
- package/dist/supervisor/session.d.ts.map +1 -0
- package/dist/supervisor/session.js +63 -0
- package/dist/supervisor/session.js.map +1 -0
- package/dist/supervisor/write-tools.d.ts +26 -0
- package/dist/supervisor/write-tools.d.ts.map +1 -0
- package/dist/supervisor/write-tools.js +227 -0
- package/dist/supervisor/write-tools.js.map +1 -0
- package/dist/workspace.d.ts +3 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +14 -4
- package/dist/workspace.js.map +1 -1
- package/factory-skills/factory-triage/SKILL.md +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provenance.js","names":[],"sources":["../../../src/integrations/github/provenance.ts"],"sourcesContent":["import type { FactoryRuleJsonValue } from '../../rules/types.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryRunBindingRecord, WorkItemRow, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { GithubIntegration } from './integration.js';\nimport { parseCreatedPullRequest } from './session-subscriptions.js';\n\nexport interface RecordFactoryPullRequestProvenanceInput {\n binding: FactoryRunBindingRecord;\n item: WorkItemRow;\n assistantMessageId: string;\n toolCallId: string;\n toolName: string;\n toolInput: FactoryRuleJsonValue;\n toolResult: FactoryRuleJsonValue;\n status: 'success' | 'error';\n}\n\nexport interface FactoryPullRequestProvenanceData {\n kind: 'factory-pr-provenance';\n bindingId: string;\n workItemId: string;\n repositoryId: number;\n pullRequestNumber: number;\n pullRequestUrl: string;\n assistantMessageId: string;\n toolCallId: string;\n}\n\nexport async function resolveFactoryPullRequestParentWorkItemId(\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n input: { orgId: string; repositoryId: number; pullRequestNumber: number },\n): Promise<string | null> {\n const targetKey = `factory-pr-provenance:${input.repositoryId}:${input.pullRequestNumber}`;\n const provenance = (await integrationStorage.subscriptions.listByTarget(targetKey, { status: 'active' })).find(\n row
|
|
1
|
+
{"version":3,"file":"provenance.js","names":[],"sources":["../../../src/integrations/github/provenance.ts"],"sourcesContent":["import type { FactoryRuleJsonValue } from '../../rules/types.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryRunBindingRecord, WorkItemRow, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { GithubIntegration } from './integration.js';\nimport { parseCreatedPullRequest } from './session-subscriptions.js';\n\nexport interface RecordFactoryPullRequestProvenanceInput {\n binding: FactoryRunBindingRecord;\n item: WorkItemRow;\n assistantMessageId: string;\n toolCallId: string;\n toolName: string;\n toolInput: FactoryRuleJsonValue;\n toolResult: FactoryRuleJsonValue;\n status: 'success' | 'error';\n}\n\nexport interface FactoryPullRequestProvenanceData {\n kind: 'factory-pr-provenance';\n bindingId: string;\n workItemId: string;\n factoryProjectId: string;\n repositoryId: number;\n pullRequestNumber: number;\n pullRequestUrl: string;\n assistantMessageId: string;\n toolCallId: string;\n}\n\nexport async function resolveFactoryPullRequestParentWorkItemId(\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n input: { orgId: string; factoryProjectId: string; repositoryId: number; pullRequestNumber: number },\n): Promise<string | null> {\n const targetKey = `factory-pr-provenance:${input.repositoryId}:${input.pullRequestNumber}`;\n // Provenance is scoped to the Factory project whose run authored the PR.\n // Rows from a sibling project in the same org — or legacy rows without the\n // project stamp — fail closed rather than linking another project's card.\n const provenance = (await integrationStorage.subscriptions.listByTarget(targetKey, { status: 'active' })).find(\n row =>\n row.orgId === input.orgId &&\n row.data?.kind === 'factory-pr-provenance' &&\n row.data.factoryProjectId === input.factoryProjectId,\n );\n return provenance?.data?.workItemId ?? null;\n}\n\nexport async function recordFactoryPullRequestProvenance(\n github: GithubIntegration,\n sourceControl: SourceControlStorageHandle,\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n workItems: WorkItemsStorage,\n input: RecordFactoryPullRequestProvenanceInput,\n): Promise<void> {\n if (input.status !== 'success' || input.item.externalSource?.type === 'pull-request') return;\n const url = parseCreatedPullRequest({\n toolName: input.toolName,\n input: input.toolInput,\n output: input.toolResult,\n });\n if (!url) return;\n\n try {\n const match = url.match(/^https:\\/\\/github\\.com\\/([^/]+\\/[^/]+)\\/pull\\/(\\d+)\\/?$/i);\n if (!match) return;\n const repositorySlug = match[1]!;\n let repositoryId: number | undefined;\n let installationId: number | undefined;\n for (const connection of await sourceControl.connections.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })) {\n const installation = await sourceControl.installations.get({\n orgId: input.binding.orgId,\n id: connection.installationId,\n });\n if (!installation) continue;\n for (const link of await sourceControl.projectRepositories.list({\n orgId: input.binding.orgId,\n connectionId: connection.id,\n })) {\n const repository = await sourceControl.repositories.get({ orgId: input.binding.orgId, id: link.repositoryId });\n if (!repository || repository.slug.toLowerCase() !== repositorySlug.toLowerCase()) continue;\n repositoryId = Number(repository.externalId);\n installationId = Number(installation.externalId);\n break;\n }\n if (repositoryId !== undefined) break;\n }\n const pullRequestNumber = Number(match[2]);\n const [owner, repo] = repositorySlug.split('/');\n if (\n !owner ||\n !repo ||\n repositoryId === undefined ||\n installationId === undefined ||\n !Number.isInteger(repositoryId) ||\n !Number.isInteger(installationId) ||\n !Number.isInteger(pullRequestNumber) ||\n pullRequestNumber < 1\n )\n return;\n const targetKey = `factory-pr-provenance:${repositoryId}:${pullRequestNumber}`;\n // Dedupe within the authoring project only: a sibling project's row must\n // not block this project from recording its own provenance.\n if (\n (await integrationStorage.subscriptions.listByTarget(targetKey)).some(\n row => row.orgId === input.binding.orgId && row.data?.factoryProjectId === input.binding.factoryProjectId,\n )\n ) {\n return;\n }\n\n const { data } = await github\n .getInstallationOctokit(installationId)\n .pulls.get({ owner, repo, pull_number: pullRequestNumber });\n if (data.base.repo.id !== repositoryId || data.number !== pullRequestNumber || data.html_url !== url) return;\n\n await integrationStorage.subscriptions.create({\n orgId: input.binding.orgId,\n targetKey,\n threadId: input.binding.threadId,\n status: 'active',\n data: {\n kind: 'factory-pr-provenance',\n bindingId: input.binding.id,\n workItemId: input.item.id,\n factoryProjectId: input.binding.factoryProjectId,\n repositoryId,\n pullRequestNumber,\n pullRequestUrl: url,\n assistantMessageId: input.assistantMessageId,\n toolCallId: input.toolCallId,\n },\n });\n\n const reviewItem = (\n await workItems.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })\n ).find(\n item =>\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'pull-request' &&\n (item.externalSource.externalId === `github-pr:${pullRequestNumber}` ||\n item.externalSource.externalId === `github:${repositoryId}:pull-request:${pullRequestNumber}`),\n );\n if (reviewItem) {\n await workItems.setParentWorkItemIfMissing({\n orgId: input.binding.orgId,\n id: reviewItem.id,\n userId: 'factory-pr-provenance',\n parentWorkItemId: input.item.id,\n });\n }\n } catch {\n return;\n }\n}\n"],"mappings":";;AA8BA,eAAsB,0CACpB,oBAKA,OACwB;CACxB,MAAM,YAAY,yBAAyB,MAAM,aAAa,GAAG,MAAM;CAUvE,QANoB,MAAM,mBAAmB,cAAc,aAAa,WAAW,EAAE,QAAQ,SAAS,CAAC,EAAA,CAAG,MACxG,QACE,IAAI,UAAU,MAAM,SACpB,IAAI,MAAM,SAAS,2BACnB,IAAI,KAAK,qBAAqB,MAAM,gBAExB,CAAC,EAAE,MAAM,cAAc;AACzC;AAEA,eAAsB,mCACpB,QACA,eACA,oBAKA,WACA,OACe;CACf,IAAI,MAAM,WAAW,aAAa,MAAM,KAAK,gBAAgB,SAAS,gBAAgB;CACtF,MAAM,MAAM,wBAAwB;EAClC,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,QAAQ,MAAM;CAChB,CAAC;CACD,IAAI,CAAC,KAAK;CAEV,IAAI;EACF,MAAM,QAAQ,IAAI,MAAM,0DAA0D;EAClF,IAAI,CAAC,OAAO;EACZ,MAAM,iBAAiB,MAAM;EAC7B,IAAI;EACJ,IAAI;EACJ,KAAK,MAAM,cAAc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;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,gGAAgG;IAChG,cAAc,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IACnD,6EAA6E;IAC7E,SAAS,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,iBAAiB,CAAC,EAAE,OAAO,qCAAqC,EAAE,4BAA4B,CAAC;IAC/F,kFAAkF;IAClF,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,0CAA0C,EAAE,gBAAgB,EAAE,wBAAwB,CAAC,CAAC;IAChH,+FAA+F;IAC/F,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE;AA4ND;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,QAAQ,EAAE,CAmoB/E;AA+GD,KAAK,wBAAwB,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { clearGithubPat, getGithubPatStatus, setGithubPat } from "./pat.js";
|
|
2
2
|
import { listPullRequestSubscriptionsForThread, subscribeToPullRequest } from "./subscriptions.js";
|
|
3
|
+
import { MaterializeError, SetupCommandError, commitAll, isValidGitRef, pushBranch } from "./sandbox.js";
|
|
3
4
|
import { requireExec } from "../../sandbox/materialization.js";
|
|
4
5
|
import { sanitizeSegment } from "../../sandbox/workdir.js";
|
|
5
6
|
import { peekSessionSandbox } from "../../sandbox/session-sandbox.js";
|
|
@@ -7,7 +8,6 @@ import { normalizeSessionTitle } from "../../session/session-title.js";
|
|
|
7
8
|
import { listRepositoryCommits } from "./commits.js";
|
|
8
9
|
import { getGithubFeatureDiagnostics, isGithubFeatureEnabled } from "./config.js";
|
|
9
10
|
import { reclaimDeletedSessionSandbox } from "./sandbox-release.js";
|
|
10
|
-
import { MaterializeError, SetupCommandError, commitAll, isValidGitRef as isValidGitRef$1, pushBranch } from "./sandbox.js";
|
|
11
11
|
import { handleGithubWebhook } from "./webhook.js";
|
|
12
12
|
import { registerApiRoute } from "@mastra/core/server";
|
|
13
13
|
import { randomUUID } from "crypto";
|
|
@@ -60,15 +60,6 @@ function pullRequestNumberFromUrl(value, expectedRepo) {
|
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Validate a git branch/ref name against a strict whitelist. The value is later
|
|
65
|
-
* interpolated into a shell `git clone --branch` command, so it must never
|
|
66
|
-
* contain shell metacharacters. We accept only git-ref-safe characters and
|
|
67
|
-
* reject anything else rather than relying on shell quoting alone.
|
|
68
|
-
*/
|
|
69
|
-
function isValidGitRef(value) {
|
|
70
|
-
return typeof value === "string" && value.length > 0 && value.length <= 255 && /^[A-Za-z0-9_./-]+$/.test(value);
|
|
71
|
-
}
|
|
72
63
|
function isJsonObject(value) {
|
|
73
64
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
74
65
|
}
|
|
@@ -404,29 +395,11 @@ function buildGithubRoutes(options) {
|
|
|
404
395
|
repo
|
|
405
396
|
});
|
|
406
397
|
}
|
|
407
|
-
const repos =
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
input: {
|
|
413
|
-
installationId: inst.id,
|
|
414
|
-
externalId: repo.id.toString(),
|
|
415
|
-
slug: repo.fullName,
|
|
416
|
-
defaultBranch: isValidGitRef(repo.defaultBranch) ? repo.defaultBranch : "main",
|
|
417
|
-
providerMetadata: {
|
|
418
|
-
private: repo.private,
|
|
419
|
-
owner: repo.owner
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
repos[start + offset] = {
|
|
424
|
-
...repo,
|
|
425
|
-
installationStorageId: inst.id,
|
|
426
|
-
repositoryStorageId: repository.id,
|
|
427
|
-
sandboxProvider: sandbox ? "custom" : "none",
|
|
428
|
-
sandboxWorkdir: `~/${sanitizeSegment(repo.fullName.split("/", 2)[1] || "repo")}`
|
|
429
|
-
};
|
|
398
|
+
const repos = matches.map(({ inst, repo }) => ({
|
|
399
|
+
...repo,
|
|
400
|
+
installationStorageId: inst.id,
|
|
401
|
+
sandboxProvider: sandbox ? "custom" : "none",
|
|
402
|
+
sandboxWorkdir: `~/${sanitizeSegment(repo.fullName.split("/", 2)[1] || "repo")}`
|
|
430
403
|
}));
|
|
431
404
|
return c.json({ repos });
|
|
432
405
|
}
|
|
@@ -944,7 +917,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
|
|
|
944
917
|
const requestedBaseBranch = body.baseBranch;
|
|
945
918
|
if (requestedBaseBranch !== void 0 && typeof requestedBaseBranch !== "string") return c.json({ error: "Invalid baseBranch" }, 400);
|
|
946
919
|
const baseBranch = requestedBaseBranch ?? project.defaultBranch;
|
|
947
|
-
if (!isValidGitRef
|
|
920
|
+
if (!isValidGitRef(baseBranch)) return c.json({ error: "Invalid baseBranch" }, 400);
|
|
948
921
|
const requestedSessionId = body.sessionId;
|
|
949
922
|
if (requestedSessionId !== void 0 && (typeof requestedSessionId !== "string" || !UUID_PATTERN.test(requestedSessionId))) return c.json({ error: "Invalid sessionId" }, 400);
|
|
950
923
|
const sessionId = requestedSessionId ?? randomUUID();
|
|
@@ -954,7 +927,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
|
|
|
954
927
|
const requestedBranch = body.branch;
|
|
955
928
|
let branch;
|
|
956
929
|
if (requestedBranch === void 0) branch = `${USER_SESSION_BRANCH_PREFIX}${sessionId}`;
|
|
957
|
-
else if (typeof requestedBranch === "string" && isValidGitRef
|
|
930
|
+
else if (typeof requestedBranch === "string" && isValidGitRef(requestedBranch)) branch = requestedBranch;
|
|
958
931
|
else return c.json({ error: "Invalid branch" }, 400);
|
|
959
932
|
if (requestedSessionId !== void 0) {
|
|
960
933
|
const existing = await github.sourceControlStorage.sessions.getBySessionId(sessionId);
|
|
@@ -1133,7 +1106,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
|
|
|
1133
1106
|
if ("response" in loaded) return loaded.response;
|
|
1134
1107
|
const { orgId, project } = loaded;
|
|
1135
1108
|
const branch = c.req.query("branch") ?? project.defaultBranch;
|
|
1136
|
-
if (!isValidGitRef
|
|
1109
|
+
if (!isValidGitRef(branch)) return c.json({ error: "Invalid branch" }, 400);
|
|
1137
1110
|
const limit = Math.min(Math.max(Math.floor(Number(c.req.query("limit") ?? DEFAULT_COMMIT_PAGE)) || DEFAULT_COMMIT_PAGE, 1), MAX_COMMIT_PAGE);
|
|
1138
1111
|
try {
|
|
1139
1112
|
const commits = await listRepositoryCommits(github, {
|
|
@@ -1169,7 +1142,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
|
|
|
1169
1142
|
} catch {
|
|
1170
1143
|
return c.json({ error: "Invalid JSON body" }, 400);
|
|
1171
1144
|
}
|
|
1172
|
-
if (!isValidGitRef
|
|
1145
|
+
if (!isValidGitRef(body.branch)) return c.json({ error: "Invalid branch" }, 400);
|
|
1173
1146
|
const branch = body.branch;
|
|
1174
1147
|
const sessionWorkspace = await resolveSessionWorkspace(github, project.id, userId, body.sessionId);
|
|
1175
1148
|
if (!sessionWorkspace) return c.json({ error: "Invalid sessionId" }, 400);
|
|
@@ -1226,9 +1199,9 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
|
|
|
1226
1199
|
} catch {
|
|
1227
1200
|
return c.json({ error: "Invalid JSON body" }, 400);
|
|
1228
1201
|
}
|
|
1229
|
-
if (!isValidGitRef
|
|
1202
|
+
if (!isValidGitRef(body.branch)) return c.json({ error: "Invalid branch" }, 400);
|
|
1230
1203
|
const base = body.base === void 0 ? project.defaultBranch : body.base;
|
|
1231
|
-
if (!isValidGitRef
|
|
1204
|
+
if (!isValidGitRef(base)) return c.json({ error: "Invalid base" }, 400);
|
|
1232
1205
|
if (typeof body.title !== "string" || body.title.trim().length === 0 || body.title.length > 256) return c.json({ error: "Invalid title" }, 400);
|
|
1233
1206
|
if (body.body !== void 0 && (typeof body.body !== "string" || body.body.length > 65536)) return c.json({ error: "Invalid body" }, 400);
|
|
1234
1207
|
const head = body.branch;
|