-
Notifications
You must be signed in to change notification settings - Fork 153
refactor: Improve logging in processors/action chain #1338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
|
kriswest
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix the any
| if (!commitMessage) { | ||
| console.log('No commit message included...'); | ||
| return false; | ||
| // console.log('No commit message included...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented lines
| import { getCommitConfig } from '../../../config'; | ||
|
|
||
| const isMessageAllowed = (commitMessage: string): boolean => { | ||
| const isMessageAllowed = (commitMessage: any): string | null => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining that a string response indicates failure would be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented lines
| 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...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented lines
| console.log('Invalid regex pattern...'); | ||
| return false; | ||
| // console.log('Invalid regex pattern...'); | ||
| return 'Invalid regex pattern...'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented line
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed
| } | ||
|
|
||
| console.log(`The following commit messages are legal: ${uniqueCommitMessages}`); | ||
| // console.log(`The following commit messages are legal: ${uniqueCommitMessages}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
|
@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