Last active
April 17, 2023 11:36
-
-
Save nikhilw/7492c3d0426543f983acedbf1fc9f600 to your computer and use it in GitHub Desktop.
Revisions
-
nikhilw revised this gist
Apr 17, 2023 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,8 @@ # NOTES: # 1. This is one of the three implementation, this one is in Python. if you do not have python installed, there are 'node' and 'scala' counterparts. # 2. To use this file, place it in .git/hooks/ in your repository. # 3. You can also use this script with the 'husky' npm module. import sys import os import re -
nikhilw created this gist
Apr 5, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/usr/bin/env python3 # NOTES: # 1. This is one of the three implementation, this one is in Python. if you do not have python installed, there are 'node' and 'scala' counterparts. # 2. To use this file, place it in .git/hooks/ in your repository. # 3. You can also use this script to along with 'husky' npm module. import sys import os import re filename = sys.argv[1] or os.getenv('GIT_PARAMS') with open(filename, 'r') as f: msg = f.read() msg = re.sub(r'\r\n|\r|\n', ' ', msg) maxLen = 50 if len(msg) > 50 else len(msg) msg = msg[0:maxLen] matchTest = re.search('([A-Z]+-?\d+|Adhoc)\: (.+: )?(Added|Removed|BugFix|Modified|Feature|Merged|Refactored|Release): (.+){15,}$', msg) exitCode = 0 if (not (matchTest is None)) else 1 if (exitCode == 0): print("SUCCESS: Commit ACCEPTED.") else: print("ERROR: Commit REJECTED. REASON: Your commit message: '" + msg + "' does not follow the commit message convention."); print("Convention: '[JIRAID]: [Optional clientId]: [One Primary Change Type: Added|Removed|BugFix|Modified|Feature|Merged|Refactored|Release]: [Message describing the change. If absolutely necessary, you can add multiple Change types here.]"); print("Sample: IT-123: Added: git hook to validate commit message."); exit(exitCode)