Files
PaperClipAI/server/src/services/managed-project-checkout-name.ts
T
Devin FoleyandPaperclip e30550ef39 refactor: remove code comments added by recent PRs (#16681)
CONTRIBUTING.md says PRs add no code comments, but #16485, #16586, #16621 and #16672 added some. This removes the 215 comment-only lines git blame on master attributes to those merge commits, across 12 code files, plus one blank line the removal left doubled. Rewritten (not added) comments in scripts/assert-cloud-image-sentry.mjs and comments in .github workflows are left alone. No code changes.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-17 18:55:39 -07:00

34 lines
1.1 KiB
TypeScript

import { createHash } from "node:crypto";
export function projectRepositoryIdentity(url: string) {
return url.trim().replace(/\.git\/?$/, "").replace(/\/$/, "");
}
export function deriveRepoNameFromRepoUrl(repoUrl: string | null): string | null {
const trimmed = repoUrl?.trim() ?? "";
if (!trimmed) return null;
try {
const parsed = new URL(trimmed);
const cleanedPath = parsed.pathname.replace(/\/+$/, "");
const repoName =
cleanedPath
.split("/")
.filter(Boolean)
.pop()
?.replace(/\.git$/i, "") ?? "";
return repoName || null;
} catch {
return null;
}
}
export function managedProjectCheckoutName(workspace: {
id: string; repoUrl: string; repoRef: string | null; cwd?: string | null;
}) {
const name = (deriveRepoNameFromRepoUrl(workspace.repoUrl) ?? "repo").replace(/[^a-zA-Z0-9_-]/g, "-");
const hash = createHash("sha256")
.update(JSON.stringify([workspace.id, projectRepositoryIdentity(workspace.repoUrl), workspace.repoRef, workspace.cwd ?? null]))
.digest("hex").slice(0, 12);
return `${name}-${hash}`;
}