mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 05:16:50 +01:00
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>
34 lines
1.1 KiB
TypeScript
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}`;
|
|
}
|