-
Notifications
You must be signed in to change notification settings - Fork 15
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
Option to use custom bug fix pattern #16
base: master
Are you sure you want to change the base?
Conversation
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.
First of all, thank you for your contribution!
Overall this looks great. I just have a few comments, mostly about allowing an arbitrary number of bugfix tags.
stdout = check_output(bash_cmd.split()).decode('utf-8').rstrip('\n') | ||
except CalledProcessError as err: | ||
print('Failed to execute bash command: {!r}'.format(str(bash_cmd))) | ||
exit(1) |
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.
Good call adding the non-zero exit status
try: | ||
stdout = check_output(bash_cmd.split()).decode('utf-8').rstrip('\n') | ||
except CalledProcessError as err: | ||
print('Failed to execute bash command: {!r}'.format(str(bash_cmd))) |
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.
Do we need to wrap bash_cmd
in str()
? It should be a string already I think.
# TODO: add option to specify custom bugfix tags | ||
bash_cmd = "git log -i --all --grep BUG --grep FIX --pretty=format:%h" | ||
bash_cmd = "git log -i --all --grep {} --grep {} --pretty=format:%h"\ | ||
.format(pattern[0], pattern[1]) |
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.
Let's do this in a way that allows for a variable number of bugfix tags, maybe something like:
grep_clause = ' '.join(['--grep {}'.format(tag) for tag in pattern])
bash_cmd = "git log -i --all --pretty=format:%h " + grep_clause
@@ -80,7 +84,7 @@ def get_git_log(commit=None): | |||
return stdout | |||
|
|||
|
|||
def get_bugfix_commits(): | |||
def get_bugfix_commits(pattern=None): | |||
"""Get the commits whose commit messages contain BUG or FIX. |
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.
We should probably update this docstring too.
@@ -14,7 +14,9 @@ def cli(): | |||
|
|||
|
|||
@cli.command() | |||
def train(): | |||
@click.option('-p', '--pattern', required=False, | |||
help="Bug fix pattern. Ex. BUG,FIX", type=str) |
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.
click
lets you specify an option multiple times by passing multiple=True
. Let's do that so we can accept an arbitrary number of tags, which will be nice.
One thing to watch out for though: using multiple=True
makes the option always return a tuple even if no arguments were passed, so we will need to change our check in get_bugfix_commits
from if pattern is None
to if len(pattern) == 0
.
Will fix |
In cases when you don't use
BUG
andFIX
to mark your bug fixes, you need to change it using--pattern
or-p
.Example:
P.S. БАГ is BUG in Russian.
Pretty self-explanatory.
Edit 1:
Also
_run_bash_command
now exits with error code 1 whenbash_cmd
exits with other error code then 0.