import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
import type { Repository } from "@prisma/client";
import type { RepositoryServiceDeps } from "./types";
const makeGetRepositorySSHCloneUrl: ServiceMethodFactory<
RepositoryServiceDeps,
[Repository],
Promise<string>
> = ({ request }) => {
return async (repo) => {
const parentOrg = await request.prisma.organization.findUnique({
where: {
id: repo.organizationId,
},
});
if (parentOrg == null) {
throw new Error(
`Could not find the parent organization for project "${repo.slug}".`
);
}
const baseUrl = `git@localhost`;
return `${baseUrl}:${parentOrg.slug}/${repo.slug}.git`;
};
};
export default makeGetRepositorySSHCloneUrl;