canvas-lms/script/tatl_tael

106 lines
3.4 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "../gems/tatl_tael/lib/tatl_tael"
require 'yaml'
unless ENV['GERRIT_PATCHSET_REVISION']
require 'colorize'
end
def pretty_comment(severity, message)
result = ""
result += "[#{severity}]".colorize(:yellow)
result += " => #{message.colorize(:green)}"
puts result
end
def post(message)
if ENV['GERRIT_PATCHSET_REVISION']
label = ENV['GERGICH_REVIEW_LABEL'] || "Lint-Review"
`gergich message "#{message}"`
`gergich label "#{label}" -1`
else
pretty_comment("error", message)
end
end
plugin = ENV['GERRIT_PROJECT']
plugin = nil if plugin == 'canvas-lms'
git_dir = "gems/plugins/#{plugin}/" if plugin
if git_dir && !Dir.exist?(git_dir)
puts "No plugin #{plugin} found"
exit 0
end
linter = TatlTael::Linter.new(git_dir: git_dir)
# don't run for wips
if linter.wip?
puts "WIP detected, TatlTael will not run."
exit 0
end
user_config_file = File.expand_path("../../gems/dr_diff/config/gergich_user_config.yml", __FILE__)
if File.exists?(user_config_file)
config = YAML.load_file(user_config_file) || {}
user_list = config['only_report_errors'] || []
exit 0 if user_list.include?(ENV['GERRIT_EVENT_ACCOUNT_EMAIL'])
end
errors = []
linter.ban_new_erb do
errors << "Your commit includes new ERB files,"\
" which has been a no-no in Canvas since 2011."\
" All new UI should be built in React on top of documented APIs.\n"\
"Maybe try doing something like this in your controller instead:\n\n"\
" @page_title = t('Your Page Title')\n"\
" @body_classes << 'whatever-classes you-want-to-add-to-body'\n"\
" js_bundle :your_js_bundle\n"\
" css_bundle :any_css_bundles_you_want\n"\
" js_env({whatever: 'you need to put in window.ENV'})\n"\
" render :text => \"\".html_safe, :layout => true"\
end
linter.ensure_public_js_specs do
errors << "Your commit includes changes to public/javascripts,"\
" but does not include specs (coffee or jsx)."\
" Please add some to verify your changes."\
" Even $.fn.crazyMethods can and should be tested"\
" (and not via selenium)."
end
linter.ensure_coffee_specs do
errors << "Your commit includes coffee changes,"\
" but does not include coffee or jsx specs."\
" Please add some to verify your changes."
end
linter.ensure_jsx_specs do
errors << "Your commit includes jsx changes,"\
" but does not include jsx specs."\
" Please add some to verify your changes."\
" See /doc/testing_javascript.md for help."
end
linter.ensure_ruby_specs do
if linter.selenium_specs?
errors << "Your commit includes ruby changes,"\
" but does not include ruby specs."\
" Please add some to verify your changes."
else
errors << "Your commit includes ruby changes,"\
" but does not include non-selenium specs (model, controller, etc)."\
" Please add some to verify your changes."
end
end
linter.ensure_no_unnecessary_selenium_specs do
errors << "Your commit modifies selenium specs,"\
" when your changes might be more appropriately"\
" tested at a lower level (see above)."\
" Please limit your selenium specs to happy-path scenarios."
end
unless errors.empty?
post(errors.join("\n\n"))
end