import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
import type { Repository } from "@prisma/client";
import { Env } from "../../env";
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 = `ssh://git@${Env.DEPLOYMENT_DOMAIN}`;
return `${baseUrl}/${parentOrg.slug}/${repo.slug}.git`;
};
};
export default makeGetRepositorySSHCloneUrl;