Читает формат checkstyle и пишет комментарии к pull-request в stash/bitbucket
- Публикация комментариев на основе отчетов checkstyle
- Режимы работы инспектора только с измененным кодом или контекстом
- Группировка ошибок
- Ограничения по важности
- Ограничения по количеству комментариев: общий, на файл, на группу
- Реакция на исправленные ошибки (геймификация)
- Игнорирование по паттерну ошибки, или по файлу
- Отправка статистики в statsd
Данные которые требуются: проект, репозиторий, ветка. Комментарии будут публиковаться в пулл-реквест со статусом OPEN, если такой имеется.
- Передается результат
git diff origin/master <BRANCH>
или разница ревизий - Последовательно передаются результаты работы статических анализаторов в формате checkstyle
- Производится анализ и рассылка комментариев
This project reads checkstyle format reports and writes comments to stash / bitbucket pull-requests.
- Posts comments based on checkstyle reports
- Can be configured to check the context or modified code only
- Error grouping
- Severity limitation
- Limit the number of comments: total, per file, or per group
- Reaction to fixed bugs (gamification)
- Ignoring by error patterns and by filenames
- Sending statistics to statsd
Required options: project, repository, and branch names. Comments will be posted to a pull-request with an OPEN status, if any.
- The results of
git diff origin/master <BRANCH>
or the revisions difference is transmitted to analyzers - Static analyzers' reports are collected
- The comments are analyzed and sent to Bitbucket API
https://developer.atlassian.com/server/bitbucket/reference/rest-api/
Default configuration filename is .config.php
<?php
use BitbucketReviews\Config;
/**
* @see \BitbucketReviews\Config
*/
return [
// Stash API config
// https://<hostname>/projects/<project>/repos/<repository>/browse
'stash' => [
'url' => 'https://bitbucket.org',
// @see https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html
'accessToken' => '<secret-token-read-perms>',
'project' => '<project>',
'repository' => '<repository>',
'debug' => false,
],
'analyzer' => [
'inspect' => Config::INSPECT_CONTEXT,
'ignoredText' => [
'eslint.rules.radix',
],
'ignoredFiles' => [
'composer.json',
'composer.lock',
],
'limit' => Config::NO_LIMIT,
'limitPerFile' => Config::NO_LIMIT,
'limitPerGroup' => Config::NO_LIMIT,
],
// Optional
'statsd' => [
'host' => '<statsd-host>',
'port' => '<statsd-port>',
'namespace' => 'myApp.code-analyze',
],
];
/vendor/bin/bitbucket-reviews run refs/head/MY_BRANCH git-diff.txt \
--config config.php \
--checkstyle eslint.xml:/code/base \
--checkstyle phan.xml \
--checkstyle phpstan.xml
run [options] [--] <branch> <diff>
Arguments:
branch Branch name, full path like `refs/heads/master`
diff git diff output file path
Options:
--diff-vsc[=DIFF-VSC] git diff output file path [default: "git"]
-c, --checkstyle[=CHECKSTYLE] checkstyle file path <filename>:<root> (multiple values allowed)
-k, --config[=CONFIG] config file [default: ".config.php"]
#!/usr/bin/env bash
set -x
function join { local IFS="$1"; shift; echo "$*"; }
BRANCH_NAME=$1 # my-feature
CONTEXT_LINES=$2 # 10
CODE_PATH=/code
mkdir reports
### Saving DIFF for analyzer - diff.txt
git diff -U${CONTEXT_LINES:-10} master...${BRANCH_NAME} > diff.txt
### Collecting ESLINT report - eslint.xml ###
JS_IMAGE=yarn:latest
ESLINT_FILES=$(git diff --name-only master...${BRANCH_NAME} | grep -E "\.(js|vue)$")
docker run --rm \
--volume $(pwd):${CODE_PATH} \
--workdir ${CODE_PATH} \
--entrypoint=${CODE_PATH}/node_modules/.bin/eslint \
--interactive \
${JS_IMAGE} \
${ESLINT_FILES} -o ./reports/eslint.xml -f checkstyle
### Collecting PHAN report - phan.xml ###
PHP_IMAGE=php7-cli:latest
PHAN_FILES=$(join , $(git diff --name-only origin/master...${BRANCH_NAME} | grep -E "\.php$"))
docker run --rm \
--volume $(pwd):${CODE_PATH} \
--workdir ${CODE_PATH} \
--entrypoint ${CODE_PATH}/vendor/bin/phan \
--interactive \
${PHP_IMAGE} \
-k ${CODE_PATH}/.phan.php -m checkstyle -o ./reports/phan.xml --include-analysis-file-list ${PHAN_FILES}
### Static review
REVIEW_IMAGE=aaerofeev/bitbucket-static-reviews:latest
docker pull ${REVIEW_IMAGE}
docker run --rm \
--volume $(pwd)/reports:/reports \
--volume $(pwd)/bin/analyze/review.php:/code/config.php \
${REVIEW_IMAGE} \
run -k /code/config.php -c /reports/eslint.xml:${CODE_PATH} -c /reports/phan.xml refs/heads/${BRANCH_NAME} /reports/diff.txt
exit 0