UNPKG

grading

Version:

Grading of student submissions, in particular programming tests.

87 lines 4.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cmdDiff = void 0; const path_1 = __importDefault(require("path")); const fsUtil_1 = require("../fsUtil"); const gitCommands_1 = require("../gitCommands"); const cliUtil_1 = require("./cliUtil"); /** * Basically calls `git diff --no-color --binary --output submission.patch main grading`. * * @param options * @returns */ async function cmdDiff(options) { (0, cliUtil_1.verbosity)(options); const submissionsDir = options.submissionsDir; const patchFolder = options.patchFolder; const patchSubmissionBranches = options.patchSubmissionBranches; const patchGradingBranch = options.patchGradingBranch; const selected = (0, cliUtil_1.retrieveSelectedFilter)(options); const dry = options.dry; try { if (!await (0, fsUtil_1.folderExists)(submissionsDir, "submissionsDir")) { program.error(`Submissions folder ${submissionsDir} does not exist yet, first run check (at least with --prepareSubmission).`); } const submissionDirs = await (0, fsUtil_1.readDir)(submissionsDir, 'dir', false, 'Diff submissions folder.'); if (submissionDirs.length == 0) { program.error(`No submissions found in ${submissionsDir}`); } (0, cliUtil_1.verb)(`Found ${submissionDirs.length} submissions.`); let name = "", subId = ""; // define here for catch block for (let counter = 0; counter < submissionDirs.length; counter++) { try { const subDir = submissionDirs[counter]; ({ name, submissionId: subId } = (0, cliUtil_1.parseSubmitter)(subDir)); if (!(0, cliUtil_1.isSubmissionSelected)(selected, [], name, subId)) { (0, cliUtil_1.verb)(`Skip user ${name}, id ${subId}`); continue; } const absSubDir = path_1.default.join(submissionsDir, subDir); (0, cliUtil_1.verb)(`\nProcessing submission ${counter + 1} of ${submissionDirs.length}: ${subId} ${name}\n`); const wsDir = path_1.default.join(submissionsDir, subDir, 'ws' + (name ? "_" + name.replace(/ /g, '_') : "")); if (!await (0, fsUtil_1.folderExists)(wsDir, 'workspace folder')) { (0, cliUtil_1.warn)(`Skipping submission of ${name}, workspace folder not unzipped yet.`); continue; } if (!await (0, gitCommands_1.hasLocalGitRepository)(wsDir)) { (0, cliUtil_1.warn)(`Skipping submission of ${name}, no local git repository found.`); continue; } const branches = await (0, gitCommands_1.gitBranches)(wsDir); const submissionBranch = patchSubmissionBranches.find(subBranch => branches.find(br => br === subBranch)); const gradingBranch = branches.find(br => br === patchGradingBranch); if (!submissionBranch) { (0, cliUtil_1.warn)(`Skipping submission of ${name}, no matching submission branch found, branches found: ${branches.join()}.`); continue; } if (!gradingBranch) { (0, cliUtil_1.verb)(`Skipping submission of ${name}, no matching grading branch found, branches found: ${branches.join()}.`); continue; } (0, cliUtil_1.log)(`Create patch file for submission ${name} with difference between ${submissionBranch} and grading branch ${gradingBranch}.`); if (!dry) { await (0, gitCommands_1.gitDiff)(wsDir, submissionBranch, gradingBranch, patchFolder, name, subId); } else { (0, cliUtil_1.log)(`Dry run: Would run git diff for submission ${name} with diff between ${submissionBranch} and ${gradingBranch}.`); } } catch (err) { const msg = `${name}: ${err instanceof Error ? err.message : err}`; (0, cliUtil_1.error)(`${msg}`); (0, cliUtil_1.debug)(err); (0, cliUtil_1.error)(`Continue with next submission.`); } } } catch (err) { (0, cliUtil_1.error)(`${SEP}`); program.error(String(err)); } } exports.cmdDiff = cmdDiff; //# sourceMappingURL=cmdDiff.js.map