Add commit message template
Review Request #6833 — Created Jan. 27, 2015 and discarded
Some RBT commands, like patch/land, allow users to commit with a commit message. Previously, this commit message would be hard coded with python strings, however adding the option to specify a user defined template would be more helpful.
The added option is --template <template_directory_or_name>, which could be any of:
- the template's directory
- the template's directory within the "TEMPLATES_DIR" folder, as specified in .reviewboardrc
- the name of the template, as specified in .reviewboardrcIf no template is specified, a default template is selected.
If no template exists under the argument, the user will be prompted for the default template.
As template design is up to the user, the code is not responsible for handling misconfigured templates.
I've tested with (rbt patch):
--template <existing_template_path>
--template <non_existant_template_path>
--template <existing_template in TEMPLATES_DIR>
--template <variable name in .reviewboardrc>
--template with invalid syntax (like not closing the if statement)
--template attempting to access invalid variables
--commit (no --template, which should render the default template)Unit tests are available as well, but I don't know if they make sense tested that way.
Description | From | Last Updated |
---|---|---|
Col: 1 W293 blank line contains whitespace |
reviewbot | |
This doesn't belong in this change. |
brennie | |
Import statements should go at the beginning of the file. This is grouped in the second group (third-party non-rbtools imports). |
brennie | |
I know this is a first draft, but perhaps a flag and/or config option would be a better place for … |
brennie | |
Col: 62 W291 trailing whitespace |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 40 W291 trailing whitespace |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Usually the pattern is except TemplateNotFound as e: Same below. |
brennie | |
You can remove these lines. No point to keep them commented because they will be in version control. |
brennie | |
Col: 5 E303 too many blank lines (2) |
reviewbot | |
So Jinja2 templates aren't actually python files. This would be better marked as a .txt file because Review Bot is … |
brennie | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 42 E225 missing whitespace around operator |
reviewbot | |
You are setting variables here but using review_request.bugs_closed later. Why not just use review_request.foo for everything? |
brennie | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 50 E225 missing whitespace around operator |
reviewbot | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 52 E225 missing whitespace around operator |
reviewbot | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 44 E225 missing whitespace around operator |
reviewbot | |
You don't want two blank lines between summary and description. |
brennie | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 11 E225 missing whitespace around operator |
reviewbot | |
You don't want two blank lines between description and testing done. You may want to put the blank line after … |
brennie | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 19 E228 missing whitespace around modulo operator |
reviewbot | |
Col: 1 E112 expected an indented block |
reviewbot | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 11 E225 missing whitespace around operator |
reviewbot | |
Col: 33 E228 missing whitespace around modulo operator |
reviewbot | |
Col: 2 E225 missing whitespace around operator |
reviewbot | |
Col: 1 E112 expected an indented block |
reviewbot | |
Again, you probably don't want two blank lines here. |
brennie | |
'pdb' imported but unused |
reviewbot | |
Col: 80 E501 line too long (94 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 66 W291 trailing whitespace |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 40 W291 trailing whitespace |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 80 E501 line too long (90 > 79 characters) |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
undefined name 'default_templates_dir' |
reviewbot | |
Col: 80 E501 line too long (92 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (94 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
There's some inconsistency in the blank lines here. If the 'testing done' field is present, there's plenty of space, but … |
david | |
os and pkg_resources are standard library modules, and so should be in their own group before six. six should be … |
david | |
These should be a single import statement and kept alphabetical: from jinja2 import (Environment, FileSystemLoader, StrictUndefined, TemplateError, TemplateNotFound, UndefinedError) |
david | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
extract_template is a pretty weird name for this. How about render_commit_message_template? |
david | |
Col: 66 W291 trailing whitespace |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 40 W291 trailing whitespace |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 80 E501 line too long (90 > 79 characters) |
reviewbot | |
How about a message more like raise CommandError('Syntax error in template %s: %s' % (template_name, ue.message)) |
david | |
I'd like to see this error message contain the template name, and put it all on one line. Something like … |
david | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
This should probably check to make sure that the template name isn't absolute before joining it to cwd/templates |
david | |
undefined name 'default_templates_dir' |
reviewbot | |
Col: 80 E501 line too long (92 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (94 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (99 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (112 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (84 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (87 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (94 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 29 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 29 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 68 W291 trailing whitespace |
reviewbot | |
Col: 37 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 57 W291 trailing whitespace |
reviewbot | |
Col: 80 E501 line too long (99 > 79 characters) |
reviewbot | |
Col: 100 W291 trailing whitespace |
reviewbot | |
Col: 80 E501 line too long (111 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
Col: 33 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 33 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 80 E501 line too long (102 > 79 characters) |
reviewbot | |
local variable 'e' is assigned to but never used |
reviewbot | |
Col: 37 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 80 E501 line too long (82 > 79 characters) |
reviewbot | |
Col: 33 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot | |
Col: 42 W291 trailing whitespace |
reviewbot | |
local variable 'e' is assigned to but never used |
reviewbot | |
Col: 80 E501 line too long (84 > 79 characters) |
reviewbot | |
self.config.get(name) should be the equivalent of the self.config[name] if condition else None |
VT VTL-Developer | |
Col: 80 E501 line too long (98 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
Col: 31 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 33 E127 continuation line over-indented for visual indent |
reviewbot | |
I noticed you have three cases. For the case where there's only template_name, it get combines with working directory and … |
VT VTL-Developer | |
Col: 59 W291 trailing whitespace |
reviewbot | |
Col: 80 E501 line too long (89 > 79 characters) |
reviewbot | |
Col: 71 W291 trailing whitespace |
reviewbot | |
Add a real help description. |
brennie | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
One blank line instead of two. |
brennie | |
Add a blank line between these two. |
brennie | |
Undo this change. |
brennie | |
We only use trailing commas on the last line of a dictionary definition. |
brennie | |
Move this up to the previous line. |
brennie | |
Use e instead of tnfe. This is for consistency with the rest of the codebase. |
brennie | |
Use e instead of ue. |
brennie | |
Use e instead of te. |
brennie | |
We don't use str.format. Please use % instead for string formatting. |
brennie | |
More than one of these can fit on a line. |
brennie | |
Blank line between a statement and a block |
brennie | |
We don't use str.format. Please use % for formatting instead. |
brennie | |
This string isn't formatted correctly. There will be no space between file and must. Also, please use all available line … |
brennie | |
Since you are doing the following: else: if foo: bar() else: baz() This can be changed to: elif foo: bar() … |
brennie | |
Isn't this the template filename, not the directory? |
brennie | |
One blank line between these. |
brennie | |
Why unset the name here? |
brennie | |
Use %s instead for string formatting. |
brennie | |
More than one of these can fit on a line. |
brennie | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
'Template' imported but unused |
reviewbot | |
Col: 80 E501 line too long (89 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (80 > 79 characters) |
reviewbot | |
Col: 1 W293 blank line contains whitespace |
reviewbot | |
undefined name 'ue' |
reviewbot | |
Please revert this change. |
david | |
Please revert this change. |
david | |
This is part of a separate review request and should not be present in this change. |
david | |
How about just doing import jinja2 and then using qualified names (jinja2.Environment) for each of these? Many of these names … |
david | |
This should be a fully-qualified module name (rbtools.utils.console) |
david | |
This method should have a docstring. |
david | |
Based on this code, it looks like directory is actually a filename, not a directory. |
david | |
Comments should have proper capitalization and punctuation. |
david | |
We generally don't use try/else. Instead, you can move template.render() into the try case above and then have all the … |
david | |
Is this the best name for this method? Probably not. |
david | |
This doesn't look like it's returning the directory name (rather, it looks like it's returning a filename). The explanation of … |
david | |
This function isn't terribly well named anymore. Can we change it to be build_commit_message? |
david | |
'extract_commit_message' imported but unused |
reviewbot | |
undefined name 'build_commit_message' |
reviewbot | |
'extract_commit_message' imported but unused |
reviewbot | |
undefined name 'build_commit_message' |
reviewbot | |
Please revert this change. |
david | |
Revert this change. |
david | |
I'm not sure why you set these variables, given that later on you use review_request.bugs_closed. Can we just prefix all … |
david | |
Should have a space before the closing %} |
david | |
Should have a space before the closing %} |
david | |
This should be a docstring, not a comment (and change 'Returns' to 'Return' and add a period at the end.) |
david | |
Returns -> Return. |
david | |
What is 'template_cmnd'? That string doesn't appear anywhere else in this change. |
david | |
This should present an error that the commit message template directory could not be found. |
david | |
Please add a class docstring. |
david | |
Indent this 4 more spaces. |
david | |
Please add docstrings for all the test methods in here. We want to print nice things with nosetests -v |
david | |
Alphabetize these. |
brennie | |
I would reword this to say something like "Use the specified template (either in the directory specified in .reviewboardrc or … |
brennie | |
We use single quotes for strings. |
brennie | |
This should be on the previous line. |
brennie | |
Since we're using this in multiple places, this might be worth putting into a list in __init__.py and referencing it … |
brennie | |
See my other comment. |
brennie | |
We use single quotes for strings. |
brennie | |
This should be on the previous line. |
brennie | |
Use single quotes for all these strings. |
brennie | |
Can you put the first %s in double quotes? |
brennie | |
Use a %-formatting expression. Its more efficient than string concatenation. |
brennie | |
Can you format that is as a reStructured Text List and mark the keys with double backticks, e.g. * ``foo``: … |
brennie | |
Can we rename template_cmd to something like template_arg or specified_template? template_cmd seems like an inaccurate name for it. |
brennie | |
Maybe this should this just be template ? |
brennie | |
Blank line between these. |
brennie | |
Put this on the previous line. |
brennie | |
Use a %-formatting expression here. |
brennie | |
Blank line between these. |
brennie | |
Blank line between these. |
brennie | |
Blank line between these. |
brennie | |
Alphabetize these. |
brennie | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Can you format the docstring as such: def render_template(filename, review_request): """Render a commit message template. It is up to the … |
david | |
This should be a docstring, not a comment. |
david | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
No blank line between the docstring and code for methods. |
david | |
All test docstrings should start with "Testing" instead of "Test". Here and below. |
david | |
First line of a docstring should come right after """ ("""Render a template...) |
david | |
This should just be """Return the filename of the default template.""" (note: one line, with period) |
david | |
Instead of defining a new empty class for this, I think you could just do mock_review_request = object() |
david | |
alphabetical order |
VT VTL-Developer | |
If .reviewboardrc specifies a template, it should be used for all commits, without needing to pass an argument. |
chipx86 | |
This isn't needed. |
chipx86 | |
The wrapping should use up more of the line. |
chipx86 | |
Same comments here. |
chipx86 | |
This should be part of the next group of imports. |
chipx86 | |
This should use format strings, instead of string concatenation. |
chipx86 | |
Blank line between these. |
chipx86 | |
This is deprecated. You'll need to rewrite the code to use os.walk instead. |
chipx86 | |
Looks like trim_blocks will easily fit on the previous line. |
chipx86 | |
I don't know that a newline is appropriate here. Can it just be: 'Template error: %s' ? |
chipx86 | |
You can use os.path.abspath(template_arg) instead, and it will do the equivalent. |
chipx86 | |
This leaves out the space between sentences. |
chipx86 | |
This code is repeating itself. You should rewrite it to only do this once. |
chipx86 | |
Same here. |
chipx86 | |
Missing a trailing period. |
chipx86 | |
Missing a trailing period. |
chipx86 | |
Must be in alphabetical order. |
chipx86 | |
You shouldn't really use """ here. Instead, it's best to just do: mock_template = ( 'Start\n' '...\n' '...\n') That way, … |
chipx86 | |
These really should go in the tests themselves, so that they're self-contained and not vulnerable to impact from another test … |
chipx86 | |
This should be done in setUp(). |
chipx86 | |
I missed this part of the design before. I realize now that this is allowing multiple templates per tree. I've … |
chipx86 | |
No backticks here. It'll actually render incorrectly, as comments are meant to be in ReST syntax, where backticks are used … |
chipx86 | |
Might be nice to have a bit of information on the format of the template here. Things like how variables/functions … |
chipx86 | |
You should be able to use os.path.split here, to do this in one go. |
chipx86 | |
Missing a trailing period. |
chipx86 | |
Should use single quotes where possible. |
chipx86 | |
"Error" shouldn't be capitalized. |
chipx86 | |
We may want to check that this is a directory first, and provide an error otherwise. |
chipx86 | |
This should just be: if not default_templates: Better than checking < 1, since the only reasonable value is 0. |
chipx86 | |
Blank line here. |
chipx86 | |
I kind of think that if the template is missing, we should just error out. That's a very clear configuration … |
chipx86 | |
Missing a trailing period. "Raises" is maybe the wrong word here? |
chipx86 | |
'build_commit_message' imported but unused |
reviewbot | |
Col: 69 W291 trailing whitespace |
reviewbot | |
undefined name 'extract_commit_message' |
reviewbot | |
'build_commit_message' imported but unused |
reviewbot | |
Col: 69 W291 trailing whitespace |
reviewbot | |
undefined name 'extract_commit_message' |
reviewbot |
-
-
-
Import statements should go at the beginning of the file. This is grouped in the second group (third-party non-rbtools imports).
-
I know this is a first draft, but perhaps a flag and/or config option would be a better place for this. Something like
TEMPLATE_ENV = 'templates' POST_TEMLATE = 'post.txt'
with some reasonable defaults. Or it could be passed in as a parameter to the function. I'm not sure about this.
-
-
You can remove these lines. No point to keep them commented because they will be in version control.
-
So Jinja2 templates aren't actually python files. This would be better marked as a
.txt
file because Review Bot is going to keep having issues with it. -
You are setting variables here but using
review_request.bugs_closed
later. Why not just usereview_request.foo
for everything? -
-
You don't want two blank lines between description and testing done.
You may want to put the blank line after the
{% if testing_done %}
bit.
-
- Branch:
-
tien_templatemaster
- Commit:
-
d01821c33009976ea4a4b7e5fe99eed374ff14b001c0355dd1fe65eb3ecdf4ab429d015d7e849523
-
Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
There's some inconsistency in the blank lines here. If the 'testing done' field is present, there's plenty of space, but if it's not, the bugs and review request URL will be jammed up right against the description.
We should also have a blank line after the summary.
-
os and pkg_resources are standard library modules, and so should be in their own group before
six
.six
should be grouped with the jinja2 imports. -
These should be a single import statement and kept alphabetical:
from jinja2 import (Environment, FileSystemLoader, StrictUndefined, TemplateError, TemplateNotFound, UndefinedError)
-
-
How about a message more like
raise CommandError('Syntax error in template %s: %s' % (template_name, ue.message))
-
I'd like to see this error message contain the template name, and put it all on one line. Something like this:
raise CommandError('Unknown error while rendering commit-message template %s: %s' % (template_name, e.message))
-
This should probably check to make sure that the template name isn't absolute before joining it to cwd/templates
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Groups:
-
Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
-
-
I noticed you have three cases. For the case where there's only template_name, it get combines with working directory and template_name becomes empty. For the case where there's a template_dir, it gets added to working directory, and the template_name can or can not be empty. It seems a bit inconsistent. Not familiar with the templating, so I don't know if it accomodates for that, but my view I feel it may cause errors.
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/patch.py rbtools/commands/post.py rbtools/utils/commands.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
This string isn't formatted correctly. There will be no space between
file
andmust
. Also, please use all available line width efficiently. -
Since you are doing the following:
else: if foo: bar() else: baz()
This can be changed to:
elif foo: bar() else: baz()
This reduces the nesting and makes the code easier to follow.
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
- Summary:
-
Add commit message template prototypeAdd commit message template
- Description:
-
~ This is a draft only
~ Some RBT commands, like patch/land, allow users to commit with a commit message. Previously, this commit message would be hard coded with python strings, however adding the option to specify a user defined template would be more helpful.
+ + The added option is --template <template_directory_or_name>, which could be any of:
+ - the template's directory + - the template's directory within the "TEMPLATES_DIR" folder, as specified in .reviewboardrc + - the name of the template, as specified in .reviewboardrc + + If no template is specified, a default template is selected.
+ If no template exists under the argument, the user will be prompted for the default template. + As template design is up to the user, the code is not responsible for handling misconfigured templates. - Testing Done:
-
+ I've tested with (rbt patch):
+ --template <existing_template_path> + --template <non_existant_template_path> + --template <existing_template in TEMPLATES_DIR> + --template <variable name in .reviewboardrc> + --template with invalid syntax (like not closing the if statement) + --template attempting to access invalid variables + --commit (no --template, which should render the default template) + + Unit tests are available as well, but I don't know if they make sense tested that way.
- Commit:
-
3f6eb04aaeaadcac44c2da017563fd90c86fe38d265f134d4fcbfffcbd4e5ea82acb75307e20f250
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
How about just doing
import jinja2
and then using qualified names (jinja2.Environment
) for each of these? Many of these names are pretty generic, and when looking at names likeEnvironment
andUndefinedError
it's not immediately apparent that these are part of jinja2. -
-
-
-
-
We generally don't use try/else. Instead, you can move
template.render()
into the try case above and then have all the exception handlers at one level:try: env = Environment(...) template = env.get_template(template_name) return template.render(review_request=review_request) except TemplateNotFound as e: ... except UndefinedError as e: ... ...
-
-
This doesn't look like it's returning the directory name (rather, it looks like it's returning a filename).
The explanation of what this method does should also be a docstring instead of a comment.
-
- Change Summary:
-
Changed mostly formatting issues based on David's code reviews.
I am pretty sure this works, what do I have to do next to land this?
- Commit:
-
265f134d4fcbfffcbd4e5ea82acb75307e20f25060fb63308b25b0659198d233fc995297b9c64393
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/commands/post.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
I'm not sure why you set these variables, given that later on you use
review_request.bugs_closed
. Can we just prefix all variables withreview_request.
? -
-
-
This should be a docstring, not a comment (and change 'Returns' to 'Return' and add a period at the end.)
-
-
-
-
-
-
Please add docstrings for all the test methods in here. We want to print nice things with
nosetests -v
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
I would reword this to say something like
"Use the specified template (either in the directory specified in .reviewboardrc or by its path) to generate the commit message."
Also, I would put the space on the previous line because it reads more nicely.
-
-
-
Since we're using this in multiple places, this might be worth putting into a list in
__init__.py
and referencing it elsewhere (so that we're not repeating ourselves). -
-
-
-
-
-
-
Can you format that is as a reStructured Text List and mark the keys with double backticks, e.g.
* ``foo``: bar * ``bar``: baz
-
Can we rename
template_cmd
to something liketemplate_arg
orspecified_template
?template_cmd
seems like an inaccurate name for it. -
-
-
-
-
-
-
-
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
Just some style nits:
-
Can you format the docstring as such:
def render_template(filename, review_request): """Render a commit message template. It is up to the template author to ensure that the syntax is correct. If not, this method will raise an error with Jinja2's error message. """
Specifically, the changes are:
- First line should be a short summary.
- Blank line between summary and more extensive description.
- Imperative mood in the summary ("Render" rather than "Renders").
- Periods at the end of sentences. -
-
-
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
If
.reviewboardrc
specifies a template, it should be used for all commits, without needing to pass an argument. -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
You shouldn't really use
"""
here. Instead, it's best to just do:mock_template = ( 'Start\n' '...\n' '...\n')
That way, we better control newline characters and indentation, producing more reliable test results.
Same with all others.
-
These really should go in the tests themselves, so that they're self-contained and not vulnerable to impact from another test wanting to modify a string slightly.
-
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
I missed this part of the design before. I realize now that this is allowing multiple templates per tree. I've discussed this with others, and I think it's probably best to keep this simple and just have a single template specified in
.reviewboardc
.I think we should focus on one template, and don't provide an option to override.
The reason is that a project is going to have a standard, and they want all commits to meet that standard. If something more custom is needed, it can just be a manually-created/augmented commit, but I don't think there are any cases where people are going to need multiple templates here.
What use-cases did you have in mind?
-
No backticks here. It'll actually render incorrectly, as comments are meant to be in ReST syntax, where backticks are used for document references.
-
Might be nice to have a bit of information on the format of the template here. Things like how variables/functions are used.
-
-
-
-
-
-
This should just be:
if not default_templates:
Better than checking
< 1
, since the only reasonable value is 0. -
-
I kind of think that if the template is missing, we should just error out. That's a very clear configuration problem.
-
-
Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt Tool: PEP8 Style Checker Processed Files: rbtools/commands/land.py rbtools/utils/commands.py rbtools/utils/tests.py rbtools/commands/patch.py Ignored Files: rbtools/templates/default.txt