Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/gittensory-ui/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -14593,6 +14593,39 @@
}
}
}
},
"/v1/repos/{owner}/{repo}/contributor-issue-drafts/generate": {
"post": {
"responses": {
"200": {
"description": "Generate maintainer-reviewed contributor issue drafts from repo policy (dry-run by default)",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": {
"nullable": true
}
}
}
}
},
"400": {
"description": "Invalid request or explicit create without dryRun false"
},
"403": {
"description": "Insufficient role"
}
},
"security": [
{
"GittensoryBearer": []
},
{
"GittensorySessionCookie": []
}
]
}
}
},
"servers": [
Expand Down
39 changes: 39 additions & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ import { MAX_LOCAL_SCORER_WARNING_CHARS, MAX_LOCAL_SCORER_WARNING_COUNT } from "
import { compileFocusManifestPolicy } from "../signals/focus-manifest";
import { loadRepoFocusManifest, upsertRepoFocusManifest } from "../signals/focus-manifest-loader";
import { buildRepoOnboardingPackPreviewForRepo } from "../services/repo-onboarding-pack";
import { generateContributorIssueDrafts } from "../services/contributor-issue-draft";
import { buildRepoSettingsPreview, type PublicSurfaceSkipReason } from "../signals/settings-preview";
import {
buildGittensorConfigRecommendation,
Expand Down Expand Up @@ -464,6 +465,12 @@ const repositorySettingsSchema = z.object({
.default(DEFAULT_COMMAND_AUTHORIZATION_POLICY),
});

const contributorIssueDraftGenerateSchema = z.object({
dryRun: z.boolean().optional().default(true),
create: z.boolean().optional().default(false),
limit: z.number().int().min(1).max(20).optional().default(5),
});

const settingsPreviewSchema = z.object({
sample: z
.object({
Expand Down Expand Up @@ -1547,6 +1554,33 @@ export function createApp() {
return c.json(response);
});

app.post("/v1/repos/:owner/:repo/contributor-issue-drafts/generate", async (c) => {
const fullName = `${c.req.param("owner")}/${c.req.param("repo")}`;
const forbidden = await requireAppRole(c, ["maintainer", "owner", "operator"]);
if (forbidden) return forbidden;
const identity = await authenticateRequestIdentity(c);
const repo = await getRepository(c.env, fullName);
if (identity?.kind === "session") {
const repoForbidden = await requireSessionRepoAccess(c, identity, fullName, repo);
if (repoForbidden) return repoForbidden;
}
const body = await c.req.json().catch(() => null);
if (body === null) return c.json({ error: "invalid_json" }, 400);
const parsed = contributorIssueDraftGenerateSchema.safeParse(body);
if (!parsed.success) return c.json({ error: "invalid_contributor_issue_draft_request", issues: parsed.error.issues }, 400);
if (parsed.data.create && parsed.data.dryRun !== false) {
return c.json({ error: "explicit_create_requires_dry_run_false" }, 400);
}
return c.json(
await generateContributorIssueDrafts(c.env, fullName, {
dryRun: parsed.data.dryRun,
create: parsed.data.create,
limit: parsed.data.limit,
requestedBy: identity?.kind === "session" ? identity.actor : "api",
}),
);
});

app.get("/v1/repos/:owner/:repo/settings", async (c) => {
const fullName = `${c.req.param("owner")}/${c.req.param("repo")}`;
return c.json(await getRepositorySettings(c.env, fullName));
Expand Down Expand Up @@ -3454,6 +3488,7 @@ function canSessionAccessPath(env: Env, identity: Extract<AuthIdentity, { kind:
if (isAuthorizedGitHubSessionLogin(env, identity.actor)) return true;
if (path.startsWith("/v1/app/")) return true;
if (isRepoOnboardingPackPreviewPath(path)) return true;
if (isRepoContributorIssueDraftGeneratePath(path)) return true;
if (path === EXTENSION_PULL_CONTEXT_PATH && isExtensionScopedSession(identity)) return true;
return false;
}
Expand All @@ -3462,6 +3497,10 @@ function isRepoOnboardingPackPreviewPath(path: string): boolean {
return /^\/v1\/repos\/[^/]+\/[^/]+\/onboarding-pack\/preview$/.test(path);
}

function isRepoContributorIssueDraftGeneratePath(path: string): boolean {
return /^\/v1\/repos\/[^/]+\/[^/]+\/contributor-issue-drafts\/generate$/.test(path);
}

async function authenticateRequestIdentity(c: ProtectedRouteContext): Promise<AuthIdentity | null> {
const bearer = await authenticatePrivateToken(c.env, extractBearerToken(c.req.header("authorization")));
if (bearer) return bearer;
Expand Down
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare global {
GITTENSORY_AUTO_FILE_DRIFT_ISSUES?: string;
GITTENSORY_DRIFT_ISSUE_REPO?: string;
GITTENSORY_DRIFT_ISSUE_TOKEN?: string;
GITTENSORY_CONTRIBUTOR_ISSUE_TOKEN?: string;
PRODUCT_USAGE_HASH_SALT?: string;
GITTENSORY_API_TOKEN: string;
GITTENSORY_MCP_TOKEN: string;
Expand Down
9 changes: 9 additions & 0 deletions src/openapi/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@ export function buildOpenApiSpec() {
404: { description: "Repository is not accepted or preview unavailable" },
},
});
registry.registerPath({
method: "post",
path: "/v1/repos/{owner}/{repo}/contributor-issue-drafts/generate",
responses: {
200: { description: "Generate maintainer-reviewed contributor issue drafts from repo policy (dry-run by default)", content: { "application/json": { schema: z.record(z.string(), z.unknown()) } } },
400: { description: "Invalid request or explicit create without dryRun false" },
403: { description: "Insufficient role" },
},
});
registry.registerPath({
method: "get",
path: "/v1/repos/{owner}/{repo}/settings",
Expand Down
Loading