code-review/bot
Valentin Rigal 2e4e05cfc0
Compare issues with the backend (a.k.a. before/after) (#1581)
* Compare issues with known ones in the backend

* rebase

* Update list_repo_issues helper

* Fix issues grouping by path

* Cache Issue hash computed value

* Repport issues that are tagged as new

* Update publication

* Add a comment section for issues outside the diff

* Publish issues inside or outside the patch in two similar sections of the Phabricator comment

* Only publish new issues to harbormaster

* Improve message for known issues

* Always refer to issues as 'defects' in Phabricator comment

* Fix Phabricator publish return value

* Make sure to run before/after on all the diffs of a revision

* Only store new issues in bot's backend while runing before/after

* Group in and out issue main comments

* Preserve original publications (remove known issues footer)

* Update existing tests

* Add tests

* Use a cached prop for issues' hash

Define local repository in runtime settings

* Fix before after random check for a revision

* Suggestions

* Use itertools.groupby or paths lookup

* Improve RNG seed comment

* Always compare issues that are found inside the diff

* Raise error to sentry when GECKO_BASE_REV is unset on the decision task

* Disable before/after for a non published revision

* Override runtime local repository setting

* Do not display existing issues stats
2023-05-11 07:31:20 +02:00
..
code_review_bot Compare issues with the backend (a.k.a. before/after) (#1581) 2023-05-11 07:31:20 +02:00
docker Support cloning a revision's repository to build references to found issues (#1517) 2023-05-11 07:31:18 +02:00
tests Compare issues with the backend (a.k.a. before/after) (#1581) 2023-05-11 07:31:20 +02:00
tools bot: add specific request headers. 2023-05-03 14:40:53 +03:00
.dockerignore Add dockerfile 2019-06-07 16:33:14 +02:00
README.md Add prettier linter to pre-commit (#1660) 2023-04-17 13:56:57 +02:00
VERSION Release 1.6.7 2023-05-11 07:31:20 +02:00
requirements-dev.txt build(deps-dev): bump pre-commit from 3.2.2 to 3.3.1 in /bot (#1702) 2023-05-11 07:31:19 +02:00
requirements.txt build(deps): bump libmozdata from 0.2.0 to 0.2.2 in /bot (#1701) 2023-05-11 07:31:19 +02:00
setup.py Use pre-commit + black + other hooks (#73) 2019-08-05 13:34:17 +02:00
taskcluster-hook.json Add prettier linter to pre-commit (#1660) 2023-04-17 13:56:57 +02:00

README.md

Static Analysis Bot

Developer setup

The code review bot is a Python 3 application, so it should be easy to bootstrap on your computer:

mkvirtualenv -p /usr/bin/python3 code-review
pip install -r requirements.txt -r requirements-dev.txt
pip install -e .

You should now be able to run linting and unit tests:

flake8
pytest

If those tests are OK, you can run the bot locally, by using a local configuration file with your Phabricator API token (see details at the end of this README), and a task reference to analyze.

export TRY_TASK_ID=XXX
export TRY_TASK_GROUP_ID=XXX
code-review-bot --configuration=path/to/config.yaml

Configuration

The code review bot is configured through the Taskcluster secrets service or a local YAML configuration file (the latter is preferred for new contributors as it's easier to setup)

The following configuration variables are currently supported:

  • APP_CHANNEL [required] is provided by the common configuration (staging or production)
  • REPORTERS [required] lists all the reporting tools to use when a code review is completed (details below)
  • PHABRICATOR [required] holds the credentials to make API calls on Phabricator.
  • ZERO_COVERAGE_ENABLED is a boolean value enabling or disabling the zero coverage warning report.
  • PAPERTRAIL_HOST is the optional Papertrail host configuration, used for logging.
  • PAPERTRAIL_PORT is the optional Papertrail port configuration, used for logging.
  • SENTRY_DSN is the optional Sentry full url to report runtime errors.

The REPORTERS configuration is a list of dictionaries describing which reporting tool to use at the end of the patches code review. Supported reporting tools are emails (for admins) and Phabricator.

Each reporter configuration must contain a reporter key with a unique name per tool. Each tool has its own configuration requirement.

You can view a full configuration sample here.

Phabricator credentials

They are required, and must be set like this:

  PHABRICATOR:
    url: 'https://phabricator.services.mozilla.com/api/'
    api_key: api-XXXX

Reporter: Mail

Key reporter is mail

The emails are sent through Taskcluster notify service, the hook must have notify:email:* in its scopes (enabled on our staging & production instances)

Only one configuration is required: emails is a list of emails addresses receiving the admin output for each analysis.

This reporter will send detailed information about every issue.

Reporter: Phabricator

Key reporter is phabricator

Configuration:

  • analyzers_skipped : The analyzers that will not be published on Phabricator.

This reporter will send detailed information about every publishable issue.

Example configuration

---
common:
  APP_CHANNEL: development
  PHABRICATOR:
    url: https://dev.phabricator.mozilla.com
    api_key: deadbeef123456

bot:
  REPORTERS:
    - reporter: phabricator