Skip to content

Commit

Permalink
Merge pull request #1 from prontolabs/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Try431 authored Oct 11, 2023
2 parents 66f9cfc + 7ae7501 commit c9f743a
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 73 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/pronto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Pronto

on:
pull_request:
branches: [master]

jobs:
pronto:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
bundler-cache: true
- name: Run Pronto
run: bundle exec pronto run --exit-code -c origin/${{ github.base_ref }}
41 changes: 41 additions & 0 deletions .github/workflows/specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Specs

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
ruby-version:
- "2.3"
- "2.4"
- "2.5"
- "2.6"
- "2.7"
- "3.0"
- "3.1"
- "3.2"
exclude:
- ruby-version: "2.3" # Rugged uses the wrong openssl version on CI and segfaults (similar to https://github.com/libgit2/rugged/issues/718)
steps:
- uses: actions/checkout@v3
- name: Use specific gitlab gem version (if required)
if: matrix.ruby-version == '2.4'
run: echo "gem 'gitlab', '< 4.14.1'" >> Gemfile.local
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@7bcf9e73c0ee77d178e72c0ec69f1a99c1afc1f3 # v2.7.5
env:
CC_TEST_REPORTER_ID: 3d676246ffa66d3fdef6253a9870431b1a2da04e9ecb25486c08a38823c37b6a
COVERAGE: true
with:
coverageCommand: bundle exec rspec
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4

Documentation:
Enabled: false
Expand Down
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
# Changelog

## 0.11.1

### New features

* [#371](https://github.com/prontolabs/pronto/pull/371) allow to filter runners via config
* [#402](https://github.com/prontolabs/pronto/pull/402) add --workdir option
* [#410](https://github.com/prontolabs/pronto/pull/410) allow the default commit run against to be configured
* [#435](https://github.com/prontolabs/pronto/pull/435) allow override of config file path via PRONTO_CONFIG_FILE

### Bugs fixed

* [#422](https://github.com/prontolabs/pronto/pull/422) fix Gitlab#slug_regex when URL has different host
* [#423](https://github.com/prontolabs/pronto/pull/423) show existing message count when reporting posted messages

### Changes

* [#397](https://github.com/prontolabs/pronto/pull/397) migrate CI to GitHub Actions
* [#398](https://github.com/prontolabs/pronto/pull/398) fix duplicated runs on GitHub Actions
* [#403](https://github.com/prontolabs/pronto/pull/403) run pronto on GitHub Actions without any reporting
* [#408](https://github.com/prontolabs/pronto/pull/408) require rexml ~> 3.2.5 due to CVE-2021-28965
* [#409](https://github.com/prontolabs/pronto/pull/409) add article about GitHub Actions to README.md
* [#414](https://github.com/prontolabs/pronto/pull/414) fix typo in README.md
* [#415](https://github.com/prontolabs/pronto/pull/415) remove deprecated pronto-bundler_audit from README.md
* [#417](https://github.com/prontolabs/pronto/pull/417) relax rugged dependency to allow releases up to 1.2.0
* [#424](https://github.com/prontolabs/pronto/pull/424) add Ruby 3.1 to the test matrix
* [#431](https://github.com/prontolabs/pronto/pull/431) relax rugged dependency to allow releases up to 2.0
* [#436](https://github.com/prontolabs/pronto/pull/436) update dead links in README.md
* [#438](https://github.com/prontolabs/pronto/pull/438) add Ruby 3.2 to the test matrix
* [#439](https://github.com/prontolabs/pronto/pull/439) relax dependencies to allow currently released major versions

## 0.11.0

### New features

* [#304](https://github.com/prontolabs/pronto/pull/304) add option to limit comments per PR review
* [#333](https://github.com/prontolabs/pronto/pull/333) add github_combined_status formatter
* [#334](https://github.com/prontolabs/pronto/pull/334) add configurable review_type for GitHub (with REQUEST_CHANGES as default)
* [#351](https://github.com/prontolabs/pronto/pull/351) add gitLab_mr formatter
* [#369](https://github.com/prontolabs/pronto/pull/369) make Pronto::Git::Patch#new_file_path public
* update to the BitBucket 2.0 API (_as the 1.0 API was deprecated_) via [#347](https://github.com/prontolabs/pronto/pull/347), [#348](https://github.com/prontolabs/pronto/pull/348), [#352](https://github.com/prontolabs/pronto/pull/352) and [#354](https://github.com/prontolabs/pronto/pull/354)

### Bugs fixed

* [#344](https://github.com/prontolabs/pronto/pull/344) treat Gemfile and .gemspecs as Ruby
* [#380](https://github.com/prontolabs/pronto/pull/380) fix compatibility with rugged >= 0.99
* [#387](https://github.com/prontolabs/pronto/pull/387) fix running pronto inside git submodules

### Changes

* [#370](https://github.com/prontolabs/pronto/pull/370) allow thor 1.x gem versions
* [#379](https://github.com/prontolabs/pronto/pull/379) allow rugged 1.0.x gem versions
* [#386](https://github.com/prontolabs/pronto/pull/386) add ruby 2.7 to CI
* [#390](https://github.com/prontolabs/pronto/pull/390) fix issue with generating Sorbet RBI
* [#396](https://github.com/prontolabs/pronto/pull/396) add support for Ruby 3.0
* document/improve GitHub Actions integration in README.md via [#360](https://github.com/prontolabs/pronto/pull/360), [#378](https://github.com/prontolabs/pronto/pull/378) and [#389](https://github.com/prontolabs/pronto/pull/389)
* add links to additional pronto runners in README.md

## 0.10.0

### New features
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
source 'https://rubygems.org'

gemspec

local_gemfile = File.expand_path('Gemfile.local', __dir__)
eval_gemfile local_gemfile if File.exist?(local_gemfile)
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ in order to avoid the rate limit of the providers.
X = N / {PRONTO_WARNINGS_PER_REVIEW || warnings_per_review || 30})
```

Note: In case no environment variable or config setting is specified in `.pronto.yml`,
Note: In case no environment variable or config setting is specified in `.pronto.yml`,
a default value of `30` will be used.

```sh
Expand Down Expand Up @@ -164,7 +164,7 @@ Pronto.run('origin/master', '.', formatters)

#### GitHub Actions Integration

You can also run Pronto as a GitHub action.
You can also run Pronto as a GitHub action.

Here's an example `.github/workflows/pronto.yml` workflow file using the `github_status` and `github_pr` formatters and running on each GitHub PR, with `pronto-rubocop` as the runner:

Expand Down Expand Up @@ -222,7 +222,7 @@ Merge request integration:
$ PRONTO_GITLAB_API_PRIVATE_TOKEN=token PRONTO_PULL_REQUEST_ID=id pronto run -f gitlab_mr -c origin/master
```

On GitLabCI make make sure to run Pronto in a [merge request pipeline](https://docs.gitlab.com/ce/ci/merge_request_pipelines/):
On GitLabCI, make sure to run Pronto in a [merge request pipeline](https://docs.gitlab.com/ce/ci/merge_request_pipelines/):

```yml
lint:
Expand Down Expand Up @@ -261,7 +261,14 @@ $ PRONTO_BITBUCKET_USERNAME=user PRONTO_BITBUCKET_PASSWORD=pass pronto run -f bi
## Configuration

The behavior of Pronto can be controlled via the `.pronto.yml` configuration
file. It must be placed in your project directory.
file. It can either be placed in the working directory (*) or specified using
the environment variable `PRONTO_CONFIG_FILE`.

(*) The working directory is where you run the command from, which is typically
your project directory.

If this file cannot be found, then the default configuration in
[Pronto::ConfigFile::EMPTY](lib/pronto/config_file.rb) applies.

The file has the following format:

Expand Down Expand Up @@ -290,13 +297,23 @@ bitbucket:
max_warnings: 150
warnings_per_review: 30
verbose: false
runners: [rubocop, eslint] # only listed runners will be executed
skip_runners: [reek] # all, except listed runners will be executed
```

All properties that can be specified via `.pronto.yml`, can also be specified
via environment variables. Their names will be the upcased path to the property.
For example: `PRONTO_GITHUB_SLUG` or `PRONTO_GITLAB_API_PRIVATE_TOKEN`. Environment variables
will always take precedence over values in configuration file.

| Property | Description |
|-----------------------|--------------------------------------------------------------------------------------|
| `max_warnings` | Limits the amount of warnings. Returns all warnings if option is skipped. |
| `runners` | Runs only listed runners. Runs everything if option is skipped. |
| `skip_runners` | All, except listed runners will be executed. Runs everything if option is skipped. |
| `verbose` | Outputs more information when set to `true`. |
| `warnings_per_review` | Limits the amount of warnings per review. Returns all warnings if option is skipped. |

### Message format

Pronto allows you to configure the format of the messages that are produced. You
Expand Down Expand Up @@ -342,7 +359,6 @@ Currently available:
* [pronto-bigfiles](https://github.com/apiology/pronto-bigfiles)
* [pronto-blacklist](https://github.com/pbstriker38/pronto-blacklist)
* [pronto-brakeman](https://github.com/prontolabs/pronto-brakeman)
* [pronto-bundler_audit](https://github.com/pdobb/pronto-bundler_audit)
* [pronto-checkstyle](https://github.com/seikichi/pronto-checkstyle)
* [pronto-coffeelint](https://github.com/siebertm/pronto-coffeelint)
* [pronto-clang_format](https://github.com/micjabbour/pronto-clang_format)
Expand Down Expand Up @@ -410,12 +426,13 @@ Articles to help you to get started:
* [How to end fruitless dev discussions about your project’s code style?](https://medium.com/appaloosa-store-engineering/how-to-end-fruitless-dev-discussions-about-your-project-s-code-style-245070bff6d4)
* [Free automated code reviews using Pronto](https://hovancik.net/blog/2016/04/11/free-automated-code-reviews-using-pronto/)
* [Automated Elixir code review with Github, Credo and Travis CI](https://medium.com/fazibear/automated-elixir-code-review-with-github-credo-and-travis-ci-986cd56b8f02)
* [Running Rubocop before git commit](https://christoph.luppri.ch/articles/2016/11/21/running-rubocop-before-git-commit/)
* [Running Rubocop before git commit](https://web.archive.org/web/20181225040512/https://christoph.luppri.ch/articles/code-quality/running-rubocop-before-git-commit/)
* [Pronto, Codeship and GitHub for automatic code review](http://abinoam.tl1n.com/pronto-codeship-and-github-for-automatic-code-review/)
* [How to automatically review your PRs for style violations with Pronto and RuboCop](https://christoph.luppri.ch/articles/2017/03/05/how-to-automatically-review-your-prs-for-style-violations-with-pronto-and-rubocop/)
* [How to automatically review your PRs for style violations with Pronto and RuboCop](https://christoph.luppri.ch/how-to-automatically-review-your-prs-for-style-violations-with-pronto-and-rubocop)
* [Create your own Pronto Runner](https://kevinjalbert.com/create-your-own-pronto-runner/)
* [Make Code Reviews A Little Bit Better With Automation](https://medium.com/jimmy-farrell/make-codes-reviews-a-little-bit-better-with-automation-35640df08a62)
* [Stop shipping untested Ruby code with undercover](https://medium.com/futuredev/stop-shipping-untested-ruby-code-with-undercover-1edc963be4a6)
* [Automatic code review with Pronto and GitHub Actions](https://everydayrails.com/2021/05/29/pronto-github-actions-code-quality.html)

Make a Pull Request to add something you wrote or found useful.

Expand Down
8 changes: 6 additions & 2 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
require 'pronto/formatter/formatter'

module Pronto
def self.run(commit = 'master', repo_path = '.',
def self.run(commit = nil, repo_path = '.',
formatters = [Formatter::TextFormatter.new], file = nil)
commit ||= 'master'
commit ||= default_commit

repo = Git::Repository.new(repo_path)
options = { paths: [file] } if file
Expand All @@ -72,4 +72,8 @@ def self.run(commit = 'master', repo_path = '.',

result
end

def self.default_commit
Config.new.default_commit
end
end
8 changes: 6 additions & 2 deletions lib/pronto/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def is_thor_reserved_word?(word, type)

method_option :commit,
type: :string,
default: 'master',
aliases: '-c',
desc: 'Commit for the diff'

Expand All @@ -33,6 +32,11 @@ def is_thor_reserved_word?(word, type)
type: :boolean,
desc: 'Analyze changes in git staging area'

method_option :workdir,
type: :boolean,
aliases: ['-w'],
desc: 'Analyze both staged and unstaged changes'

method_option :runner,
type: :array,
default: [],
Expand All @@ -55,7 +59,7 @@ def run(path = '.')

formatters = ::Pronto::Formatter.get(options[:formatters])

commit_options = %i[staged unstaged index]
commit_options = %i[workdir staged unstaged index]
commit = commit_options.find { |o| options[o] } || options[:commit]

repo_workdir = ::Rugged::Repository.discover(path).workdir
Expand Down
45 changes: 41 additions & 4 deletions lib/pronto/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def initialize(config_hash = ConfigFile.new.to_h)
end
end

def default_commit
default_commit =
ENV['PRONTO_DEFAULT_COMMIT'] ||
@config_hash.fetch('default_commit', 'master')
default_commit
end

def consolidate_comments?
consolidated =
ENV['PRONTO_CONSOLIDATE_COMMENTS'] ||
Expand Down Expand Up @@ -52,27 +59,57 @@ def bitbucket_hostname
end

def warnings_per_review
ENV['PRONTO_WARNINGS_PER_REVIEW'] && Integer(ENV['PRONTO_WARNINGS_PER_REVIEW']) || @config_hash['warnings_per_review']
fetch_integer('warnings_per_review')
end

def max_warnings
ENV['PRONTO_MAX_WARNINGS'] && Integer(ENV['PRONTO_MAX_WARNINGS']) || @config_hash['max_warnings']
fetch_integer('max_warnings')
end

def message_format(formatter)
formatter_config = @config_hash[formatter]
if formatter_config && formatter_config.key?('format')
formatter_config['format']
else
ENV['PRONTO_FORMAT'] || @config_hash['format']
fetch_value('format')
end
end

def skip_runners
fetch_list('skip_runners')
end

def runners
fetch_list('runners')
end

def logger
@logger ||= begin
verbose = ENV['PRONTO_VERBOSE'] || @config_hash['verbose']
verbose = fetch_value('verbose')
verbose ? Logger.new($stdout) : Logger.silent
end
end

private

def fetch_integer(key)
full_key = env_key(key)

(ENV[full_key] && Integer(ENV[full_key])) || @config_hash[key]
end

def fetch_value(key)
ENV[env_key(key)] || @config_hash[key]
end

def env_key(key)
"PRONTO_#{key.upcase}"
end

def fetch_list(key)
Array(fetch_value(key)).flat_map do |runners|
runners.split(',')
end
end
end
end
Loading

0 comments on commit c9f743a

Please sign in to comment.