Skip to content

Commit

Permalink
KTOR-927 Add git hook to check commit message (#2103)
Browse files Browse the repository at this point in the history
* KTOR-927 Add git hook to check commit message
  • Loading branch information
e5l authored Oct 8, 2020
1 parent 9a839b7 commit 980e529
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ if there is already an open ticket and open a new one if not yet opened.

Contributions are made using Github [pull requests](https://help.github.com/en/articles/about-pull-requests).

1. [Create](https://github.com/ktorio/ktor/compare) a new PR, your PR should request to merge to the **master** branch.
2. Ensure that the description is clear, refer to an existing ticket/bug if applicable.
3. When contributing a new feature, provide motivation and use-cases describing why
1. Open (or find) the corresponding [YT](https://youtrack.jetbrains.com/issues/KTOR) issue.
2. Please make sure that commit messages start with issue number (like `KTOR-1001`). You can copy `githook/prepare-commit-msg` to `.git/hooks` to enable automatic commit message check.
3. [Create](https://github.com/ktorio/ktor/compare) a new PR, your PR should request to merge to the **master** branch.
4. Ensure that the description is clear, refer to an existing ticket/bug if applicable.
5. When contributing a new feature, provide motivation and use-cases describing why
the feature is important enough to be delivered with ktor to everyone.
4. Adding and updating features may require to update the [documentation](https://github.com/ktorio/ktorio.github.io).
6. Adding and updating features may require to update the [documentation](https://github.com/ktorio/ktorio.github.io).
Create a documentation PR and link both pull requests.
5. Make sure you have adequate tests added and no existing tests were broken.
7. Make sure you have adequate tests added and no existing tests were broken.

# Styleguides

Expand Down
41 changes: 41 additions & 0 deletions githook/prepare-commit-msg
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)

0 comments on commit 980e529

Please sign in to comment.