refactor: Improve logging in processors/action chain#1338
refactor: Improve logging in processors/action chain#1338RichardUri wants to merge 5 commits intofinos:mainfrom
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
|
kriswest
left a comment
There was a problem hiding this comment.
Happy to see this clean-up. Needs a few small tweaks and cleanup of commented lines.
| import { getCommitConfig } from '../../../config'; | ||
|
|
||
| const isMessageAllowed = (commitMessage: string): boolean => { | ||
| const isMessageAllowed = (commitMessage: any): string | null => { |
| if (!commitMessage) { | ||
| console.log('No commit message included...'); | ||
| return false; | ||
| // console.log('No commit message included...'); |
| import { getCommitConfig } from '../../../config'; | ||
|
|
||
| const isMessageAllowed = (commitMessage: string): boolean => { | ||
| const isMessageAllowed = (commitMessage: any): string | null => { |
There was a problem hiding this comment.
A comment explaining that a string response indicates failure would be good
There was a problem hiding this comment.
Perhaps also renaming the function to match output style, e.g. to checkCommitMessage
| if (typeof commitMessage !== 'string') { | ||
| console.log('A non-string value has been captured for the commit message...'); | ||
| return false; | ||
| // console.log('A non-string value has been captured for the commit message...'); |
| if (literalMatches.length || patternMatches.length) { | ||
| console.log('Commit message is blocked via configured literals/patterns...'); | ||
| return false; | ||
| // console.log('Commit message is blocked via configured literals/patterns...'); |
| console.log('Invalid regex pattern...'); | ||
| return false; | ||
| // console.log('Invalid regex pattern...'); | ||
| return 'Invalid regex pattern...'; |
There was a problem hiding this comment.
| return 'Invalid regex pattern...'; | |
| return 'Invalid regex pattern'; |
| const uniqueCommitMessages = [...new Set(action.commitData?.map((commit) => commit.message))]; | ||
|
|
||
| const illegalMessages = uniqueCommitMessages.filter((message) => !isMessageAllowed(message)); | ||
| // const illegalMessages = uniqueCommitMessages.filter((message) => !isMessageAllowed(message)); |
| const illegalMessages = uniqueCommitMessages.filter( | ||
| (message) => isMessageAllowed(message) !== null, | ||
| ); | ||
|
|
||
| if (illegalMessages.length > 0) { | ||
| console.log(`The following commit messages are illegal: ${illegalMessages}`); | ||
| // console.log(`The following commit messages are illegal: ${illegalMessages}`); | ||
|
|
||
| step.error = true; | ||
| step.log(`The following commit messages are illegal: ${illegalMessages}`); | ||
| illegalMessages.forEach((message) => { | ||
| const error = isMessageAllowed(message); | ||
| step.log( | ||
| `Illegal commit message detected: "${message}" - Reason: ${error ?? 'Unknown reason'}`, | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Using the function twice is inefficent. Perhaps swap out filter for map, then filter the result for non-null messages
| // step.error = true; | ||
| // step.log(`The following commit messages are illegal: ${illegalMessages}`); |
| } | ||
|
|
||
| console.log(`The following commit messages are legal: ${uniqueCommitMessages}`); | ||
| // console.log(`The following commit messages are legal: ${uniqueCommitMessages}`); |
|
@RichardUri have you hit the Please click here to be authorized link yet? If you've been added to your firm's CLA it should make the EasyCLA check pass you (but you have to manually click on it) |
Resolves log data not being recorded due to use of console.log. Now properly uses step.log.
Fixes #1281