2022-02-10 15:47:44 +01:00
|
|
|
import { asyncExecShell, saveBuildLog } from '$lib/common';
|
2022-02-14 09:28:37 +01:00
|
|
|
import { ErrorHandler } from '$lib/database';
|
2022-02-10 15:47:44 +01:00
|
|
|
|
|
|
|
export default async function ({
|
|
|
|
applicationId,
|
|
|
|
debug,
|
|
|
|
workdir,
|
|
|
|
repodir,
|
|
|
|
repository,
|
|
|
|
branch,
|
|
|
|
buildId,
|
|
|
|
privateSshKey
|
|
|
|
}): Promise<any> {
|
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(
|
|
|
|
`git clone -q -b ${branch} git@gitlab.com:${repository}.git --config core.sshCommand="ssh -q -i ${repodir}id.rsa -o StrictHostKeyChecking=no" ${workdir}/ && cd ${workdir}/ && git submodule update --init --recursive && cd ..`
|
|
|
|
);
|
|
|
|
const { stdout: commit } = await asyncExecShell(`cd ${workdir}/ && git rev-parse HEAD`);
|
|
|
|
return commit.replace('\n', '');
|
|
|
|
}
|