├── tests ├── __init__.py ├── feito │ ├── __init__.py │ ├── fixtures │ │ ├── __init__.py │ │ └── analyze_file.py │ ├── github │ │ ├── __init__.py │ │ └── test_api.py │ ├── test_filters.py │ ├── test_repository.py │ ├── test_prospector.py │ ├── test_messages.py │ └── support │ │ └── prospector_analysis_stub_return.py └── test_feito.py ├── requirements.txt ├── feito ├── github │ ├── __init__.py │ └── api.py ├── filters.py ├── prospector.py ├── repository.py ├── messages.py └── __init__.py ├── setup.cfg ├── requirements ├── package.txt └── development.txt ├── bin └── feito ├── pytest.ini ├── DEVELOPEMENT.md ├── LICENSE ├── setup.py ├── .circleci └── config.yml ├── .gitignore └── README.md /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/feito/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/feito/fixtures/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/feito/github/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | -r requirements/package.txt 2 | -------------------------------------------------------------------------------- /feito/github/__init__.py: -------------------------------------------------------------------------------- 1 | from .api import API 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /requirements/package.txt: -------------------------------------------------------------------------------- 1 | prospector==0.12.7 2 | requests==2.18.4 3 | -------------------------------------------------------------------------------- /bin/feito: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import feito 4 | feito.run() 5 | -------------------------------------------------------------------------------- /tests/feito/fixtures/analyze_file.py: -------------------------------------------------------------------------------- 1 | def hi(): 2 | return "bla bla" 3 | -------------------------------------------------------------------------------- /requirements/development.txt: -------------------------------------------------------------------------------- 1 | feito==0.0.4 2 | pytest-env==0.6.2 3 | pytest==3.4.0 4 | requests-mock==1.4.0 5 | twine==1.9.1 6 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | env = 3 | PULL_REQUEST_ID=1 4 | REPOSITORY_USERNAME=daniel 5 | OAUTH_TOKEN=incdsc98er 6 | COMMIT_ID=475348957349843957 7 | REPOSITORY_NAME=test 8 | -------------------------------------------------------------------------------- /feito/filters.py: -------------------------------------------------------------------------------- 1 | class Filters: 2 | 3 | @staticmethod 4 | def filter_python_files(files): 5 | """ 6 | param files: list of strings -> File names 7 | 8 | For a list of file name strings. it returns 9 | only those that are a Python file 10 | """ 11 | return list(filter(lambda file: file[-2:] == 'py', files)) 12 | -------------------------------------------------------------------------------- /tests/feito/test_filters.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | 3 | from feito.filters import Filters 4 | 5 | 6 | class FiltersTestCase(TestCase): 7 | 8 | def test_filter_python_files(self): 9 | files = ['test.py', 'test/another-test.py', 'not-python.rb', '.also-not-python'] 10 | filtered_files = Filters.filter_python_files(files) 11 | 12 | assert filtered_files == ['test.py', 'test/another-test.py'] 13 | -------------------------------------------------------------------------------- /feito/prospector.py: -------------------------------------------------------------------------------- 1 | import json 2 | import subprocess 3 | 4 | 5 | class Prospector: 6 | 7 | def __init__(self, repo): 8 | self.repo = repo 9 | 10 | def run(self): 11 | """ 12 | Runs prospector in the input files and returns a json with the analysis 13 | """ 14 | arg_prospector = f'prospector --output-format json {self.repo.diff_files()}' 15 | analysis = subprocess.run(arg_prospector, stdout=subprocess.PIPE, shell=True) 16 | return json.loads(analysis.stdout) 17 | -------------------------------------------------------------------------------- /DEVELOPEMENT.md: -------------------------------------------------------------------------------- 1 | # Development Guide 2 | 3 | ## Dependencies 4 | 5 | Install development dependencies: 6 | 7 | ```bash 8 | pip install -r requirements/development.txt 9 | ``` 10 | 11 | ## Tests 12 | 13 | ```sh 14 | pytest 15 | ``` 16 | 17 | ## Releases 18 | 19 | ### PyPI 20 | 21 | Add your credentials from PyPI to `~/.pypirc`: 22 | 23 | ``` 24 | [pypi] 25 | username: 26 | password: 27 | ``` 28 | 29 | To release a new version to PyPI: 30 | 31 | ```sh 32 | python setup.py sdist 33 | twine upload dist/* 34 | ``` 35 | -------------------------------------------------------------------------------- /tests/feito/test_repository.py: -------------------------------------------------------------------------------- 1 | import os 2 | from unittest import TestCase 3 | 4 | from feito import Repository 5 | 6 | 7 | class RepositoryTestCase(TestCase): 8 | 9 | def setUp(self): 10 | self.repo = Repository(os.getenv('REPOSITORY_NAME')) 11 | 12 | def test_repo_name(self): 13 | repo_name = self.repo.repo_name 14 | 15 | assert repo_name == os.getenv('REPOSITORY_NAME') 16 | 17 | def test_last_commit_id(self): 18 | commit_id = self.repo.last_commit_id 19 | 20 | assert commit_id == os.getenv('COMMIT_ID') 21 | -------------------------------------------------------------------------------- /feito/repository.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | from feito.filters import Filters 5 | 6 | 7 | class Repository: 8 | 9 | GIT_DIFF_COMMAND = 'git diff --name-only --diff-filter=ACMR master' 10 | 11 | def __init__(self, repo): 12 | self.repo_name = repo 13 | self.last_commit_id = os.getenv('COMMIT_ID') 14 | 15 | def diff_files(self): 16 | diff_files = subprocess.run(self.GIT_DIFF_COMMAND, stdout=subprocess.PIPE, shell=True) 17 | diff_list = diff_files.stdout.decode().split('\n')[:-1] 18 | 19 | filtered_python_files = Filters.filter_python_files(diff_list) 20 | 21 | return " ".join(filtered_python_files) 22 | -------------------------------------------------------------------------------- /tests/feito/test_prospector.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | from unittest import mock 3 | 4 | from feito import Prospector 5 | 6 | 7 | class ProspectorTestCase(TestCase): 8 | 9 | @mock.patch('feito.prospector.Prospector') 10 | def test_run(self, repo_mock): 11 | repo_mock.repo.diff_files.return_value = 'tests/feito/fixtures/analyze_file.py' 12 | 13 | pros = Prospector(repo_mock.repo) 14 | analysis = pros.run() 15 | 16 | stub_analysis = { 17 | 'source': 'pep8', 18 | 'code': 'E113', 19 | 'location': { 20 | 'path': 'tests/feito/fixtures/analyze_file.py', 21 | 'module': None, 22 | 'function': None, 23 | 'line': 1, 'character': 5 24 | }, 25 | 'message': 'unexpected indentation' 26 | } 27 | 28 | assert stub_analysis in analysis['messages'] 29 | -------------------------------------------------------------------------------- /feito/messages.py: -------------------------------------------------------------------------------- 1 | class Messages: 2 | 3 | def __init__(self, analysis): 4 | """ 5 | params analysis: list of dictionaries -> List contating dictionaries with the 6 | prospector analysis. 7 | """ 8 | self.analysis = analysis 9 | 10 | def commit_format(self): 11 | """ 12 | Formats the analysis into a simpler dictionary with the line, file and message values to 13 | be commented on a commit. 14 | Returns a list of dictionaries 15 | """ 16 | formatted_analyses = [] 17 | for analyze in self.analysis['messages']: 18 | formatted_analyses.append({ 19 | 'message': f"{analyze['source']}: {analyze['message']}. Code: {analyze['code']}", 20 | 'file': analyze['location']['path'], 21 | 'line': analyze['location']['line'], 22 | }) 23 | 24 | return formatted_analyses 25 | -------------------------------------------------------------------------------- /feito/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from feito.github import API 4 | from feito.prospector import Prospector 5 | from feito.messages import Messages 6 | from feito.repository import Repository 7 | 8 | 9 | PULL_REQUEST_ID = os.getenv('PULL_REQUEST_ID') 10 | REPOSITORY_USERNAME = os.getenv('REPOSITORY_USERNAME') 11 | OAUTH_TOKEN = os.getenv('OAUTH_TOKEN') 12 | REPOSITORY_NAME = os.getenv('REPOSITORY_NAME') 13 | 14 | 15 | def run(): 16 | repository = Repository(REPOSITORY_NAME) 17 | analysis = Prospector(repository).run() 18 | messages = Messages(analysis).commit_format() 19 | for message in messages: 20 | api = API(REPOSITORY_USERNAME, repository.repo_name, token=OAUTH_TOKEN) 21 | api.create_comment_commit( 22 | body=message['message'], 23 | commit_id=repository.last_commit_id, 24 | path=message['file'], 25 | position=message['line'], 26 | pr_id=PULL_REQUEST_ID, 27 | ) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Magrathea Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/feito/github/test_api.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import requests_mock 4 | 5 | from feito.github import API 6 | 7 | 8 | class APITestCase(unittest.TestCase): 9 | GITHUB_API_URL = 'https://api.github.com' 10 | 11 | @requests_mock.Mocker() 12 | def test_create_comment_commit(self, mock): 13 | user = 'spencerWilliams' 14 | repo = 'basin-street-blues' 15 | token = 'knfw784t9jg573h' 16 | mock.post( 17 | f"{self.GITHUB_API_URL}/repos/{user}/{repo}/pulls/1/comments", 18 | request_headers={'authorization': f'token {token}'} 19 | ) 20 | 21 | api = API(user, repo, token) 22 | api.create_comment_commit( 23 | body='That sax is gold', 24 | commit_id='bb6a298654dd59dd6e4feb087d13b81778e6e565', 25 | path='file_actions.py', 26 | position=1, 27 | pr_id=1 28 | ) 29 | 30 | assert mock.called == True 31 | assert mock.last_request.json() == { 32 | 'body': 'That sax is gold', 33 | 'commit_id': 'bb6a298654dd59dd6e4feb087d13b81778e6e565', 34 | 'path': 'file_actions.py', 35 | 'position': 1 36 | } 37 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | requires = [ 4 | 'requests==2.18.4', 5 | 'prospector==0.12.7' 6 | ] 7 | 8 | setup( 9 | name='feito', 10 | version='0.0.5', 11 | description='Automated code review in Python', 12 | url='http://github.com/magrathealabs/feito', 13 | author='Magrathea Labs', 14 | author_email='contact@magrathealabs.com', 15 | license='MIT', 16 | packages=['feito', 'feito/github'], 17 | zip_safe=False, 18 | keywords = ['code review', 'good code', 'linter', 'coverage', 'pronto for python'], 19 | scripts=['bin/feito'], 20 | install_requires=requires, 21 | classifiers = [ 22 | 'Development Status :: 3 - Alpha', 23 | 'Intended Audience :: Developers', 24 | 'Intended Audience :: Information Technology', 25 | 'License :: OSI Approved :: MIT License', 26 | 'Operating System :: OS Independent', 27 | 'Programming Language :: Python :: 3 :: Only', 28 | 'Topic :: Software Development :: Libraries :: Python Modules', 29 | 'Topic :: Software Development :: Quality Assurance', 30 | 'Topic :: Software Development :: Testing', 31 | 'Topic :: Utilities', 32 | ] 33 | ) 34 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/python:3.6.1 6 | 7 | working_directory: ~/feito 8 | 9 | steps: 10 | - checkout 11 | - restore_cache: 12 | keys: 13 | - v1-dependencies-{{ checksum "requirements.txt" }} 14 | - v1-dependencies- 15 | 16 | - run: 17 | name: Install dependencies 18 | command: | 19 | python3 -m venv venv 20 | . venv/bin/activate 21 | pip install -r requirements.txt 22 | 23 | - save_cache: 24 | paths: 25 | - ./venv 26 | key: v1-dependencies-{{ checksum "requirements.txt" }} 27 | - run: 28 | name: Run tests 29 | command: | 30 | . venv/bin/activate 31 | pytest 32 | - run: 33 | name: Run Feito 34 | command: | 35 | . venv/bin/activate 36 | export PULL_REQUEST_ID=`echo $CIRCLE_PULL_REQUEST | grep -o -E '[0-9]+'` 37 | export REPOSITORY_NAME=${CIRCLE_PROJECT_REPONAME} 38 | export REPOSITORY_USERNAME=${CIRCLE_PROJECT_USERNAME} 39 | export COMMIT_ID=${CIRCLE_SHA1} 40 | 41 | if [[ -n ${PULL_REQUEST_ID} ]] 42 | then 43 | feito 44 | fi 45 | 46 | - store_artifacts: 47 | path: test-reports 48 | destination: test-reports 49 | -------------------------------------------------------------------------------- /feito/github/api.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | class API: 5 | GITHUB_API_URL = 'https://api.github.com' 6 | 7 | # TODO: Add username and password authentication methods 8 | def __init__(self, user, repo, token=None, password=None): 9 | """ 10 | param user: str -> Github username 11 | param token: str -> Github oauth token 12 | param repo: str -> Github repository name 13 | param password: str -> Github user password 14 | """ 15 | self.user = user 16 | self.repo = repo 17 | self.token = token 18 | self.password = password 19 | 20 | if token: 21 | self.auth_header = {'authorization': f'token {token}'} 22 | 23 | def create_comment_commit(self, body, commit_id, path, position, pr_id): 24 | """ 25 | Posts a comment to a given commit at a certain pull request. 26 | Check https://developer.github.com/v3/pulls/comments/#create-a-comment 27 | 28 | param body: str -> Comment text 29 | param commit_id: str -> SHA of the commit 30 | param path: str -> Relative path of the file to be commented 31 | param position: int -> The position in the diff to add a review comment 32 | param pr_id: int -> Github pull request id 33 | """ 34 | comments_url = f"{self.GITHUB_API_URL}/repos/{self.user}/{self.repo}/pulls/{pr_id}/comments" 35 | data = {'body': body, 'commit_id': commit_id, 'path': path, 'position': position} 36 | 37 | return requests.post(comments_url, json=data, headers=self.auth_header) 38 | -------------------------------------------------------------------------------- /tests/feito/test_messages.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | 3 | from feito import Messages 4 | 5 | 6 | class MessagesTestCase(TestCase): 7 | 8 | def test_format(self): 9 | stub_messages = { 10 | 'messages': [{ 11 | 'source': 'pylint', 12 | 'code': 'syntax-error', 13 | 'location': { 14 | 'path': 'tests/feito/fixtures/analyze_file.py', 15 | 'module': 'tests.feito.fixtures.analyze_file', 16 | 'function': None, 17 | 'line': 1, 18 | 'character': 0 19 | }, 20 | 'message': 'unexpected indent (, line 1)', 21 | },{ 22 | 'source': 'pylint', 23 | 'code': 'too-many-arguments', 24 | 'location': { 25 | 'path': 'feito/github/api.py', 26 | 'module': 'feito.github.api', 27 | 'function': 'API.create_comment_commit', 28 | 'line': 25, 29 | 'character': 4 30 | }, 31 | 'message': 'Too many arguments (6/5)' 32 | }] 33 | } 34 | 35 | formatted_messages = Messages(stub_messages).commit_format() 36 | 37 | assert formatted_messages == [{ 38 | 'message': 'pylint: unexpected indent (, line 1). Code: syntax-error', 39 | 'file': 'tests/feito/fixtures/analyze_file.py', 40 | 'line': 1 41 | },{ 42 | 'message': 'pylint: Too many arguments (6/5). Code: too-many-arguments', 43 | 'file': 'feito/github/api.py', 44 | 'line': 25 45 | }] 46 | -------------------------------------------------------------------------------- /tests/feito/support/prospector_analysis_stub_return.py: -------------------------------------------------------------------------------- 1 | stub_return = { 2 | 'summary': { 3 | 'started': '2018-02-14 09:46:02.106964', 4 | 'libraries': [], 5 | 'strictness': None, 6 | 'profiles': 'default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings', 7 | 'tools': [ 8 | 'dodgy', 'mccabe', 'pep8', 'profile-validator', 'pyflakes', 'pylint' 9 | ], 10 | 'message_count': 3, 11 | 'completed': '2018-02-14 09:46:02.182521', 12 | 'time_taken': '0.08', 13 | 'formatter': 'json' 14 | }, 15 | 'messages': [{ 16 | 'source': 'pep8', 17 | 'code': 'E113', 18 | 'location': { 19 | 'path': 'tests/feito/fixtures/analyze_file.py', 20 | 'module': None, 21 | 'function': None, 22 | 'line': 1, 23 | 'character': 5 24 | }, 25 | 'message': 'unexpected indentation' 26 | }, { 27 | 'source': 'pylint', 28 | 'code': 'syntax-error', 29 | 'location': { 30 | 'path': 'tests/feito/fixtures/analyze_file.py', 31 | 'module': 'tests.feito.fixtures.analyze_file', 32 | 'function': None, 33 | 'line': 1, 34 | 'character': 0 35 | }, 36 | 'message': 'unexpected indent (, line 1)' 37 | }, { 38 | 'source': 'pep8', 39 | 'code': 'E112', 40 | 'location': { 41 | 'path': 'tests/feito/fixtures/analyze_file.py', 42 | 'module': None, 43 | 'function': None, 44 | 'line': 2, 45 | 'character': 5 46 | }, 47 | 'message': 'expected an indented block' 48 | }] 49 | } 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | .pytest_cache/ 103 | -------------------------------------------------------------------------------- /tests/test_feito.py: -------------------------------------------------------------------------------- 1 | import os 2 | from unittest import TestCase 3 | from unittest import mock 4 | 5 | import requests_mock 6 | 7 | from tests.feito.support.prospector_analysis_stub_return import stub_return 8 | from feito.prospector import Prospector 9 | import feito 10 | 11 | 12 | class RunTest(TestCase): 13 | 14 | @requests_mock.Mocker() 15 | @mock.patch.object(Prospector, 'run', return_value=stub_return) 16 | def test_run(self, mock_requ, _): 17 | self.__mock_github_api(mock_requ) 18 | 19 | feito.run() 20 | 21 | sent_data = [data.json() for data in mock_requ.request_history] 22 | 23 | assert sent_data == [{ 24 | 'body': 'pep8: unexpected indentation. Code: E113', 25 | 'commit_id': '475348957349843957', 26 | 'path': 'tests/feito/fixtures/analyze_file.py', 27 | 'position': 1 28 | }, { 29 | 'body': 'pylint: unexpected indent (, line 1). Code: syntax-error', 30 | 'commit_id': '475348957349843957', 31 | 'path': 'tests/feito/fixtures/analyze_file.py', 32 | 'position': 1 33 | }, { 34 | 'body': 'pep8: expected an indented block. Code: E112', 35 | 'commit_id': '475348957349843957', 36 | 'path': 'tests/feito/fixtures/analyze_file.py', 37 | 'position': 2 38 | }] 39 | 40 | def __mock_github_api(self, mock): 41 | github_api = 'https://api.github.com' 42 | user = os.getenv('REPOSITORY_USERNAME') 43 | repo = os.getenv('REPOSITORY_NAME') 44 | token = os.getenv('OAUTH_TOKEN') 45 | pr_id = os.getenv('PULL_REQUEST_ID') 46 | 47 | mock.post( 48 | f"{github_api}/repos/{user}/{repo}/pulls/{pr_id}/comments", 49 | request_headers={'authorization': f'token {token}'}, 50 | json='ok' 51 | ) 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CircleCI](https://circleci.com/gh/magrathealabs/feito.svg?style=shield&circle-token=7ca1c63859e4f72f377a16e2e2f817e1b097c919)](https://circleci.com/gh/magrathealabs/feito) 2 | 3 | [![PyPI version](https://badge.fury.io/py/feito.svg)](https://badge.fury.io/py/feito) 4 | [![code review by feito](https://img.shields.io/badge/code%20review%20by-feito-blue.svg)](https://github.com/magrathealabs/feito) 5 | 6 | # Feito 7 | 8 | Automated code review in Python done with Prospector 9 | 10 | ## Setting up 11 | 12 | Right now, Feito only supports GitHub. 13 | 14 | ### Installation 15 | 16 | `$ pip install feito` 17 | 18 | ### Requirements for usage 19 | 20 | In order to have an account to comment as Feito in your PRs, a GitHub OAuth Token must be acquired. Follow this [link](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/#creating-a-token). When the Scopes section arrives, the `admin:repo_hook` and `repo` checkboxes must be selected. Copy the Token (really, copy it, you won't be able to visualize it afterward) and save it somewhere. 21 | 22 | ### Setting environment variables 23 | 24 | #### Locally 25 | 26 | This lib is meant to be run in CI programs, not locally, as a mean to automate code lintage. However, this is still possible. 27 | The following environment variables must be exported: 28 | 29 | ```sh 30 | PULL_REQUEST_ID (e.g., 1) 31 | REPOSITORY_USERNAME (e.g. magrathealabs) 32 | OAUTH_TOKEN (Github OAuth Token) 33 | COMMIT_ID (e.g. 08a943e797af4121c1e809d3b2288bbd70dcb0b7) 34 | REPOSITORY_NAME (e.g. feito) 35 | ``` 36 | 37 | #### In CIs 38 | 39 | In CircleCI, your `circle.yml` (v1.0) or `.circleci/config.yml` (v2.0) file can be modified with the following code: 40 | 41 | ```sh 42 | export PULL_REQUEST_ID=`echo $CIRCLE_PULL_REQUEST | grep -o -E '[0-9]+'` 43 | export REPOSITORY_NAME=${CIRCLE_PROJECT_REPONAME} 44 | export REPOSITORY_USERNAME=${CIRCLE_PROJECT_USERNAME} 45 | export COMMIT_ID=${CIRCLE_SHA1} 46 | feito 47 | ``` 48 | 49 | The `OAUTH_TOKEN` was set in Circle's own area for environment variables, and therefore does not need to be exported in the configuration file. 50 | 51 | For more insight, check out this project's `.circleci/config.yml`. 52 | 53 | 54 | ### Usage 55 | 56 | After exporting the environment variables above, execute `feito`. In a few moments, the analysis done by Prospector will be shown in your PR 57 | 58 | ## Steps taken in Feito 59 | 60 | Feito analysis is done with [Prospector](https://github.com/landscapeio/prospector). When `python run.py` is called, these are the actions taken:
61 | **1)** Gets the added, modified, renamed and copied files from the diff against the master branch.
62 | **2)** Filters the files by removing every non Python file.
63 | **3)** Runs Prospector on the Python files returned from the step above.
64 | **4)** Formats the returned Prospector analysis into a list of dictionaries containing the message, the line which triggered this review and the file path.
65 | **5)** Iterates throught this list and send a POST request for each dictionary, with its data properly formatted, that end up being the commit review message. 66 | 67 | 68 | ## Badge 69 | 70 | Show the world you're using Feito! Add the badge code review by feito to your project. 71 | 72 | [![code review by feito](https://img.shields.io/badge/code%20review%20by-feito-blue.svg)](https://github.com/magrathealabs/feito) 73 | 74 | ## License 75 | 76 | The package is available as open source under the terms of the MIT License. 77 | 78 | 79 | ## Contributing 80 | 81 | Make your modifications, run the tests with `pytest` and then open a PR. 82 | --------------------------------------------------------------------------------