Setting up the bot to handle Git repositories and pass the repository paths to the tools
Review Request #5869 — Created May 23, 2014 and discarded
Sets up repository on ReviewBot load
- stores repositories in root folder
- updates repositories programaticallySupports Git, but easy to extend for new types of repositories
- switch to base commit
- use SCM tool to apply patch to temp repositoryFixed bug in make_tempfile
Delete temporary folders
Added cached_property to ReviewBot
- turned File properties into cached properties
- cached path property on Repository_CloneAdded new Tool base class to support access to entire repository
- sending repository path to tool
- comment on a file by its path
- created example ReviewBot tool to look at entire repository
- added more Queues to Celery so that a bot only picks up a task that it has the repository forAdded flag to extension model to signal if ReviewBot tool supports entire directory
- added UI in admin panel to show this
The following configuration was used in reviewbot/config.py
from reviewbot.revisioning.constants import GIT BOT_REPOSITORY_SETTINGS = { 'http://localhost:8080/': { 'ReviewBot': { 'type': GIT, 'url': 'git://github.com/reviewboard/ReviewBot.git', }, }, }
The following tool was added at the path reviewbot/tools/pep8repo.py
import os from reviewbot.tools import RepositoryTool from reviewbot.tools.process import execute from reviewbot.utils import is_exe_in_path class PEP8RepoTool(RepositoryTool): name = 'PEP8 Style Checker - Entire Repository' version = '0.2' description = "Checks code for style errors using the PEP8 tool." def check_dependencies(self): return is_exe_in_path('pep8') def handle_repository(self, repository_working_directory): path = repository_working_directory.path if not path: return False for root, subFolders, files in os.walk(path): for file_path in files: if not file_path.endswith('.py'): continue full_path = os.path.join(root, file_path) output = execute( [ 'pep8', '-r', full_path ], split_lines=True, ignore_errors=True) for line in output: parsed = line.split(':', 3) lnum = int(parsed[1]) col = int(parsed[2]) msg = parsed[3] repository_working_directory.comment( full_path, 'Col: %s\n%s' % (col, msg), lnum) return True
I used a server running on "http://localhost:8080" to test my changes. The setup process is the same as if you were setting up ReviewBot normally. When refreshing the list of tools, PEP8 Style Checker - Entire Repository should show up with a value of true in the 'working directory required' column. To test I set both it and the normal PEP8 Style Checker to run automatically to compare output.
Tests:
1. On the second startup of the bot, it should take less time than the second to start Celery (if you include the reviewboard repository it is more noticeable). This indicates that the repository is being stored between bot sessions as expected. These repositories should stored in a folder system ~/ReviewBotRepositories/server_url/repo_name/.
2. In the celery startup output, it should be shown that one of the Celery Queues the bot is listening on is: pep8repo.0.2.http://localhost:8080/.ReviewBot exchange=pep8repo.0.2.http://localhost:8080/.ReviewBot(direct) key=pep8repo.0.2.http://localhost:8080/.ReviewBot
3. The reviewboard page /admin/extensions/reviewbotext.extension.ReviewBotExtension/db/reviewbotext/reviewbottool/ should show a column called Working directory required. For the tool 'PEP8 Style Checker - Entire Repository' there should be a green check.
5. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a file in /tmp/ that contains the patch to apply to the repository to get the code as it is in the review request.
4. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a folder in /tmp/ that contains the ReviewBot repository without the .git folder. The state of the repository should be identical to that of the review request.
5. After a publishing a review, checking the /tmp/ folder of the bot should show there are no temp files or directories.
6. Both the normal PEP8 and the full repository PEP8 should complete without error. The resulting code comments should be identical. Of particular note, there should be no comments on files not changed in the review request.
Description | From | Last Updated |
---|---|---|
Col: 14 E203 whitespace before ':' |
reviewbot | |
Col: 14 E203 whitespace before ':' |
reviewbot | |
local variable 'repo' is assigned to but never used |
reviewbot | |
Col: 15 E203 whitespace before ':' |
reviewbot | |
Col: 14 E203 whitespace before ':' |
reviewbot | |
Col: 15 E203 whitespace before ':' |
reviewbot | |
Col: 14 E203 whitespace before ':' |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
local variable 'repo' is assigned to but never used |
reviewbot | |
'Repo' imported but unused |
reviewbot | |
'NoSuchPathError' imported but unused |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 80 E501 line too long (99 > 79 characters) |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 52 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 54 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 51 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 53 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 71 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 73 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot | |
Col: 1 W391 blank line at end of file |
reviewbot | |
'ToolRepository' imported but unused |
reviewbot | |
Col: 5 E265 block comment should start with '# ' |
reviewbot | |
Col: 80 E501 line too long (85 > 79 characters) |
reviewbot | |
Col: 50 E261 at least two spaces before inline comment |
reviewbot | |
Col: 50 E262 inline comment should start with '# ' |
reviewbot | |
Col: 5 E265 block comment should start with '# ' |
reviewbot | |
Col: 80 E501 line too long (82 > 79 characters) |
reviewbot | |
'RepositoryManager' imported but unused |
reviewbot | |
local variable 'tool_repository' is assigned to but never used |
reviewbot | |
Col: 22 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 24 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 29 E203 whitespace before ':' |
reviewbot | |
local variable 'tool_repository' is assigned to but never used |
reviewbot | |
You'll want to put a blank line before from reviewboar.revisioning.repository_manager import RepositoryManger. The why we style our imports is as … |
SM smacleod | |
Leave this blank line in, we want 2 blanks here. |
SM smacleod | |
So as I mentioned in the hackpad we want to namespace the configuration down one more level to include the … |
SM smacleod | |
Is there a reason you chose to use abstract base classes for this? If not, I think we should just … |
SM smacleod | |
The docstring should be before any code in the method. |
SM smacleod | |
What is _path here suppose to represent, and why does it just return self.name? What am I missing? |
SM smacleod | |
So a couple of things with this: @classmethod methods should generally use "cls" as the first argument, not "self". What … |
SM smacleod | |
Instead of doing these checks from constants and then using a particular class, we should just create a dictionary mapping … |
SM smacleod | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
In order to intiialize the tool repository we'll need: * The name of the repository * The Review Board server … |
SM smacleod | |
local variable 'tool_repository' is assigned to but never used |
reviewbot | |
Lets call this working_dir_required |
SM smacleod | |
'RepositoryManager' imported but unused |
reviewbot | |
undefined name 'shutil' |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 1 W391 blank line at end of file |
reviewbot | |
local variable 'e' is assigned to but never used |
reviewbot | |
undefined name 'logging' |
reviewbot | |
Col: 25 E128 continuation line under-indented for visual indent |
reviewbot | |
'rdb' imported but unused |
reviewbot | |
Col: 9 E265 block comment should start with '# ' |
reviewbot | |
Col: 80 E501 line too long (85 > 79 characters) |
reviewbot | |
undefined name 'self' |
reviewbot | |
Col: 29 E126 continuation line over-indented for hanging indent |
reviewbot | |
Col: 17 E128 continuation line under-indented for visual indent |
reviewbot | |
undefined name 'path' |
reviewbot | |
undefined name 'payload' |
reviewbot | |
undefined name 'logger' |
reviewbot | |
undefined name 'repository_manager' |
reviewbot | |
undefined name 'payload' |
reviewbot | |
undefined name 'RepositoryClone' |
reviewbot | |
undefined name 'logger' |
reviewbot | |
undefined name 'repository_clone' |
reviewbot | |
Col: 80 E501 line too long (85 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot | |
Col: 21 E128 continuation line under-indented for visual indent |
reviewbot | |
'RepositoryClone' imported but unused |
reviewbot | |
Col: 19 E262 inline comment should start with '# ' |
reviewbot | |
'GIT' imported but unused |
reviewbot | |
Maybe I should include this in the comments rather than in the actual code. I really want whoever writes the … |
MA matthewcmaclean | |
Can you remove the extra space and add a period at the end of the sentence? |
anselina | |
Capitalize the first word + period (for consistency?) |
PE PeterTran | |
s/supoort/support |
anselina | |
s/an/An |
anselina | |
Can you capitalize URL? Here and in all your other comments/docstrings. |
anselina | |
Remove the apostrophe on "name's". |
anselina | |
We generally add full-package imports before single-item imports, so this should go after import tempfile. |
anselina | |
Remove the extra space before and after the sentence, and add a period. |
anselina | |
Can you add a blank line after this? We generally have one blank line before and after if/for/while blocks. |
anselina | |
Can you add a blank line before this, while you're here? |
anselina | |
Add a blank line before this. |
anselina | |
Remove the extra space before the sentence. |
anselina | |
Remove the extra space before and after the sentence. |
anselina | |
Remove the extra space before and after the sentence. Here and in all other docstrings below. |
anselina | |
Remove the extra space before the sentence, and add a period. |
anselina | |
This should come directly after from git.exc import NoSuchPathError (since RBTools would be considered as a third-party library import for … |
anselina | |
This should be: from os import chdir, get cwd from re import sub from django.utils.functional import cached_property from rbtools.commands.patch import … |
anselina | |
We generally use single quotes for strings. (Here and in other places.) |
anselina | |
Can you change this to: logging.warning( 'server: %s, repository %s: type%s is not supported' % (server_url, repo_name, repo_settings['type'])) |
anselina | |
You will need a space after been. Otherwise when the Exception is raised it'll be concatenated like: Respository _ in … |
PE PeterTran | |
Can you make this into a single-line docstring, like """Returns the server URL and names of repositories the bot supports."""? |
anselina | |
s/seperately/separately |
anselina | |
Should this class be uppercase? |
PE PeterTran | |
Can you remove the extra space before the sentence, and add a period? |
anselina | |
Add a blank line after this. |
anselina | |
Since you removed your pep8repo tool used for testing, this line should also be deleted. |
anselina | |
If there are multiple tools with working_directory_required == True, this will initialize the RepositoryManager multiple times. Each queue would be … |
anselina | |
If the patch doesn't apply cleanly or raises an error, we probably shouldn't proceed with the review. execute() has some … |
anselina | |
Can we call this RepositoryWorkingDirectory instead (or something to that effect), and change the docstring to "Represents a working directory … |
anselina | |
Can we put this in a function like initialize_repository_manager(), and just add a call to this in celery.py if a … |
anselina | |
Can you indent this an extra level? |
anselina | |
"static" should be removed since we can now do more than just static analysis with the full working directory. |
anselina | |
Indent this an extra level. |
anselina | |
Actually, sorry, instead of calling initialize_repositories() here, how about we call it in supported_repositories()? |
anselina | |
Globals are usually capitalized, so can you make this be REPOSITORIES? |
anselina | |
Let's set REPOSITORIES = None in line 12, and set REPOSITORIES = {} here. This way, we can just do … |
anselina |
- Description:
-
~ I'm currently exploring GitPython and how I can use it to manipulate the repositories for the different tools.
~ Setting up the bot to handle Git repositories and pass the file paths to the tools.
+ Currently it: + - sets up repository on load + - supports Git, but easy to extend for new types of repositories + - stores repository in root + WIP: + - sending file path to tools - Commit:
-
22b59a38ea81e80902e538afbccc328785d6bc777bdbc0ffd92332411cf46fd716172e776a6b0927
- Diff:
-
Revision 2 (+109 -2)
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
-
-
-
- Change Summary:
-
Fixed style issues
- Commit:
-
7bdbc0ffd92332411cf46fd716172e776a6b092702ce4c150c4a9f699a1ff37c5238cd9bdb6b7f68
- Diff:
-
Revision 3 (+117 -2)
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
- Description:
-
Setting up the bot to handle Git repositories and pass the file paths to the tools.
Currently it: - sets up repository on load - supports Git, but easy to extend for new types of repositories - stores repository in root WIP: + - determining information about base commit - sending file path to tools - Commit:
-
02ce4c150c4a9f699a1ff37c5238cd9bdb6b7f68f0c674149db9280c5b9aeaececae91a4d2dba557
- Diff:
-
Revision 4 (+120 -1)
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
-
-
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
-
- Change Summary:
-
Fixing reviewbot issues
- Commit:
-
f0c674149db9280c5b9aeaececae91a4d2dba557132a80bd76bbdffbffd4ded6945031a21e86d0d3
- Diff:
-
Revision 5 (+117 -1)
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files:
-
- Change Summary:
-
Added base repository commit and repository name to payload
- Description:
-
Setting up the bot to handle Git repositories and pass the file paths to the tools.
Currently it: - sets up repository on load - supports Git, but easy to extend for new types of repositories - stores repository in root - WIP: - determining information about base commit + WIP: - sending file path to tools - Commit:
-
132a80bd76bbdffbffd4ded6945031a21e86d0d381d2d97c1ff079334f453f98d2233d46d5162a92
-
Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files: bot/reviewbot/revisioning/.repository_manager.py.swp extension/reviewbotext/.handlers.py.swp bot/reviewbot/.config.py.swp Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py Ignored Files: bot/reviewbot/revisioning/.repository_manager.py.swp extension/reviewbotext/.handlers.py.swp bot/reviewbot/.config.py.swp
-
-
-
I think we're moving in the right directions here. I've done a quick pass and noted some of the style issues I caught, as well as some of the bigger conventional, architectural, or preferential issues.
Also, it looks like a bunch of binary swap files snuck into your diff. Please remove these from your commits in future revisions.
-
You'll want to put a blank line before
from reviewboar.revisioning.repository_manager import RepositoryManger
.The why we style our imports is as follows:
<Python Standard Library Imports>
<Blank Line>
<Third Party Library Imports>
<Blank Line>
<Package Imports>Where third party library imports are things from outside the project (anything not from "reviewbot")
-
-
So as I mentioned in the hackpad we want to namespace the configuration down one more level to include the Review Board server url.
So in this case we'd have:
repo_settings = {
"http://localhost:8080/": {
"RBTools": {
"type": GIT,
"url": "git://github.com/reviewboard/rbtools.git",
},
"Review Board": {
"type": GIT,
"url": "git://github.com/reviewboard/reviewboard.git",
},
},
} -
Is there a reason you chose to use abstract base classes for this?
If not, I think we should just use the normal inheritance. Just defining a set of methods in the base class which make up the interace and then defining them in each class should be fine.
-
-
-
So a couple of things with this:
@classmethod
methods should generally use "cls" as the first argument, not "self". What is actually passed will be the class not an object so this makes that clearer.Using this sort of singleton class as an object is less testable than just actually using an object or sets of functions - and we usually don't do it this way around the rest of the code. (I know, Review Bot doesn't have test... but I hope it does one day).
-
Instead of doing these checks from constants and then using a particular class, we should just create a dictionary mapping repositories type string to the classes. That will allow a quick lookup and instantiation of the proper class.
All of these repo types should inherit from the same class and have the same interface going forward. So while there is only git right now, keep that in mind.
-
In order to intiialize the tool repository we'll need: * The name of the repository * The Review Board server URL,
I think we should keep the commit information out of it at the initialization step, and move that into a method you call on the ToolRepository object - "getWorkingdirectoryForCommit()" or something.
-
- Groups:
- Change Summary:
-
Create temporary folder with base commit folder.
- Description:
-
Setting up the bot to handle Git repositories and pass the file paths to the tools.
~ Currently it: ~ Currently in: - sets up repository on load - supports Git, but easy to extend for new types of repositories - stores repository in root - determining information about base commit + - switch to base commit WIP: ~ - sending file path to tools ~ - sending file path to tools + - might not be deleting temporary directory - Commit:
-
81d2d97c1ff079334f453f98d2233d46d5162a92a09494d997de85ce230169cf3e18e8fb5e007943
-
Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/reviewbot/processing/filesystem.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py
-
-
-
-
Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/base_repository.py bot/reviewbot/processing/filesystem.py bot/setup.py bot/reviewbot/revisioning/tool_repository.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py
-
-
-
-
- Description:
-
Setting up the bot to handle Git repositories and pass the file paths to the tools.
Currently in: - sets up repository on load - supports Git, but easy to extend for new types of repositories - stores repository in root - determining information about base commit - switch to base commit + - cached path property + - fixed bug in make_tempfile + - delete temporary folders + - update local repository programatically WIP: - sending file path to tools ~ - might not be deleting temporary directory ~ - use SCM tool to apply patch to repository - Commit:
-
a09494d997de85ce230169cf3e18e8fb5e007943f0e81766a7717b6d90b51739d27ea39d737f56e2
- Diff:
-
Revision 8 (+282 -25)
-
Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/revisioning/constants.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
-
-
-
-
-
- Change Summary:
-
Finished adding the ability to apply a patch to a directory and have moved where the RepositoryClone object is accessible from.
- Description:
-
Setting up the bot to handle Git repositories and pass the file paths to the tools.
Currently in: - sets up repository on load - supports Git, but easy to extend for new types of repositories - stores repository in root - determining information about base commit - switch to base commit - cached path property - fixed bug in make_tempfile - delete temporary folders - update local repository programatically - WIP: - sending file path to tools ~ - use SCM tool to apply patch to repository ~ - use SCM tool to apply patch to repository + WIP: + - comment on a file from its path - Branch:
-
master
- Commit:
-
f0e81766a7717b6d90b51739d27ea39d737f56e27d94a4ab845d32d27d8457760ccb323587545da1
- Diff:
-
Revision 9 (+353 -61)
-
Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
-
-
-
-
Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
-
-
-
-
-
-
-
-
- Description:
-
~ Setting up the bot to handle Git repositories and pass the file paths to the tools.
~ Currently in: ~ - sets up repository on load ~ - supports Git, but easy to extend for new types of repositories ~ - stores repository in root ~ - determining information about base commit ~ - switch to base commit ~ - cached path property ~ - fixed bug in make_tempfile ~ - delete temporary folders ~ - update local repository programatically ~ - sending file path to tools ~ - use SCM tool to apply patch to repository ~ WIP: ~ - comment on a file from its path ~ Setting up the bot to handle Git repositories and pass the repository paths to the tools.
~ ~ Currently in:
~ ~ Sets up repository on ReviewBot load
~ - stores repositories in root folder ~ - updates repositories programatically ~ ~ Supports Git, but easy to extend for new types of repositories
~ - switch to base commit ~ - use SCM tool to apply patch to temp repository ~ ~ Fixed bug in make_tempfile
~ ~ Delete temporary folders
+ + Added cached_property to ReviewBot
+ - turned File properties into cached properties + - cached path property on Repository_Clone + + Added new Tool base class to support access to entire repository
+ - sending repository path to tool + - comment on a file by its path + - created example ReviewBot tool to look at entire repository + + Added flag to extension model to signal if ReviewBot tool supports entire directory
+ - added UI in admin panel to show this + + WIP:
- Branch:
-
masterrelease-0.2.x
- Commit:
-
7d94a4ab845d32d27d8457760ccb323587545da100a5b44457d0e0915600c29426ebb8db34b85338
-
Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
- Change Summary:
-
Re-added GitPython into setup.py. It must have gotten lost in a rebase.
- Commit:
-
00a5b44457d0e0915600c29426ebb8db34b85338cec345787c84793583f8056344c65cea760a4990
-
Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
- Change Summary:
-
Added all the tests I check. I also added more queues to Celery so that a bot only takes on tasks for repositories it can handle.
- Summary:
-
[WIP] Added support to reviewbot to pull git repositories.Setting up the bot to handle Git repositories and pass the repository paths to the tools
- Description:
-
- Setting up the bot to handle Git repositories and pass the repository paths to the tools.
- - Currently in:
- Sets up repository on ReviewBot load
- stores repositories in root folder - updates repositories programatically Supports Git, but easy to extend for new types of repositories
- switch to base commit - use SCM tool to apply patch to temp repository Fixed bug in make_tempfile
Delete temporary folders
Added cached_property to ReviewBot
- turned File properties into cached properties - cached path property on Repository_Clone Added new Tool base class to support access to entire repository
- sending repository path to tool - comment on a file by its path ~ - created example ReviewBot tool to look at entire repository ~ - created example ReviewBot tool to look at entire repository + - added more Queues to Celery so that a bot only picks up a task that it has the repository for Added flag to extension model to signal if ReviewBot tool supports entire directory
- added UI in admin panel to show this - - WIP:
- Testing Done:
-
+ The following configuration was used in reviewbot/config.py
+ + bot_repository_settings = {
+ "http://localhost:8080/": {
+ "ReviewBot": {
+ "type": GIT,
+ "url": "git://github.com/reviewboard/ReviewBot.git",
+ },
+ }
+ + + + + The following tool was added at the path reviewbot/tools/pep8repo.py
+ + import os
+ + from reviewbot.tools import RepositoryTool
+ from reviewbot.tools.process import execute
+ from reviewbot.utils import is_exe_in_path
+ + + class PEP8ToolRepo(RepositoryTool):
+ name = 'PEP8 Style Checker - Entire Repository'
+ version = '0.2'
+ description = "Checks code for style errors using the PEP8 tool."
+ + def check_dependencies(self):
+ return is_exe_in_path('pep8')
+ + def handle_repository(self, repository_clone):
+ path = repository_clone.path
+ if not path:
+ return False
+ + for root, subFolders, files in os.walk(path):
+ for file_path in files:
+ if not file_path.endswith('.py'):
+ continue
+ + full_path = os.path.join(root, file_path)
+ + output = execute(
+ [
+ 'pep8',
+ '-r',
+ full_path
+ ],
+ split_lines=True,
+ ignore_errors=True)
+ + for line in output:
+ parsed = line.split(':', 3)
+ lnum = int(parsed[1])
+ col = int(parsed[2])
+ msg = parsed[3]
+ repository_clone.comment(
+ full_path,
+ 'Col: %s\n%s' % (col, msg),
+ lnum)
+ + return True
+ + + + + I used a server running on "http://localhost:8080" to test my changes. The setup process is the same as if you were setting up ReviewBot normally. When refreshing the list of tools, PEP8 Style Checker - Entire Repository should show up with a value of true in the 'working directory required' column. To test I set both it and the normal PEP8 Style Checker to run automatically to compare output.
+ + Tests:
+ 1. On the second startup of the bot, it should take less time than the second to start Celery (if you include the reviewboard repository it is more noticeable). This indicates that the repository is being stored between bot sessions as expected. These repositories should stored in a folder system ~/ReviewBotRepositories/server_url/repo_name/. + 2. In the celery startup output, it should be shown that one of the Celery Queues the bot is listening on is: pep8repo.0.2.http://localhost:8080/.ReviewBot exchange=pep8repo.0.2.http://localhost:8080/.ReviewBot(direct) key=pep8repo.0.2.http://localhost:8080/.ReviewBot + 3. The reviewboard page /admin/extensions/reviewbotext.extension.ReviewBotExtension/db/reviewbotext/reviewbottool/ should show a column called Working directory required. For the tool 'PEP8 Style Checker - Entire Repository' there should be a green check. + 5. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a file in /tmp/ that contains the patch to apply to the repository to get the code as it is in the review request. + 4. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a folder in /tmp/ that contains the ReviewBot repository without the .git folder. The state of the repository should be identical to that of the review request. + 5. After a publishing a review, checking the /tmp/ folder of the bot should show there are no temp files or directories. + 6. Both the normal PEP8 and the full repository PEP8 should complete without error. The resulting code comments should be identical. Of particular note, there should be no comments on files not changed in the review request. - Commit:
-
6de54d8f333cc52675a6b203ae8f71c44e0eade0c5d7445ff571ca0f3ab46e143a67088d0adc28f7
-
Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
- Change Summary:
-
Fixed bracket issues in the config.py and moved the import into the comments as it isn't actually used.
- Commit:
-
c5d7445ff571ca0f3ab46e143a67088d0adc28f77df8bde15e6f6d74bc636b47dd4a31239591ed39
-
Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
Thanks for the detailed description! This is mostly a style review since I haven't been following your project closely. I'll try to follow up with another review of the logic though, after I read your Hackpad.
-
-
-
-
-
-
We generally add full-package imports before single-item imports, so this should go after
import tempfile
. -
-
Can you add a blank line after this? We generally have one blank line before and after if/for/while blocks.
-
-
-
-
-
-
-
This should come directly after
from git.exc import NoSuchPathError
(since RBTools would be considered as a third-party library import for Review Bot). -
This should be:
from os import chdir, get cwd from re import sub from django.utils.functional import cached_property from rbtools.commands.patch import Patch from reviewbot.processing.filesystem import make_tempfile
-
-
Can you change this to:
logging.warning( 'server: %s, repository %s: type%s is not supported' % (server_url, repo_name, repo_settings['type']))
-
Can you make this into a single-line docstring, like """Returns the server URL and names of repositories the bot supports."""?
-
-
-
-
- Testing Done:
-
The following configuration was used in reviewbot/config.py
bot_repository_settings = {
~ "http://localhost:8080/": {
~ "ReviewBot": {
~ "type": GIT,
~ "url": "git://github.com/reviewboard/ReviewBot.git",
~ 'http://localhost:8080/': {
~ 'ReviewBot': {
~ 'type': GIT,
~ 'url': 'git://github.com/reviewboard/ReviewBot.git',
},
~ }
~ },
+ }
The following tool was added at the path reviewbot/tools/pep8repo.py
import os
from reviewbot.tools import RepositoryTool
from reviewbot.tools.process import execute
from reviewbot.utils import is_exe_in_path
~ class PEP8ToolRepo(RepositoryTool):
~ class PEP8RepoTool(RepositoryTool):
name = 'PEP8 Style Checker - Entire Repository'
version = '0.2'
description = "Checks code for style errors using the PEP8 tool."
def check_dependencies(self):
return is_exe_in_path('pep8')
def handle_repository(self, repository_clone):
path = repository_clone.path
if not path:
return False
for root, subFolders, files in os.walk(path):
for file_path in files:
if not file_path.endswith('.py'):
continue
full_path = os.path.join(root, file_path)
output = execute(
[
'pep8',
'-r',
full_path
],
split_lines=True,
ignore_errors=True)
for line in output:
parsed = line.split(':', 3)
lnum = int(parsed[1])
col = int(parsed[2])
msg = parsed[3]
repository_clone.comment(
full_path,
'Col: %s\n%s' % (col, msg),
lnum)
return True
I used a server running on "http://localhost:8080" to test my changes. The setup process is the same as if you were setting up ReviewBot normally. When refreshing the list of tools, PEP8 Style Checker - Entire Repository should show up with a value of true in the 'working directory required' column. To test I set both it and the normal PEP8 Style Checker to run automatically to compare output.
Tests:
1. On the second startup of the bot, it should take less time than the second to start Celery (if you include the reviewboard repository it is more noticeable). This indicates that the repository is being stored between bot sessions as expected. These repositories should stored in a folder system ~/ReviewBotRepositories/server_url/repo_name/. 2. In the celery startup output, it should be shown that one of the Celery Queues the bot is listening on is: pep8repo.0.2.http://localhost:8080/.ReviewBot exchange=pep8repo.0.2.http://localhost:8080/.ReviewBot(direct) key=pep8repo.0.2.http://localhost:8080/.ReviewBot 3. The reviewboard page /admin/extensions/reviewbotext.extension.ReviewBotExtension/db/reviewbotext/reviewbottool/ should show a column called Working directory required. For the tool 'PEP8 Style Checker - Entire Repository' there should be a green check. 5. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a file in /tmp/ that contains the patch to apply to the repository to get the code as it is in the review request. 4. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a folder in /tmp/ that contains the ReviewBot repository without the .git folder. The state of the repository should be identical to that of the review request. 5. After a publishing a review, checking the /tmp/ folder of the bot should show there are no temp files or directories. 6. Both the normal PEP8 and the full repository PEP8 should complete without error. The resulting code comments should be identical. Of particular note, there should be no comments on files not changed in the review request. - Commit:
-
7df8bde15e6f6d74bc636b47dd4a31239591ed39477c77eab9a705bdf5982ccf66ff0d680044cacc
-
Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/tools/pep8repo.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
- Change Summary:
-
Removed pep8repo.py which I by mistake added back in.
- Commit:
-
477c77eab9a705bdf5982ccf66ff0d680044caccc246791217e90f8078d1139de7d74cea732a04b9
-
Tool: Pyflakes Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
Tool: PEP8 Style Checker Processed Files: bot/setup.py bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/reviewbot/revisioning/repository_clone.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
This looks great! You may not have time for this, but I think it'd be good to also grab the branch information off the review request, and actually checkout that branch before switching to the base commit and applying the patch.
-
If there are multiple tools with working_directory_required == True, this will initialize the RepositoryManager multiple times. Each queue would be added several times extra too.
Also, I'm just curious if there is a reason for having separate queues for each repository (instead of a single pep8repo tool queue, for example)?
-
If the patch doesn't apply cleanly or raises an error, we probably shouldn't proceed with the review. execute() has some parameters dealing with errors.
-
Can we call this RepositoryWorkingDirectory instead (or something to that effect), and change the docstring to "Represents a working directory of a specified repository."? It's easy to mistake this to be an actual clone of the repo.
-
Can we put this in a function like initialize_repository_manager(), and just add a call to this in celery.py if a working directory is required for one of the tools? This will make it more testable for the future.
-
-
"static" should be removed since we can now do more than just static analysis with the full working directory.
-
- Change Summary:
-
Updated code as per the review. Not all the issues have been resolved as I have further questions on the implementation.
- Testing Done:
-
The following configuration was used in reviewbot/config.py
~ bot_repository_settings = {
~ from reviewbot.revisioning import GIT
+ + + bot_repository_settings = {
'http://localhost:8080/': {
'ReviewBot': {
'type': GIT,
'url': 'git://github.com/reviewboard/ReviewBot.git',
},
},
}
The following tool was added at the path reviewbot/tools/pep8repo.py
import os
from reviewbot.tools import RepositoryTool
from reviewbot.tools.process import execute
from reviewbot.utils import is_exe_in_path
class PEP8RepoTool(RepositoryTool):
name = 'PEP8 Style Checker - Entire Repository'
version = '0.2'
description = "Checks code for style errors using the PEP8 tool."
def check_dependencies(self):
return is_exe_in_path('pep8')
~ def handle_repository(self, repository_clone):
~ path = repository_clone.path
~ def handle_repository(self, repository_working_directory):
~ path = repository_working_directory.path
if not path:
return False
for root, subFolders, files in os.walk(path):
for file_path in files:
if not file_path.endswith('.py'):
continue
full_path = os.path.join(root, file_path)
output = execute(
[
'pep8',
'-r',
full_path
],
split_lines=True,
ignore_errors=True)
for line in output:
parsed = line.split(':', 3)
lnum = int(parsed[1])
col = int(parsed[2])
msg = parsed[3]
~ repository_clone.comment(
~ repository_working_directory.comment(
full_path,
'Col: %s\n%s' % (col, msg),
lnum)
return True
I used a server running on "http://localhost:8080" to test my changes. The setup process is the same as if you were setting up ReviewBot normally. When refreshing the list of tools, PEP8 Style Checker - Entire Repository should show up with a value of true in the 'working directory required' column. To test I set both it and the normal PEP8 Style Checker to run automatically to compare output.
Tests:
1. On the second startup of the bot, it should take less time than the second to start Celery (if you include the reviewboard repository it is more noticeable). This indicates that the repository is being stored between bot sessions as expected. These repositories should stored in a folder system ~/ReviewBotRepositories/server_url/repo_name/. 2. In the celery startup output, it should be shown that one of the Celery Queues the bot is listening on is: pep8repo.0.2.http://localhost:8080/.ReviewBot exchange=pep8repo.0.2.http://localhost:8080/.ReviewBot(direct) key=pep8repo.0.2.http://localhost:8080/.ReviewBot 3. The reviewboard page /admin/extensions/reviewbotext.extension.ReviewBotExtension/db/reviewbotext/reviewbottool/ should show a column called Working directory required. For the tool 'PEP8 Style Checker - Entire Repository' there should be a green check. 5. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a file in /tmp/ that contains the patch to apply to the repository to get the code as it is in the review request. 4. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a folder in /tmp/ that contains the ReviewBot repository without the .git folder. The state of the repository should be identical to that of the review request. 5. After a publishing a review, checking the /tmp/ folder of the bot should show there are no temp files or directories. 6. Both the normal PEP8 and the full repository PEP8 should complete without error. The resulting code comments should be identical. Of particular note, there should be no comments on files not changed in the review request. - Commit:
-
c246791217e90f8078d1139de7d74cea732a04b98a19bad9df86e4b5bb32316a0c9c4ed2e14a3153
-
Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_working_dir.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/setup.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/repository_working_dir.py bot/reviewbot/revisioning/repository_manager.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/setup.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
-
Actually, sorry, instead of calling initialize_repositories() here, how about we call it in supported_repositories()?
-
-
Let's set
REPOSITORIES = None
in line 12, and setREPOSITORIES = {}
here.This way, we can just do
if REPOSITORIES is None
to check if the RepositoryClients have been instantiated/initialized, so we don't need theinitialized
boolean anymore.Let's actually also move this logic to supported_repositories(), so it'll look like:
def supported_repositories(): global REPOSITORIES if REPOSITORIES is None: initialize_repositories() return REPOSITORIES.keys()
- Testing Done:
-
The following configuration was used in reviewbot/config.py
~ from reviewbot.revisioning import GIT
~ from reviewbot.revisioning.constants import GIT
~ bot_repository_settings = {
~ BOT_REPOSITORY_SETTINGS = {
'http://localhost:8080/': {
'ReviewBot': {
'type': GIT,
'url': 'git://github.com/reviewboard/ReviewBot.git',
},
},
}
The following tool was added at the path reviewbot/tools/pep8repo.py
import os
from reviewbot.tools import RepositoryTool
from reviewbot.tools.process import execute
from reviewbot.utils import is_exe_in_path
class PEP8RepoTool(RepositoryTool):
name = 'PEP8 Style Checker - Entire Repository'
version = '0.2'
description = "Checks code for style errors using the PEP8 tool."
def check_dependencies(self):
return is_exe_in_path('pep8')
def handle_repository(self, repository_working_directory):
path = repository_working_directory.path
if not path:
return False
for root, subFolders, files in os.walk(path):
for file_path in files:
if not file_path.endswith('.py'):
continue
full_path = os.path.join(root, file_path)
output = execute(
[
'pep8',
'-r',
full_path
],
split_lines=True,
ignore_errors=True)
for line in output:
parsed = line.split(':', 3)
lnum = int(parsed[1])
col = int(parsed[2])
msg = parsed[3]
repository_working_directory.comment(
full_path,
'Col: %s\n%s' % (col, msg),
lnum)
return True
I used a server running on "http://localhost:8080" to test my changes. The setup process is the same as if you were setting up ReviewBot normally. When refreshing the list of tools, PEP8 Style Checker - Entire Repository should show up with a value of true in the 'working directory required' column. To test I set both it and the normal PEP8 Style Checker to run automatically to compare output.
Tests:
1. On the second startup of the bot, it should take less time than the second to start Celery (if you include the reviewboard repository it is more noticeable). This indicates that the repository is being stored between bot sessions as expected. These repositories should stored in a folder system ~/ReviewBotRepositories/server_url/repo_name/. 2. In the celery startup output, it should be shown that one of the Celery Queues the bot is listening on is: pep8repo.0.2.http://localhost:8080/.ReviewBot exchange=pep8repo.0.2.http://localhost:8080/.ReviewBot(direct) key=pep8repo.0.2.http://localhost:8080/.ReviewBot 3. The reviewboard page /admin/extensions/reviewbotext.extension.ReviewBotExtension/db/reviewbotext/reviewbottool/ should show a column called Working directory required. For the tool 'PEP8 Style Checker - Entire Repository' there should be a green check. 5. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a file in /tmp/ that contains the patch to apply to the repository to get the code as it is in the review request. 4. In the middle of a review being made (celery.contrib.rdb.set_trace() was used to pause in the middle), there should be a folder in /tmp/ that contains the ReviewBot repository without the .git folder. The state of the repository should be identical to that of the review request. 5. After a publishing a review, checking the /tmp/ folder of the bot should show there are no temp files or directories. 6. Both the normal PEP8 and the full repository PEP8 should complete without error. The resulting code comments should be identical. Of particular note, there should be no comments on files not changed in the review request. - Commit:
-
8a19bad9df86e4b5bb32316a0c9c4ed2e14a3153d8503aa8a33025000bfcc70b6acd3deb48eaca66
-
Tool: PEP8 Style Checker Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/constants.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/setup.py bot/reviewbot/revisioning/repository_working_dir.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py
-
Tool: Pyflakes Processed Files: bot/reviewbot/tasks.py bot/reviewbot/revisioning/git_repository_client.py bot/reviewbot/tools/__init__.py bot/reviewbot/revisioning/constants.py bot/reviewbot/processing/filesystem.py extension/reviewbotext/admin.py bot/setup.py bot/reviewbot/revisioning/repository_working_dir.py bot/reviewbot/celery.py extension/reviewbotext/handlers.py extension/reviewbotext/resources.py extension/reviewbotext/extension.py bot/reviewbot/utils.py extension/reviewbotext/models.py bot/reviewbot/revisioning/__init__.py bot/reviewbot/processing/review.py bot/reviewbot/config.py bot/reviewbot/revisioning/repository_client.py