Skip to content

Commit

Permalink
KBP-138 #time 20m - fixed conflict and fix rubocop error
Browse files Browse the repository at this point in the history
  • Loading branch information
FatihAvsan committed Nov 21, 2017
2 parents a5ae640 + e97d883 commit fd1f038
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cybele.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Gem::Specification.new do |spec|

spec.add_dependency 'bundler', '~> 1.5'
spec.add_runtime_dependency 'rails', '~> 5.0', Cybele::RAILS_VERSION
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'pronto', '~> 0.9.5'
spec.add_development_dependency 'pronto-flay', '~> 0.9.0'
spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0'
spec.add_development_dependency 'rspec', '~> 3.5'

spec.extra_rdoc_files = %w[README.md MIT-LICENSE]
end
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
require 'cybele/helpers/devise'
require 'cybele/helpers/docker'
require 'cybele/helpers/error_pages'
require 'cybele/helpers/pronto'
require 'cybele/app_builder'
1 change: 1 addition & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::Devise
include Cybele::Helpers::ErrorPages
include Cybele::Helpers::Docker
include Cybele::Helpers::Pronto

def readme
template 'README.md.erb',
Expand Down
6 changes: 6 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def initialize(*args)
def customize_gemfile
say 'Customize gem file', :green
build :add_gems
bundle_command 'update thor'
build :add_simple_form_gem unless @options[:skip_simple_form]
build :add_show_for_gem unless @options[:skip_show_for]
build :add_haml_gems unless @options[:skip_haml]
Expand Down Expand Up @@ -236,6 +237,11 @@ def docker_development_env
build :setup_docker_development_env
end

def setup_pronto_config
say 'Setup pronto config', :green
build :configure_pronto
end

def goodbye
say 'Congratulations! That\'s all...', :green
end
Expand Down
27 changes: 27 additions & 0 deletions lib/cybele/helpers/pronto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Pronto
def configure_pronto
# Create pronto files
template 'pronto/example.pronto.yml.erb',
'example.pronto.yml',
force: true
template 'pronto/example.pronto.yml.erb',
'.pronto.yml',
force: true
template 'pronto/.rubocop.yml.erb',
'.rubocop.yml',
force: true
template 'pronto/rubo.erb',
'bin/rubo',
force: true
run 'chmod +x bin/rubo'

# Ignore secret information file
append_file('.gitignore', '.pronto.yml')
end
end
end
end
4 changes: 4 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,8 @@
env_production_file = content('.env.production')
expect(env_production_file).to match('REDISTOGO_URL=')
end

it 'uses pronto' do
pronto_test
end
end
4 changes: 4 additions & 0 deletions spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,8 @@
env_production_file = content('.env.production')
expect(env_production_file).not_to match('REDISTOGO_URL=')
end

it 'uses pronto' do
pronto_test
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
config.include GitIgnoreTestHelper
config.include MailTestHelpers
config.include ForceSSLTestHelper
config.include ProntoTestHelpers

config.before(:all) do
create_tmp_directory
Expand Down
9 changes: 9 additions & 0 deletions spec/support/force_ssl_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

module ForceSSLTestHelper
def force_ssl
ssl_test
environment_test
end

private

def ssl_test
config_staging_file = content('config/environments/staging.rb')
expect(config_staging_file).to match('config.force_ssl')

config_production_file = content('config/environments/staging.rb')
expect(config_production_file).to match('config.force_ssl')
end

def environment_test
env_staging_file = content('.env.staging')
expect(env_staging_file).to match('RAILS_FORCE_SSL=')

Expand Down
30 changes: 30 additions & 0 deletions spec/support/pronto_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module ProntoTestHelpers
def pronto_test
file_exist_test
file_content_test
gitignore_test
end

private

def file_exist_test
gemfile_file = content('Gemfile')
expect(gemfile_file).to match("gem 'pronto'")
expect(gemfile_file).to match("gem 'pronto-flay'")
expect(gemfile_file).to match("gem 'pronto-rubocop'")
end

def file_content_test # rubocop:disable Metrics/AbcSize
expect(File).to exist(file_project_path('example.pronto.yml'))
expect(File).to exist(file_project_path('.pronto.yml'))
expect(File).to exist(file_project_path('.rubocop.yml'))
expect(File).to exist(file_project_path('bin/rubo'))
end

def gitignore_test
gemfile_file = content('.gitignore')
expect(gemfile_file).to match('.pronto.yml')
end
end
6 changes: 6 additions & 0 deletions templates/Gemfile.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# General requirement
gem 'thor', '~> 0.19.4'

# For never accidentally send emails to real people from staging environment.
gem 'recipient_interceptor', '~> 0.1.2'

Expand Down Expand Up @@ -28,6 +31,9 @@ group :development, :test do
gem 'better_errors', '~> 2.4'
gem 'bullet', '~> 5.6', '>= 5.6.1'
gem 'letter_opener', '~> 1.4', '>= 1.4.1'
gem 'pronto', '~> 0.9.5'
gem 'pronto-flay', '~> 0.9.0', require: false
gem 'pronto-rubocop', '~> 0.9.0', require: false
end

# A set of common locale data and translations to internationalize and/or localize your Rails applications.
Expand Down
35 changes: 35 additions & 0 deletions templates/pronto/.rubocop.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
AllCops:
Includes:
- 'Rakefile'
- 'config.ru'
- 'Gemfile'
Excludes:
- Guardfile
- bin/**
- db/**/**
- spec/**/**/**/**
- test/**/**/**/**
- tmp/**/**/**/**

Documentation:
Enabled: false

Metrics/LineLength:
Max: 100
Exclude:
- 'Gemfile'

Metrics/MethodLength:
CountComments: false
Max: 15

Metrics/BlockLength:
CountComments: false
Max: 40
Exclude:
- 'Rakefile'
- '**/*.rake'
- 'spec/**/*.rb'

Style/FrozenStringLiteralComment:
EnforcedStyle: when_needed
27 changes: 27 additions & 0 deletions templates/pronto/example.pronto.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
all:
exclude:
- 'spec/**/*'
bitbucket:
slug: 'lab2023corp/<%= app_name%>'
username: 'username'
password: 'password'
max_warnings: 50
verbose: true

## for local changes before the commit
# before git add .
# pronto run --unstaged
# after git add .
# pronto run --staged

## for branch commits analyze different between develop
# pronto run
# pronto run -c origin/develop

## for pull request
# pronto run -f bitbucket_pr
# pronto run -f bitbucket_pr -c origin/develop

## for commit
# pronto run -f bitbucket
# pronto run -f bitbucket -c origin/develop
24 changes: 24 additions & 0 deletions templates/pronto/rubo.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'English'
require 'rubocop'

DISABLE_DIRECTORY = %w[db].freeze
ADDED_OR_MODIFIED = /A|AM|^M/

changed_files = `git status --porcelain`.split(/\n/).select do |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
end
changed_files = changed_files.map do |file_name_with_status|
file_name_with_status.split(' ')[1]
end
changed_files = changed_files.select do |file_name|
directory = file_name.split('/')[0]
!DISABLE_DIRECTORY.include?(directory) && File.extname(file_name) == '.rb'
end
changed_files = changed_files.join(' ')

system("rubocop #{changed_files}") unless changed_files.empty?

exit $CHILD_STATUS.to_s[-1].to_i

0 comments on commit fd1f038

Please sign in to comment.