MCPcopy Create free account
hub / github.com/angular/dev-infra / validateCommitAndCollectErrors

Function validateCommitAndCollectErrors

ng-dev/commit-message/validate.ts:67–211  ·  view source on GitHub ↗

Perform the validation checks against the parsed commit.

()

Source from the content-addressed store, hash-verified

65
66 /** Perform the validation checks against the parsed commit. */
67 function validateCommitAndCollectErrors() {
68 ////////////////////////////////////
69 // Checking revert, squash, fixup //
70 ////////////////////////////////////
71
72 // All revert commits are considered valid.
73 if (commit.isRevert) {
74 return true;
75 }
76
77 // All squashes are considered valid, as the commit will be squashed into another in
78 // the git history anyway, unless the options provided to not allow squash commits.
79 if (commit.isSquash) {
80 if (options.disallowSquash) {
81 errors.push('The commit must be manually squashed into the target commit');
82 return false;
83 }
84 return true;
85 }
86
87 // Fixups commits are considered valid, unless nonFixupCommitHeaders are provided to check
88 // against. If `nonFixupCommitHeaders` is not empty, we check whether there is a corresponding
89 // non-fixup commit (i.e. a commit whose header is identical to this commit's header after
90 // stripping the `fixup! ` prefix), otherwise we assume this verification will happen in another
91 // check.
92 if (commit.isFixup) {
93 if (config.disallowFixup) {
94 errors.push(
95 'The commit must be manually fixed-up into the target commit as fixup commits are disallowed',
96 );
97
98 return false;
99 }
100
101 if (options.nonFixupCommitHeaders && !options.nonFixupCommitHeaders.includes(commit.header)) {
102 errors.push(
103 'Unable to find match for fixup commit among prior commits: ' +
104 (options.nonFixupCommitHeaders.map((x) => `\n ${x}`).join('') || '-'),
105 );
106 return false;
107 }
108
109 return true;
110 }
111
112 ////////////////////////////
113 // Checking commit header //
114 ////////////////////////////
115 if (commit.header.length > config.maxLineLength) {
116 errors.push(`The commit message header is longer than ${config.maxLineLength} characters`);
117 return false;
118 }
119
120 if (!commit.type) {
121 errors.push(`The commit message header does not match the expected format.`);
122 return false;
123 }
124

Callers 1

validateCommitMessageFunction · 0.85

Calls 2

pushMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected