Coder Social home page Coder Social logo

bitbucket-static-reviews's Introduction

Интеграция checkstyle-format в stash/bitbucket

Checkstyle-format integration into stash / bitbucket

See English version below

Читает формат checkstyle и пишет комментарии к pull-request в stash/bitbucket

Dockerhub image

Возможности

  • Публикация комментариев на основе отчетов checkstyle
  • Режимы работы инспектора только с измененным кодом или контекстом
  • Группировка ошибок
  • Ограничения по важности
  • Ограничения по количеству комментариев: общий, на файл, на группу
  • Реакция на исправленные ошибки (геймификация)
  • Игнорирование по паттерну ошибки, или по файлу
  • Отправка статистики в statsd

Автоматическая пометка "Исправлено" / "Fixed" mark added automatically

Fixed

Группировка ошибок / Error grouping

Group

Как работает

Данные которые требуются: проект, репозиторий, ветка. Комментарии будут публиковаться в пулл-реквест со статусом OPEN, если такой имеется.

  1. Передается результат git diff origin/master <BRANCH> или разница ревизий
  2. Последовательно передаются результаты работы статических анализаторов в формате checkstyle
  3. Производится анализ и рассылка комментариев

In English

This project reads checkstyle format reports and writes comments to stash / bitbucket pull-requests.

Features

  • 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

How does it work

Required options: project, repository, and branch names. Comments will be posted to a pull-request with an OPEN status, if any.

  1. The results of git diff origin/master <BRANCH> or the revisions difference is transmitted to analyzers
  2. Static analyzers' reports are collected
  3. The comments are analyzed and sent to Bitbucket API

Bitbucket API

https://docs.atlassian.com/bitbucket-server/rest/5.15.0/bitbucket-rest.html?utm_source=%2Fstatic%2Frest%2Fbitbucket-server%2Flatest%2Fbitbucket-rest.html&utm_medium=301#idm45622371276656

https://developer.atlassian.com/server/bitbucket/reference/rest-api/

Config

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',
    ],
];

Usage example

/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"]

Advanced usage

#!/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

bitbucket-static-reviews's People

Contributors

aaerofeev avatar alexandrwelcome avatar antonsergeyev avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

antonsergeyev

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.