PRIX / lib /src /checkout.js
yamxxx1's picture
Upload 117 files
a2fe16e verified
Raw
History Blame
2.68 kB
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkoutRepo = void 0;
const utils_1 = require("./utils");
const fs_1 = require("fs");
const path_1 = require("path");
const context_1 = require("./context");
const checkoutRepo = async (tempDir, options = {}) => {
const ctx = (0, context_1.getCurrentContext)();
if (!ctx)
throw new Error('No context available for checkout');
const { owner, repo } = ctx.repo;
const installationId = ctx.probotContext.payload.installation.id;
const tokenResp = await ctx.probotContext.octokit.apps.createInstallationAccessToken({
installation_id: installationId
});
const token = tokenResp.data.token;
if (!token) {
throw new Error('Failed to create installation access token: token is undefined');
}
const cloneUrl = `https://x-access-token:${token}@github.com/${owner}/${repo}.git`;
const headBranch = ctx.probotContext.payload.pull_request.head.ref;
const headSha = ctx.probotContext.payload.pull_request.head.sha;
if ((0, fs_1.existsSync)(tempDir)) {
(0, fs_1.rmSync)(tempDir, { recursive: true, force: true });
}
(0, fs_1.mkdirSync)(tempDir, { recursive: true });
console.log(`Cloning ${owner}/${repo} into ${tempDir}...`);
if (options.sparse && options.files && options.files.length > 0) {
console.log(`Using sparse checkout for ${options.files.length} files...`);
(0, utils_1.prixExec)(`git clone --no-checkout --depth 1 ${cloneUrl} .`, {
cwd: tempDir,
stdio: 'pipe'
});
(0, utils_1.prixExec)(`git fetch origin ${headSha} --depth 1`, { cwd: tempDir });
const sparseConfig = options.files.join('\n');
(0, fs_1.writeFileSync)((0, path_1.join)(tempDir, '.git/info/sparse-checkout'), sparseConfig);
(0, utils_1.prixExec)(`git config core.sparseCheckout true`, { cwd: tempDir });
(0, utils_1.prixExec)(`git checkout ${headSha}`, { cwd: tempDir });
}
else {
console.log(`Cloning ${owner}/${repo} with depth 1...`);
(0, utils_1.prixExec)(`git clone --no-checkout --depth 1 ${cloneUrl} .`, {
cwd: tempDir,
stdio: 'pipe'
});
(0, utils_1.prixExec)(`git fetch origin ${headSha} --depth 1`, { cwd: tempDir });
(0, utils_1.prixExec)(`git checkout ${headSha}`, { cwd: tempDir });
}
(0, utils_1.prixExec)(`git config user.name "PRIX AI Auditor"`, { cwd: tempDir });
(0, utils_1.prixExec)(`git config user.email "bot@prix.ai"`, { cwd: tempDir });
return tempDir;
};
exports.checkoutRepo = checkoutRepo;
//# sourceMappingURL=checkout.js.map