Option to use custom bug fix pattern#16
Option to use custom bug fix pattern#16nm17 wants to merge 1 commit intohinnefe2:masterfrom nm17:custom-bugfix-pattern
Conversation
hinnefe2
left a comment
There was a problem hiding this comment.
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.
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.
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.
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
|
|
||
| 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.
We should probably update this docstring too.
| @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.
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
BUGandFIXto mark your bug fixes, you need to change it using--patternor-p.Example:
P.S. БАГ is BUG in Russian.
Pretty self-explanatory.
Edit 1:
Also
_run_bash_commandnow exits with error code 1 whenbash_cmdexits with other error code then 0.