30 lines
982 B
TypeScript
Raw Normal View History

2022-02-10 15:47:44 +01:00
import { asyncExecShell, saveBuildLog } from '$lib/common';
export default async function ({
applicationId,
workdir,
repodir,
2022-04-04 11:27:23 +02:00
htmlUrl,
2022-02-10 15:47:44 +01:00
repository,
branch,
buildId,
privateSshKey
}): Promise<any> {
2022-04-04 11:27:23 +02:00
const url = htmlUrl.replace('https://', '').replace('http://', '');
2022-04-03 22:53:11 +02:00
await saveBuildLog({ line: 'GitLab importer started.', buildId, applicationId });
2022-02-10 15:47:44 +01:00
await asyncExecShell(`echo '${privateSshKey}' > ${repodir}/id.rsa`);
await asyncExecShell(`chmod 600 ${repodir}/id.rsa`);
2022-04-03 22:53:11 +02:00
await saveBuildLog({
2022-02-10 15:47:44 +01:00
line: `Cloning ${repository}:${branch} branch.`,
buildId,
applicationId
});
await asyncExecShell(
2022-04-05 10:21:40 +02:00
`git clone -q -b ${branch} git@${url}:${repository}.git --config core.sshCommand="ssh -q -i ${repodir}id.rsa -o StrictHostKeyChecking=no" ${workdir}/ && cd ${workdir}/ && git submodule update --init --recursive && git lfs pull && cd .. `
2022-02-10 15:47:44 +01:00
);
const { stdout: commit } = await asyncExecShell(`cd ${workdir}/ && git rev-parse HEAD`);
return commit.replace('\n', '');
}