-
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?
Changes from all commits
5857bf3
f1fdfca
6ef713e
af46924
2d914ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,20 +1,20 @@ | ||||||
| import { Action, Step } from '../../actions'; | ||||||
| import { getCommitConfig } from '../../../config'; | ||||||
|
|
||||||
| const isMessageAllowed = (commitMessage: string): boolean => { | ||||||
| const isMessageAllowed = (commitMessage: any): string | null => { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment explaining that a string response indicates failure would be good
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps also renaming the function to match output style, e.g. to |
||||||
| try { | ||||||
| const commitConfig = getCommitConfig(); | ||||||
|
|
||||||
| // Commit message is empty, i.e. '', null or undefined | ||||||
| if (!commitMessage) { | ||||||
| console.log('No commit message included...'); | ||||||
| return false; | ||||||
| // console.log('No commit message included...'); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented lines |
||||||
| return 'No commit message included...'; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea why all the error messages end in an ellipsis, they don't need to
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| // Validation for configured block pattern(s) check... | ||||||
| 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...'); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented lines |
||||||
| return 'A non-string value has been captured for the commit message...'; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| // Configured blocked literals and patterns | ||||||
|
|
@@ -36,15 +36,15 @@ const isMessageAllowed = (commitMessage: string): boolean => { | |||||
|
|
||||||
| // Commit message matches configured block pattern(s) | ||||||
| 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...'); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented lines |
||||||
| return 'Commit message is blocked via configured literals/patterns...'; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| } catch (error) { | ||||||
| console.log('Invalid regex pattern...'); | ||||||
| return false; | ||||||
| // console.log('Invalid regex pattern...'); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented lines |
||||||
| return 'Invalid regex pattern...'; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| return true; | ||||||
| return null; | ||||||
| }; | ||||||
|
|
||||||
| // Execute if the repo is approved | ||||||
|
|
@@ -53,13 +53,23 @@ const exec = async (req: any, action: Action): Promise<Action> => { | |||||
|
|
||||||
| const uniqueCommitMessages = [...new Set(action.commitData?.map((commit) => commit.message))]; | ||||||
|
|
||||||
| const illegalMessages = uniqueCommitMessages.filter((message) => !isMessageAllowed(message)); | ||||||
| // const illegalMessages = uniqueCommitMessages.filter((message) => !isMessageAllowed(message)); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'}`, | ||||||
| ); | ||||||
| }); | ||||||
|
Comment on lines
+57
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the function twice is inefficent. Perhaps swap out |
||||||
|
|
||||||
| // step.error = true; | ||||||
| // step.log(`The following commit messages are illegal: ${illegalMessages}`); | ||||||
|
Comment on lines
+71
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed |
||||||
| step.setError( | ||||||
| `\n\n\nYour push has been blocked.\nPlease ensure your commit message(s) does not contain sensitive information or URLs.\n\nThe following commit messages are illegal: ${JSON.stringify(illegalMessages)}\n\n`, | ||||||
| ); | ||||||
|
|
@@ -68,7 +78,8 @@ const exec = async (req: any, action: Action): Promise<Action> => { | |||||
| return action; | ||||||
| } | ||||||
|
|
||||||
| console.log(`The following commit messages are legal: ${uniqueCommitMessages}`); | ||||||
| // console.log(`The following commit messages are legal: ${uniqueCommitMessages}`); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||||||
| step.log(`The following commit messages are legal: ${JSON.stringify(uniqueCommitMessages)}`); | ||||||
| action.addStep(step); | ||||||
| return action; | ||||||
| }; | ||||||
|
|
||||||
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