lib/capistrano/ghostinspector.rb in capistrano-ghostinspector-0.4.0 vs lib/capistrano/ghostinspector.rb in capistrano-ghostinspector-1.0.0

- old
+ new

@@ -6,11 +6,10 @@ module Capistrano module Ghostinspector def self.load_into(config) config.load do - after "deploy", "ghostinspector:setup" after "ghostinspector:setup", "ghostinspector:run" gi_config = YAML::load(File.read("gi_config.yaml")) namespace :ghostinspector do @@ -39,10 +38,18 @@ set :jira_project_code, gi_config["jira_project_code"] else set :jira_project_code, "GHOST" end + if gi_config.has_key?("ga_enabled") + set :ga_enabled, fetch(:ga_enabled, gi_config["ga_enabled"]) + else + set :ga_enabled, fetch(:ga_enabled, false) + end + + set :domain, fetch(:domain, nil) + # Get tests and suites from command line set :gitest, fetch(:gitest, nil) set :gisuite, fetch(:gisuite, nil) # Get any default tests that have been set on the stage @@ -59,11 +66,11 @@ desc "Run Ghost Inspector Tests" task :run, :only => { :primary => true } do if (fetch(:gi_enabled) == true) - giApi = Api.new(fetch(:gi_api_key), fetch(:domain), fetch(:rollback), fetch(:ga_property)) + giApi = Api.new(fetch(:gi_api_key), fetch(:domain), fetch(:rollback), fetch(:ga_enabled)) @collection = Array.new # run each test Capistrano::Ghostinspector.getTests(fetch(:gitest), gi_config["tests"], fetch(:gi_default_test)).each do |test| puts "* * * Running Ghost Inspector Test * * *" @@ -90,56 +97,63 @@ end desc "Send Results to Google Analytics" task :sendGA, :only => { :primary => true } do - puts "* * * Sending Data to Google Analytics * * *" + if (fetch(:gi_enabled) == true && fetch(:ga_enabled) == true && fetch(:domain) != nil) - jira_project_code = fetch(:jira_project_code) + puts "* * * Sending Data to Google Analytics * * *" - log = capture( - "cd #{current_path} && git log #{previous_revision[0,7]}..#{current_revision[0,7]} --format=\"%s\" | grep -oh '#{jira_project_code}-[0-9]\\+' | sort | uniq" - ) + jira_project_code = fetch(:jira_project_code) - options = { - :ga_property => fetch(:ga_property), - :ga_custom_1 => fetch(:ga_custom_1), - :ga_custom_2 => fetch(:ga_custom_2), - :domain => fetch(:domain), - :current_revision => fetch(:current_revision), - :previous_revision => fetch(:previous_revision), - :branch => fetch(:branch, "default"), - :stage => fetch(:stage), - :tickets => Capistrano::Ghostinspector.getTickets(log) - } + log = capture( + "cd #{current_path} && git log #{previous_revision[0,7]}..#{current_revision[0,7]} --format=\"%s\" | grep -oh '#{jira_project_code}-[0-9]\\+' | sort | uniq" + ) - analytics = Analytics.new(options) + options = { + :ga_property => fetch(:ga_property), + :ga_custom_1 => fetch(:ga_custom_1), + :ga_custom_2 => fetch(:ga_custom_2), + :domain => fetch(:domain), + :current_revision => fetch(:current_revision), + :previous_revision => fetch(:previous_revision), + :branch => fetch(:branch, "default"), + :stage => fetch(:stage), + :tickets => Capistrano::Ghostinspector.getTickets(log) + } - @collection.each do |item| - analytics.pushData(item[:type], item[:results]) + analytics = Analytics.new(options) + + @collection.each do |item| + analytics.pushData(item[:type], item[:results]) + end + end end desc "Finalise Ghost Inspector Run" task :finalise_run, :only => { :primary => true } do - set :passing, true - @collection.each do |item| - if item[:passing] == false - set :passing, false + if (fetch(:gi_enabled) == true) + set :passing, true + @collection.each do |item| + if item[:passing] == false + set :passing, false + end end - end - # If any test fails and the stage allows rollbacks then - # rollback to previous version. - if (fetch(:passing) == false && fetch(:rollback) == true) - puts "* * * Ghost Inspector Failed. Rolling back * * *" - run_locally %{cap #{stage} deploy:rollback} - else - puts "* * * Ghost Inspector Complete. Deployment Complete * * *" - end + # If any test fails and the stage allows rollbacks then + # rollback to previous version. + if (fetch(:passing) == false && fetch(:rollback) == true) + puts "* * * Ghost Inspector Failed. Rolling back * * *" + run_locally %{cap #{stage} deploy:rollback} + else + puts "* * * Ghost Inspector Complete. Deployment Complete * * *" + end + end + end end \ No newline at end of file