-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-927 Add git hook to check commit message (#2103)
* KTOR-927 Add git hook to check commit message
- Loading branch information
Showing
2 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
ALLOW = 0 | ||
RESTRICT = 1 | ||
|
||
|
||
def is_integer(value: str) -> bool: | ||
try: | ||
int(value) | ||
return True | ||
except ValueError as _: | ||
return False | ||
|
||
|
||
def is_correct_commit_message(message: str) -> bool: | ||
issue_name = first_line.split(" ")[0] | ||
|
||
# Allow fixup commits | ||
if issue_name in ["fixup!", "WIP"]: | ||
return True | ||
|
||
if issue_name.startswith("~"): | ||
return True | ||
|
||
prefix = "KTOR-" | ||
if issue_name.startswith(prefix) and is_integer(issue_name[len(prefix):]): | ||
return True | ||
|
||
print(f"Commit name should start with the issue number(like KTOR-1001). Current prefix is '{issue_name}'") | ||
return False | ||
|
||
|
||
if __name__ == "__main__": | ||
commit_message_filename: str = sys.argv[1] | ||
with open(commit_message_filename) as file: | ||
first_line: str = file.readline() | ||
|
||
exit_code = ALLOW if is_correct_commit_message(first_line) else RESTRICT | ||
exit(exit_code) |