├── .gitignore ├── lib ├── danger_plugin.rb ├── danger_pronto.rb └── danger_pronto │ ├── gem_version.rb │ └── plugin.rb ├── Gemfile ├── .travis.yml ├── spec ├── pronto_spec.rb └── spec_helper.rb ├── Guardfile ├── Rakefile ├── LICENSE.txt ├── README.md └── danger-pronto.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | pkg 3 | .idea/ 4 | -------------------------------------------------------------------------------- /lib/danger_plugin.rb: -------------------------------------------------------------------------------- 1 | require 'danger_pronto/plugin' 2 | -------------------------------------------------------------------------------- /lib/danger_pronto.rb: -------------------------------------------------------------------------------- 1 | require 'danger_pronto/gem_version' 2 | -------------------------------------------------------------------------------- /lib/danger_pronto/gem_version.rb: -------------------------------------------------------------------------------- 1 | module Pronto 2 | VERSION = "0.3.2".freeze 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in danger-pronto.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: 3 | directories: 4 | - bundle 5 | 6 | rvm: 7 | - 2.0 8 | - 2.1.3 9 | - 2.3.1 10 | 11 | script: 12 | - bundle exec rake spec -------------------------------------------------------------------------------- /spec/pronto_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../spec_helper', __FILE__) 2 | 3 | module Danger 4 | describe Danger::DangerPronto do 5 | it 'should be a plugin' do 6 | expect(Danger::DangerPronto.new(nil)).to be_a Danger::Plugin 7 | end 8 | 9 | # 10 | # You should test your custom attributes and methods here 11 | # 12 | describe 'with Dangerfile' do 13 | before do 14 | end 15 | 16 | # Some examples for writing tests 17 | # You should replace these with your own. 18 | 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A guardfile for making Danger Plugins 2 | # For more info see https://github.com/guard/guard#readme 3 | 4 | # To run, use `bundle exec guard`. 5 | 6 | guard :rspec, cmd: 'bundle exec rspec' do 7 | require 'guard/rspec/dsl' 8 | dsl = Guard::RSpec::Dsl.new(self) 9 | 10 | # RSpec files 11 | rspec = dsl.rspec 12 | watch(rspec.spec_helper) { rspec.spec_dir } 13 | watch(rspec.spec_support) { rspec.spec_dir } 14 | watch(rspec.spec_files) 15 | 16 | # Ruby files 17 | ruby = dsl.ruby 18 | dsl.watch_spec_files_for(ruby.lib_files) 19 | end 20 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | require 'rubocop/rake_task' 4 | 5 | RSpec::Core::RakeTask.new(:specs) 6 | 7 | task default: :specs 8 | 9 | task :spec do 10 | Rake::Task['specs'].invoke 11 | Rake::Task['rubocop'].invoke 12 | Rake::Task['spec_docs'].invoke 13 | end 14 | 15 | desc 'Run RuboCop on the lib/specs directory' 16 | RuboCop::RakeTask.new(:rubocop) do |task| 17 | task.patterns = ['lib/**/*.rb', 'spec/**/*.rb'] 18 | end 19 | 20 | desc 'Ensure that the plugin passes `danger plugins lint`' 21 | task :spec_docs do 22 | sh 'bundle exec danger plugins lint' 23 | end 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 RestlessThinker 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # danger-pronto 2 | 3 | [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE.txt) 4 | [![Gem](https://img.shields.io/gem/v/danger-pronto.svg?style=flat)](https://rubygems.org/gems/danger-pronto) 5 | 6 | A [Danger](https://github.com/danger/danger) plugin for [Pronto](https://github.com/mmozuras/pronto). 7 | Created by the folks at [ABODO](https://www.abodo.com). By default, only lints added or modified files. 8 | 9 | ## Installation 10 | 11 | Add this line to your Gemfile: 12 | 13 | ```rb 14 | gem 'danger-pronto' 15 | ``` 16 | 17 | Add pronto and runners to your Gemfile: 18 | 19 | ```rb 20 | gem 'pronto' 21 | gem 'pronto-jshint' 22 | gem 'pronto-rubocop' 23 | gem 'pronto-scss' 24 | ``` 25 | 26 | ## Usage 27 | 28 | Pronto runs the checks on a diff between the current HEAD and the provided commit-ish (default is master). 29 | Results are passed out as a table in markdown. 30 | 31 | 32 | Specifying custom config file. 33 | ```ruby 34 | pronto.lint 35 | ``` 36 | 37 | Run checks on a diff between the current HEAD and a specified commit 38 | ```ruby 39 | pronto.lint("e757913") 40 | ``` 41 | 42 | #### Methods 43 | 44 | 45 | `lint(commit: String)` 46 | 47 | Runs checks on a diff between the current HEAD and the provided commit-ish (default is master). Generates a `markdown` list of warnings. 48 | 49 | 50 | 51 | ## License 52 | 53 | MIT 54 | -------------------------------------------------------------------------------- /lib/danger_pronto/plugin.rb: -------------------------------------------------------------------------------- 1 | module Danger 2 | # Lints files via Pronto through specified runners 3 | # Results are displayed as a table in markdown 4 | # 5 | # [Runners](https://github.com/mmozuras/pronto#runners) 6 | # 7 | # @example Lint files with Pronto and specified Pronto Runners 8 | # 9 | # pronto.lint 10 | # 11 | # @see RestlessThinker/danger-pronto 12 | # @tags pronto, linter 13 | # 14 | class DangerPronto < Plugin 15 | 16 | # Runs files through Pronto. Generates a `markdown` list of warnings. 17 | def lint(commit = nil) 18 | files = pronto(commit) 19 | return if files.empty? 20 | 21 | markdown offenses_message(files) 22 | end 23 | 24 | private 25 | 26 | # Executes pronto command 27 | # @param commit [String] hash/branch/tag 28 | # @return [Hash] Converted hash from pronto json output 29 | def pronto(specified_commit = nil) 30 | commit = "origin/master" 31 | commit = specified_commit if !specified_commit.nil? 32 | pronto_output = `#{'bundle exec ' if File.exists?('Gemfile')}pronto run -f json -c #{commit}` 33 | JSON.parse(pronto_output) 34 | end 35 | 36 | # Builds the message 37 | def offenses_message(offending_files) 38 | require 'terminal-table' 39 | 40 | message = "### Pronto violations\n\n" 41 | table = Terminal::Table.new( 42 | headings: %w(File Line Reason Runner), 43 | style: { border_i: '|' }, 44 | rows: offending_files.map do |file| 45 | [file['path'], file['line'], file['message'], file['runner']] 46 | end 47 | ).to_s 48 | message + table.split("\n")[1..-2].join("\n") 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | ROOT = Pathname.new(File.expand_path('../../', __FILE__)) 3 | $:.unshift((ROOT + 'lib').to_s) 4 | $:.unshift((ROOT + 'spec').to_s) 5 | 6 | require 'bundler/setup' 7 | require 'pry' 8 | 9 | require 'rspec' 10 | require 'danger' 11 | 12 | # Use coloured output, it's the best. 13 | RSpec.configure do |config| 14 | config.filter_gems_from_backtrace "bundler" 15 | config.color = true 16 | config.tty = true 17 | end 18 | 19 | require 'danger_plugin' 20 | 21 | # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb 22 | # If you are expanding these files, see if it's already been done ^. 23 | 24 | # A silent version of the user interface, 25 | # it comes with an extra function `.string` which will 26 | # strip all ANSI colours from the string. 27 | 28 | # rubocop:disable Lint/NestedMethodDefinition 29 | def testing_ui 30 | @output = StringIO.new 31 | def @output.winsize 32 | [20, 9999] 33 | end 34 | 35 | cork = Cork::Board.new(out: @output) 36 | def cork.string 37 | out.string.gsub(/\e\[([;\d]+)?m/, "") 38 | end 39 | cork 40 | end 41 | # rubocop:enable Lint/NestedMethodDefinition 42 | 43 | # Example environment (ENV) that would come from 44 | # running a PR on TravisCI 45 | def testing_env 46 | { 47 | 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true', 48 | 'TRAVIS_PULL_REQUEST' => '800', 49 | 'TRAVIS_REPO_SLUG' => 'artsy/eigen', 50 | 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d', 51 | 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio' 52 | } 53 | end 54 | 55 | # A stubbed out Dangerfile for use in tests 56 | def testing_dangerfile 57 | env = Danger::EnvironmentManager.new(testing_env) 58 | Danger::Dangerfile.new(env, testing_ui) 59 | end 60 | -------------------------------------------------------------------------------- /danger-pronto.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'danger_pronto/gem_version.rb' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'danger-pronto' 8 | spec.version = Pronto::VERSION 9 | spec.authors = ['RestlessThinker'] 10 | spec.email = ['penaflor@gmail.com'] 11 | spec.description = 'A Danger plugin to lint files through Pronto.' 12 | spec.summary = 'A Danger plugin to lint files through Pronto.' 13 | spec.homepage = 'https://github.com/RestlessThinker/danger-pronto' 14 | spec.license = 'MIT' 15 | 16 | spec.files = `git ls-files`.split($/) 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ['lib'] 20 | 21 | spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0' 22 | 23 | # General ruby development 24 | spec.add_development_dependency 'bundler', '~> 1.3' 25 | spec.add_development_dependency 'rake', '~> 10.0' 26 | 27 | # Testing support 28 | spec.add_development_dependency 'rspec', '~> 3.4' 29 | 30 | # Linting code and docs 31 | spec.add_development_dependency "rubocop", "~> 0.48.1" 32 | spec.add_development_dependency "yard", "~> 0.9.11" 33 | 34 | # Makes testing easy via `bundle exec guard` 35 | spec.add_development_dependency 'guard', '~> 2.14' 36 | spec.add_development_dependency 'guard-rspec', '~> 4.7' 37 | 38 | # If you want to work on older builds of ruby 39 | spec.add_development_dependency 'listen', '3.0.7' 40 | 41 | # This gives you the chance to run a REPL inside your tests 42 | # via: 43 | # 44 | # require 'pry' 45 | # binding.pry 46 | # 47 | # This will stop test execution and let you inspect the results 48 | spec.add_development_dependency 'pry' 49 | end 50 | --------------------------------------------------------------------------------