Add command for configuring a repository to point to a Review Board server
Review Request #4662 — Created Sept. 28, 2013 and submitted
Information | |
---|---|
edwlee | |
RBTools | |
master | |
4699 | |
Reviewers | |
rbtools, students | |
Add command for configuring a repository to point to a Review Board server
The new command 'setup-repo' interactively creates the configuration file
.reviewboard in the user's current working directory.Reviewed at https://reviews.reviewboard.org/r/4662/
Tested with Git and Subversion on two Review Board servers.
Unit tests pass.
Description | From | Last Updated |
---|---|---|
'CommandError' imported but unused |
![]() |
|
Col: 80 E501 line too long (82 > 79 characters) |
![]() |
|
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
'CommandError' imported but unused |
![]() |
|
You might want to look at using distutils.util.strtobool, as that can support multiple ways of yes/no, and can just return … |
PU puiterwijk | |
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
local variable 'origcwd' is assigned to but never used |
![]() |
|
Duplicate line. Need to remove. |
ED edwlee | |
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
undefined name 'PerforceClient' |
![]() |
|
local variable 'newfile' is assigned to but never used |
![]() |
|
Col: 1 W391 blank line at end of file |
![]() |
|
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
undefined name 'PerforceClient' |
![]() |
|
local variable 'newfile' is assigned to but never used |
![]() |
|
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
undefined name 'PerforceClient' |
![]() |
|
local variable 'newfile' is assigned to but never used |
![]() |
|
Col: 20 E127 continuation line over-indented for visual indent |
![]() |
|
Col: 20 E127 continuation line over-indented for visual indent |
![]() |
|
Col: 80 E501 line too long (80 > 79 characters) |
![]() |
|
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
undefined name 'PerforceClient' |
![]() |
|
local variable 'newfile' is assigned to but never used |
![]() |
|
Col: 80 E501 line too long (83 > 79 characters) |
![]() |
|
Col: 20 E127 continuation line over-indented for visual indent |
![]() |
|
Col: 80 E501 line too long (80 > 79 characters) |
![]() |
|
Col: 80 E501 line too long (90 > 79 characters) |
![]() |
|
Col: 80 E501 line too long (80 > 79 characters) |
![]() |
|
'test' imported but unused |
![]() |
|
'json' imported but unused |
![]() |
|
I think I'd like "guess_current_branch" more. This method will actually "guess" the branch, rather than "get the guess". I also … |
SM smacleod | |
While a lot of old code doesn't match this, the format should be: """One-line summary.""" or: """One-line summary. Multi-line description. … |
|
|
I'd like to see a docstring on this, and as part of it an explanation (in git terms) of what … |
SM smacleod | |
This should not be changed like this here. Any command that talks to the Review Board server needs to support … |
SM smacleod | |
Imports go in three groups: Built-in Python modules. Third-party Python modules. Modules as part of the current codebase. The rbtools … |
|
|
Class names never use _. They're CamelCase. |
|
|
"Interactively creates" |
|
|
If you could try to wrap the text so that it's more consistent at where the line ends, that would … |
|
|
How about we just switch this to say "if the scm client supports it" |
SM smacleod | |
name = "config-repo" |
SM smacleod | |
Maybe we should have something about generating a configuration file here |
SM smacleod | |
I don't know how I feel about changing this from the same option we use for all other commands. Should … |
SM smacleod | |
Same note about docstrings. This applies to all remaining ones. |
|
|
Docstrings should have a single line summary on the first line, and then a longer description after, like your docstring … |
SM smacleod | |
These don't need to be raw strings. |
|
|
Same docstring formatting |
SM smacleod | |
This will not return every repository. The API resources are paged so you'll need to be looping through the pages … |
SM smacleod | |
Blank line between these (surrounding blocks) |
|
|
This if statement is a bit unwieldy. Maybe break it up. You can do: is_match = ( tool_name == repo.tool … |
|
|
Blank line before. |
|
|
It's unclear to me what's happening here. In one case, if the user says Yes, we return directly. Otherwise, if … |
|
|
We do this tool comparison twice. Might be nice to first filter into a list of repositories matching the proper … |
|
|
Blank line before. |
|
|
Missing a docstring for this function. |
|
|
This is unnecessary since the RBTools API doesn't support any reviewboard version <1.6.12 or something |
SM smacleod | |
Missing a docstring. |
|
|
This won't work in Python 2.4, or 2.5 without importing with_statement from __future__. |
|
|
print is wrong here. You should be using die(). |
|
|
This could be combined to one statement. |
|
|
Use parens for multiple lines instead of . In this case, we usually like to see it like: print ('......' … |
|
|
Shouldn't call sys.exit. Instead, just return. We don't want callers that call into these classes to exit prematurely. |
|
|
Ideally, this file wouldn't know which can be guessed. Instead, try calling get_guessed_branch, and if it raises NotImplementedError, catch it … |
|
|
let's make this "config-repo", instead of "config_repo". We've set a convention with the "api-get", and "list-repo-types" commands that we use … |
SM smacleod | |
All other commands use - instead of _. I think a better name for this would just be "setup", or … |
|
|
The === length should match the title. |
|
|
Should be one line. |
|
|
Python 2.4 doesn't support with, so we can't use that. |
|
|
"it attempts to guess" |
|
|
Not all repositories use this format. For example, git@github.com:reviewboard/reviewboard. Nothing else in our codebase attempts to fuzzy-match repositories. I'd suggest … |
|
|
This needs to compare against both path and mirror_path. |
|
|
One line. |
|
|
Can't use with on Python 2.4. |
|
|
Can't use .format() on the versions of Python we support. |
|
|
There will always be a name, and we should always generate with a name and not a path. |
|
|
This doesn't look like it will render the cofnig very nicely to the user. |
|
|
What about Y, N, YES, Yes, NO, No, etc? Is it case-sensitive? |
|
|
If this fails, we should probably display something like %s is not a valid answer first. |
|
|
Two blank lines between top-level items. |
|

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/create_rc.py
setup.py
Ignored Files: -
-
-

-
This is a review from Review Bot.
Tool: PEP8 Style Checker
Processed Files:
rbtools/commands/create_rc.py
setup.py
Ignored Files:

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/create_rc.py
setup.py
Ignored Files: -
-
-
-
-
rbtools/commands/create_rc.py (Diff revision 2) You might want to look at using distutils.util.strtobool, as that can support multiple ways of yes/no, and can just return True, False or ValueError.

-
This is a review from Review Bot.
Tool: PEP8 Style Checker
Processed Files:
rbtools/commands/create_rc.py
setup.py
Ignored Files:

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/create_rc.py
setup.py
Ignored Files: -
rbtools/commands/create_rc.py (Diff revision 3) local variable 'origcwd' is assigned to but never used
-
-

-
This is a review from Review Bot.
Tool: PEP8 Style Checker
Processed Files:
rbtools/commands/create_rc.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/create_rc.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -
-
-
-

-
This is a review from Review Bot.
Tool: PEP8 Style Checker
Processed Files:
rbtools/commands/create_rc.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files:

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/create_rc.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -
-
-
-
Summary: |
|
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
||||||||||||||||||||||||
Testing Done: |
|
||||||||||||||||||||||||
Diff: |
Revision 6 (+161 -3) |

-
This is a review from Review Bot.
Tool: PEP8 Style Checker
Processed Files:
rbtools/commands/config_repo.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -
rbtools/commands/config_repo.py (Diff revision 6) Col: 20
E127 continuation line over-indented for visual indent -
rbtools/commands/config_repo.py (Diff revision 6) Col: 20
E127 continuation line over-indented for visual indent -

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/config_repo.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -
-
-
-

-
This is a review from Review Bot.
Tool: PEP8 Style Checker
Processed Files:
rbtools/commands/config_repo.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -
-
rbtools/commands/config_repo.py (Diff revision 7) Col: 20
E127 continuation line over-indented for visual indent -
-
-

-
This is a review from Review Bot.
Tool: Pyflakes
Processed Files:
rbtools/commands/config_repo.py
setup.py
rbtools/clients/init.py
rbtools/commands/init.py
rbtools/clients/git.py
Ignored Files: -
-
-
-
-
-
rbtools/clients/__init__.py (Diff revision 8) While a lot of old code doesn't match this, the format should be:
"""One-line summary."""
or:
"""One-line summary.
Multi-line description.
""" -
rbtools/commands/config_repo.py (Diff revision 8) Imports go in three groups:
- Built-in Python modules.
- Third-party Python modules.
- Modules as part of the current codebase.
The rbtools imports should be separated from the distutils/pkg_resources ones.
-
-
-
rbtools/commands/config_repo.py (Diff revision 8) If you could try to wrap the text so that it's more consistent at where the line ends, that would be great. Each line should end as close as possible to column 79.
-
rbtools/commands/config_repo.py (Diff revision 8) Same note about docstrings.
This applies to all remaining ones.
-
-
-
rbtools/commands/config_repo.py (Diff revision 8) This if statement is a bit unwieldy. Maybe break it up. You can do:
is_match = (
tool_name == repo.tool and
self.match_repository_paths(...))if is_match:
May seem silly, but it's nice to keep conditionals a bit simpler.
-
-
rbtools/commands/config_repo.py (Diff revision 8) It's unclear to me what's happening here.
In one case, if the user says Yes, we return directly. Otherwise, if they say no, we're storing the name. "matched" makes it sound like one that's valid and good, but it seems to me that it's one that we don't want. That could come up multiple times, so that should be a list of discarded_repo_names.
Can you add some comments explaining the workflow for what this is all doing?
-
rbtools/commands/config_repo.py (Diff revision 8) We do this tool comparison twice. Might be nice to first filter into a list of repositories matching the proper tool. You can do this in the first pass so that you're only iterating through the good list the second time.
In fact, I mentioned a discarded_repo_names list above. We could build a list of good repo names that consists of every entry matching the repo name and not explicitly denied by the user.
-
-
-
-
rbtools/commands/config_repo.py (Diff revision 8) This won't work in Python 2.4, or 2.5 without importing
with_statement
from__future__
. -
-
-
rbtools/commands/config_repo.py (Diff revision 8) Use parens for multiple lines instead of .
In this case, we usually like to see it like:
print ('......' '....' % (...))
-
rbtools/commands/config_repo.py (Diff revision 8) Shouldn't call sys.exit. Instead, just return. We don't want callers that call into these classes to exit prematurely.
-
rbtools/commands/config_repo.py (Diff revision 8) Ideally, this file wouldn't know which can be guessed. Instead, try calling get_guessed_branch, and if it raises NotImplementedError, catch it and ignore. We'll only store a branch if the tool supports it.
That way, it's easy to add support without touching this file, and third parties can add support as well to their own modules.
-
setup.py (Diff revision 8) All other commands use - instead of _.
I think a better name for this would just be "setup", or "setup-repo", but I want David and Steven to weigh in on that.
-
-
rbtools/clients/__init__.py (Diff revision 8) I think I'd like "guess_current_branch" more. This method will actually "guess" the branch, rather than "get the guess".
I also kind of like throwing "current" in there since this could be a working directory supporting multiple branches (such as in the git case).
As for the docstring styling, let's go ahead and update this to look like the PEP8 docstrings (see sanitize_changenum above). I understand you're probably just following the majority style in this file, but it does appear we've started to transition to the standard style, so lets keep going.
I'd also like if we could be a little more verbose in describing the intended purpose of this method. How about something like::
"""Guess the repository branch of the current directory. Derived classes should override this method if they are able to determine the current branch of the working directory. The name of the branch which diffs will be generated against should returned. If a derived class supports guessing, but is unable to determine the branch, ``None`` should be returned. """
-
rbtools/clients/git.py (Diff revision 8) I'd like to see a docstring on this, and as part of it an explanation (in git terms) of what branch is being returned
-
rbtools/commands/__init__.py (Diff revision 8) This should not be changed like this here.
Any command that talks to the Review Board server needs to support the "username" and "password" options. (These should be added to your command)
As part of a cleanup I'd like to have some pre-defined options like:
RB_SERVER_OPTIONS = [ ... ] SCM_CLIENT_OPTIONS = [ ... ]
and any commands that use the respective functionality just add these to their list of options. I haven't got around to doing this yet though.
-
rbtools/commands/config_repo.py (Diff revision 8) How about we just switch this to say "if the scm client supports it"
-
-
rbtools/commands/config_repo.py (Diff revision 8) Maybe we should have something about generating a configuration file here
-
rbtools/commands/config_repo.py (Diff revision 8) I don't know how I feel about changing this from the same option we use for all other commands.
Should probably be:
Option("--server", dest="server", metavar="SERVER", config_key="REVIEWBOARD_URL", default=None, help="specify a different Review Board server to use"),
-
rbtools/commands/config_repo.py (Diff revision 8) Docstrings should have a single line summary on the first line, and then a longer description after, like your docstring for the whole command
-
-
rbtools/commands/config_repo.py (Diff revision 8) This will not return every repository. The API resources are paged so you'll need to be looping through the pages as well. You can see an example of this in "rbt post", in the "get_repository_path" method. You'll do something like:
repositories = api_root.get_repositories() try: while True: for repo in repositories: # Your looping in here repositories = repositories.get_next() except StopIteration: pass
-
rbtools/commands/config_repo.py (Diff revision 8) This is unnecessary since the RBTools API doesn't support any reviewboard version <1.6.12 or something
-
setup.py (Diff revision 8) let's make this "config-repo", instead of "config_repo". We've set a convention with the "api-get", and "list-repo-types" commands that we use dashes to seperate words in command names.
-
-
rbtools/clients/__init__.py (Diff revision 8) I don't think my description for this method is clear enough. The method is meant to guess the branch name of the server's repository (i.e. for the BRANCH config value in .reviewboardrc), not the branch of the current working directory. In this case we wouldn't want "current" in the method name.
Change Summary:
Update description.
Description: |
|
---|
Change Summary:
-Move confirm() to its own file so it can be shared.
-Add command documentation
-Simplify logic in prompting for a matching repository.
-Import with_statement from future for compatibility with Python
2.4 and 2.5.
-Fix loop in iterating through repositories so it retrieve all possible
repositories.
-Update doc strings.
-Fix styling issues.
Diff: |
Revision 10 (+235 -1) |
---|
Change Summary:
-Rename get_guessed_branch() to get_current_branch()
-Extract confirm() to its own file for reusability
-Move confirmation for creating/overwriting .reviewboardrc to the end
Diff: |
Revision 11 (+242 -1) |
---|
-
-
-
-
rbtools/commands/setup_repo.py (Diff revision 12) Python 2.4 doesn't support
with
, so we can't use that. -
-
rbtools/commands/setup_repo.py (Diff revision 12) Not all repositories use this format. For example,
git@github.com:reviewboard/reviewboard
.Nothing else in our codebase attempts to fuzzy-match repositories. I'd suggest just doing a direct compare. You probably won't need this function.
-
rbtools/commands/setup_repo.py (Diff revision 12) This needs to compare against both
path
andmirror_path
. -
-
-
rbtools/commands/setup_repo.py (Diff revision 12) Can't use
.format()
on the versions of Python we support. -
rbtools/commands/setup_repo.py (Diff revision 12) There will always be a name, and we should always generate with a name and not a path.
-
rbtools/commands/setup_repo.py (Diff revision 12) This doesn't look like it will render the cofnig very nicely to the user.
-
rbtools/utils/console.py (Diff revision 12) What about Y, N, YES, Yes, NO, No, etc? Is it case-sensitive?
-
rbtools/utils/console.py (Diff revision 12) If this fails, we should probably display something like
%s is not a valid answer
first.
Change Summary:
Fixed open issues.
Depends On: |
|
||
---|---|---|---|
Diff: |
Revision 13 (+239 -1) |
Change Summary:
Rebased changes.
Depends On: |
|
||
---|---|---|---|
Diff: |
Revision 14 (+238 -1) |
-
This looks good to me but I think Christian or Steven should take one more look.
-