MCPcopy Index your code
hub / github.com/angular/dev-infra / validateFile

Function validateFile

ng-dev/commit-message/validate-file/validate-file.ts:21–50  ·  view source on GitHub ↗
(filePath: string, isErrorMode: boolean)

Source from the content-addressed store, hash-verified

19
20/** Validate commit message at the provided file path. */
21export async function validateFile(filePath: string, isErrorMode: boolean) {
22 const git = await GitClient.get();
23 const commitMessage = readFileSync(resolve(git.baseDir, filePath), 'utf8');
24 const {valid, errors} = await validateCommitMessage(commitMessage);
25 if (valid) {
26 Log.info(`${green('✔')} Valid commit message`);
27 deleteCommitMessageDraft(filePath);
28 process.exitCode = 0;
29 return;
30 }
31
32 /** Function used to print to the console log. */
33 let printFn = isErrorMode ? Log.error : Log.log;
34
35 printFn(isErrorMode ? '✘ Invalid commit message.' : yellow('! Invalid commit message.'));
36 printValidationErrors(errors, printFn);
37 if (isErrorMode) {
38 printFn('Aborting commit attempt due to invalid commit message.');
39 printFn('Commit message aborted as failure rather than warning due to local configuration.');
40 } else {
41 printFn(yellow('Before this commit can be merged into the upstream repository, it must be'));
42 printFn(yellow('amended to follow commit message guidelines.'));
43 }
44
45 // On all invalid commit messages, the commit message should be saved as a draft to be
46 // restored on the next commit attempt.
47 saveCommitMessageDraft(filePath, commitMessage);
48 // Set the correct exit code based on if invalid commit message is an error.
49 process.exitCode = isErrorMode ? 1 : 0;
50}

Callers 1

handlerFunction · 0.85

Calls 6

resolveFunction · 0.85
validateCommitMessageFunction · 0.85
deleteCommitMessageDraftFunction · 0.85
printValidationErrorsFunction · 0.85
saveCommitMessageDraftFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected