Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Option to use custom bug fix pattern #16

wants to merge 1 commit into from

Conversation

nm17
Copy link

@nm17 nm17 commented Feb 23, 2018

In cases when you don't use BUG and FIX to mark your bug fixes, you need to change it using --pattern or -p.

Example:

$ gitrisky train -p БАГ,ФИКС

P.S. БАГ is BUG in Russian.
Pretty self-explanatory.
Edit 1:
Also _run_bash_command now exits with error code 1 when bash_cmd exits with other error code then 0.

@nm17
Copy link
Author

nm17 commented Feb 24, 2018

@hinnefe2

Copy link
Owner

@hinnefe2 hinnefe2 left a 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)
Copy link
Owner

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)))
Copy link
Owner

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])
Copy link
Owner

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.
Copy link
Owner

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)
Copy link
Owner

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.

@nm17
Copy link
Author

nm17 commented Feb 27, 2018

Will fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants