forked from devlikeapro/waha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59015fc
commit 2d37d39
Showing
2 changed files
with
51 additions
and
0 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,38 @@ | ||
import subprocess | ||
import sys | ||
|
||
|
||
def get_staged_files(): | ||
result = subprocess.run(["git", "diff", "--cached", "--name-only"], stdout=subprocess.PIPE, text=True) | ||
files = result.stdout.splitlines() | ||
return files | ||
|
||
|
||
def get_commit_message(commit_msg_filepath): | ||
with open(commit_msg_filepath, 'r') as f: | ||
return f.readline().strip() | ||
|
||
|
||
def main(): | ||
commit_msg_filepath = sys.argv[1] | ||
commit_message = get_commit_message(commit_msg_filepath) | ||
staged_files = get_staged_files() | ||
|
||
has_plus_changes = any(f.startswith('src/plus') for f in staged_files) | ||
print(commit_message) | ||
starts_with_plus = commit_message.startswith('[PLUS]') | ||
|
||
if has_plus_changes and not starts_with_plus: | ||
print("'[PLUS]' not found in commit message, but there's changes are from 'src/plus'.") | ||
return 1 | ||
|
||
if starts_with_plus and not all(f.startswith('src/plus') for f in staged_files): | ||
print("'[PLUS]' found in commit message, but there's changes from other directories. \n" | ||
"Changes MUST be only from 'src/plus'.") | ||
return 1 | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |