Git Product home page Git Product logo

git-reviewers's Introduction

git-reviewers

PyPI Python Versions

Build Status Updates Maintainability Test Coverage

Intelligently find code reviewers. See also, git-browse.

Installation

Homebrew (preferred for MacOS)

If you use Homebrew, you can install git-reviewers through the homebrew-albertyw tap:

brew install albertyw/albertyw/git-reviewers

Manual

If you don't use Homebrew, first clone this repository to somewhere on your system (perhaps in your dotfiles repository), then run <REPOSITORY_LOCATION>/install.sh.

After installation, you can modify any default flags for git-reviewers in ~/.gitconfig

Usage

usage: reviewers.py [-h] [-v] [--verbose] [-i IGNORE] [-j JSON] [-c]

Suggest reviewers for your diff. https://github.com/albertyw/git-reviewers

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --verbose             verbose mode
  -i IGNORE, --ignore IGNORE
                        ignore a list of reviewers (comma separated)
  -j JSON, --json JSON  json file to read configs from, overridden by CLI
                        flags
  -c, --copy            Copy the list of reviewers to clipboard, if available
  -b BASE_BRANCH, --base-branch BASE_BRANCH
                        Compare against a base branch (default: master)

Finders

git-reviewers is componsed of a set of strategies for generating lists of reviewers, or Finders. They return a weighted set of reviewers which is then sorted and recommended to you. They include:

  • FindLogReviewers - Generate a list of reviewers based on committers to your committed (but not merged with master) files
  • FindHistoricalReviewers - Generate reviewers based on the repository committers as a whole
  • FindArcCommitReviewers - Generate reviewers based on arc commit messages for files which you have modified on your branch

Configuration

git-reviewers supports reading configuration from a configuration file with the --json flag. The configuration file accepts json with the following fields (all fields optional):

{
    "verbose": false,
    "copy": false,
    "ignore": ["a", "b", "c"],
    "base_branch": "master"
}

git-reviewers will also by default search for and load a json configuration file at ~/.git/reviewers.

Development

pip install -r requirements-test.txt
ruff check .
mypy .
coverage run -m unittest
coverage report -m

Publishing

pip install twine
python -m build
twine upload dist/*

Need to also update albertyw/homebrew-albertyw.

git-reviewers's People

Contributors

albertyw avatar dextero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

git-reviewers's Issues

make base branch configurable

Currently the base branch which changes are compared against is hardcoded to master:

def get_changed_files(self) -> List[str]:
""" Find the changed files between current status and master """
git_diff_files_command = ['git', 'diff', 'master', '--name-only']

This is an issue because in many scenarios, git reviewers can be run on a branch which would be based on another branch such as origin/master. If that diverges from master then the whole algorithm is not based on the right changes, and in the worst case it results in terrible performance as seen in #40.

So ideally this should be configurable via a CLI option, since the base branch will vary per repo. However a good first start would be to default to comparing against the branch configured as $mybranch's upstream branch by the branch.$mybranch.remote and branch.$mybranch.merge configuration options.

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Make file-based diff work on committed code

Running git reviewers on code that has already been committed (onto a branch) does not get any results. git reviewers should do a diff between the current branch and the master.

Error when running

When running git reviewers -c

Traceback (most recent call last):
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 192, in <module>
    main()
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 188, in main
    show_reviewers(reviewers_list, args.copy)
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 141, in show_reviewers
    p.communicate(input=reviewer_string)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 828, in communicate
    self._stdin_write(input)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 781, in _stdin_write
    self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str'

performance issue

I did a fresh pip install and ran it, but strace showed it running git shortlog -sne in many files in the repo, and each one takes about 0.25s to complete, so on a large repo this seems to take forever. Since there was no visible feedback, I initially assumed it had hung.

Bad error message when arc whoami fails

$ git reviewers
 Exception
[cURL/7] (https://code.uberinternal.com/api/user.whoami) <CURLE_COULDNT_CONNECT> The cURL library raised an error while making a request. You may be able to find more information about this error (error code: 7) on the cURL site: http://curl.haxx.se/libcurl/c/libcurl-errors.html#CURLECOULDNTCONNECT
(Run with `--trace` for a full exception trace.)
Traceback (most recent call last):
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 315, in <module>
    main()
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 310, in main
    reviewers_list = get_reviewers(config)
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 205, in get_reviewers
    most_common = FindArcCommitReviewers(config) \
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 77, in filter_phabricator_activated
    usernames = [self.parse_phabricator(*x) for x in username_processes]
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 77, in <listcomp>
    usernames = [self.parse_phabricator(*x) for x in username_processes]
  File "/Users/albertyw/.dotfiles/scripts/git/git-reviewers/git_reviewers/reviewers.py", line 63, in parse_phabricator
    phab_output = json.loads(output_str)
  File "/usr/local/Cellar/[email protected]/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/[email protected]/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/[email protected]/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

reviewers.py: error: unrecognized arguments: --path=./

Right after installation, I get this error message:

$ git reviewers
usage: reviewers.py [-h] [-v] [-i IGNORE] [-c]
reviewers.py: error: unrecognized arguments: --path=./

Indeed, the --path argument is not listed in the --help output, neither can be found in the code. If I remove the --path=${GIT_PREFIX:-./}, it works just fine.

installation fails due to Counter missing from collections

$ pip3 install --user git+https://github.com/albertyw/git-reviewers.git                                                                                       
Collecting git+https://github.com/albertyw/git-reviewers.git                                                                                                     
  Cloning https://github.com/albertyw/git-reviewers.git to /tmp/pip-065tb0r7-build                                                                               
    Complete output from command python setup.py egg_info:                                                                                                       
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-065tb0r7-build/setup.py", line 8, in <module>
        from git_reviewers import reviewers
      File "/tmp/pip-065tb0r7-build/git_reviewers/reviewers.py", line 136, in <module>
        class FindHistoricalReviewers(FindFileLogReviewers):
      File "/tmp/pip-065tb0r7-build/git_reviewers/reviewers.py", line 137, in FindHistoricalReviewers
        def get_reviewers(self) -> typing.Counter[str]:
    AttributeError: module 'typing' has no attribute 'Counter'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-065tb0r7-build/ 

This happens with Python 3.5.3, but not 3.6.1.

Update readme

List strategies for getting reviewers, remove path argument.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.