lib/utils.rb in continuous4r-0.0.2 vs lib/utils.rb in continuous4r-0.0.3
- old
+ new
@@ -29,11 +29,11 @@
end
# Methode de verification de la presence d'un gem, avec installation au besoin
def self.verify_gem_presence(gem, auto_install, proxy_option)
gem_version = run_command("gem list #{gem}")
- if gem_version.blank?
+ if gem_version.nil? or gem_version.strip.empty?
if auto_install == "true"
puts " Installing #{gem}..."
gem_installed = Utils.run_command("#{"sudo " unless Config::CONFIG['host_os'] =~ /mswin/}gem install #{gem}#{proxy_option}")
if gem_installed.index("installed").nil?
raise " Install for #{gem} failed with command '#{"sudo " unless Config::CONFIG['host_os'] =~ /mswin/}gem install #{gem}#{proxy_option}'\n BUILD FAILED."
@@ -41,7 +41,75 @@
else
raise " You don't seem to have #{gem} installed. You can install it with '#{"sudo " unless Config::CONFIG['host_os'] =~ /mswin/}gem install #{gem}#{proxy_option}'.\n BUILD FAILED."
end
end
+ end
+
+ # Methode qui permet de convertir un pourcentage d'un builder en couleur css/html
+ def self.percent_to_css_style(percent)
+ style = "style='font-weight: bold; color: "
+ if percent >= 90 and percent <= 100
+ style += "#00cc00;'"
+ elsif percent >= 80 and percent < 90
+ style += "yellow;'"
+ elsif percent >= 60 and percent < 80
+ style += "red;'"
+ elsif percent >= 0 and percent < 60
+ style += "red; text-decoration: blink;'"
+ end
+ return style
+ end
+
+ # Méthode qui permet de récupérerle numéro de build courant dans le SCM
+ def self.build_name
+ if File.exist?(".git")
+ return "commit #{Utils.run_command("git log").split(/$/).select{ |l| l =~ /^commit / }.collect { |l| l[8..(l.length-1)] }[0]}"
+ elsif File.exist?(".svn")
+ get_head_log = Utils.run_command("svn log -r HEAD")
+ get_head_log_lines = get_head_log.split(/$/)
+ revision = get_head_log_lines[1].split(/ \| /)[0]
+ revision = revision[2..(revision.length-1)]
+ return "revision #{revision}"
+ end
+ end
+
+ # Méthode qui permet de typer une cellule de table HTML en fonction d'un score flog
+ def self.flog_caracteristics(flog_score)
+ if flog_score >= 0 and flog_score < 11
+ "title='Awesome'"
+ elsif flog_score >= 11 and flog_score < 21
+ "title='Good enough'"
+ elsif flog_score >= 21 and flog_score < 41
+ "style='background-color: #FFFF99; color: black;' title='Might need refactoring'"
+ elsif flog_score >= 41 and flog_score < 61
+ "style='background-color: yellow; color: black;' title='Possible to justify'"
+ elsif flog_score >= 61 and flog_score < 100
+ "style='background-color: orange; color: black;' title='Danger'"
+ elsif flog_score >= 100 and flog_score < 200
+ "style='background-color: red; color: black;' title='Whoop, whoop, whoop'"
+ elsif flog_score > 200
+ "style='background-color: black; color: white;' title='Someone please think of the children'"
+ end
+ end
+
+ # Methode qui permet de convertir un score flog en couleur css/html de titre
+ def self.flog_score_to_css_style(flog_score)
+ style = "style='font-weight: bold; "
+ if flog_score >= 0 and flog_score < 11
+ style += "background-color: #00cc00;' title='Awesome'"
+ elsif flog_score >= 11 and flog_score < 21
+ style += "background-color: #00cc00;' title='Good enough'"
+ elsif flog_score >= 21 and flog_score < 41
+ style += "background-color: #ffff99;' title='Might need refactoring'"
+ elsif flog_score >= 41 and flog_score < 61
+ style += "background-color: yellow;' title='Possible to justify'"
+ elsif flog_score >= 61 and flog_score < 100
+ style += "background-color: orange;' title='Danger'"
+ elsif flog_score >= 100 and flog_score < 200
+ style += "background-color: red;' title='Whoop, whoop, whoop'"
+ elsif flog_score > 200
+ style += "background-color: red; color: black; text-decoration: blink;' title='Someone please think of the children'"
+ end
+ return style
end
end