Class: CruiseFace::Console::UIBuilder
- Inherits:
-
Object
- Object
- CruiseFace::Console::UIBuilder
- Includes:
- Singleton
- Defined in:
- lib/cruise_face/console.rb
Instance Method Summary collapse
- #build_running(text) ⇒ Object
- #colorize(color, text) ⇒ Object
- #failing_builds(text) ⇒ Object
- #fetch_pipeline_status(pipeline) ⇒ Object
- #green_builds(text) ⇒ Object
- #job_info(jobs) ⇒ Object
- #name_of(job) ⇒ Object
- #spinner ⇒ Object
- #to_string(pipeline_status_xml) ⇒ Object
- #truncate(string, width = 15) ⇒ Object
Instance Method Details
#build_running(text) ⇒ Object
91 92 93 |
# File 'lib/cruise_face/console.rb', line 91 def build_running(text) colorize('0;33m', text) end |
#colorize(color, text) ⇒ Object
100 101 102 |
# File 'lib/cruise_face/console.rb', line 100 def colorize(color, text) "\e[#{color}#{text}\e[0m" end |
#failing_builds(text) ⇒ Object
94 95 96 |
# File 'lib/cruise_face/console.rb', line 94 def failing_builds(text) colorize('1;31m', text) end |
#fetch_pipeline_status(pipeline) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cruise_face/console.rb', line 9 def fetch_pipeline_status(pipeline) xm = Builder::XmlMarkup.new xm.instruct! xm.pipeline(:name => pipeline) do xm.stages(:type => 'array') do CruiseFace.get(pipeline).stages.each do |stage| stage.to_xml(xm) end end end rescue => e xm = Builder::XmlMarkup.new xm.instruct! xm.errors(:pipeline_name => pipeline) { xm.error(e.) } end |
#green_builds(text) ⇒ Object
97 98 99 |
# File 'lib/cruise_face/console.rb', line 97 def green_builds(text) colorize('0;32m', text) end |
#job_info(jobs) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/cruise_face/console.rb', line 69 def job_info(jobs) return name_of(jobs.first) if jobs.size == 1 return "#{jobs.size} jobs" unless Console.show_details return 0 if jobs.empty? jobs.collect{|j| name_of(j)}.join(", ") end |
#name_of(job) ⇒ Object
76 77 78 |
# File 'lib/cruise_face/console.rb', line 76 def name_of(job) job.respond_to?(:name) ? job.name : job end |
#spinner ⇒ Object
88 89 90 |
# File 'lib/cruise_face/console.rb', line 88 def spinner colorize('5;33m', '*') end |
#to_string(pipeline_status_xml) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cruise_face/console.rb', line 25 def to_string(pipeline_status_xml) if errors = Hash.from_xml(pipeline_status_xml)['errors'] return "Could not fetch pipeline #{errors['pipeline_name']} status, got error: #{errors['error']}\n" end pipeline = Resource.new(ActiveResource::Formats[:xml].decode(pipeline_status_xml)) status = "#{pipeline.name}:\n" pipeline.stages.each do |stage| status << " " if stage.building_jobs.blank? stage_info = "#{truncate(stage.name)}: [#{stage.latest.committers.collect(&:name).join(', ')}]" if stage.latest.failed? status << ' ' << failing_builds(stage_info) else status << ' ' << green_builds(stage_info) end else status << spinner << build_running("#{truncate(stage.name)}: #{job_info(stage.building_jobs)} [#{stage.latest.committers.collect(&:name).join(', ')}]") end unless stage.failing_jobs.blank? committers = stage.failing_jobs.collect(&:committers).flatten.collect(&:name).uniq.join(", ") status << ', ' if stage.building_jobs.empty? status << failing_builds("#{job_info(stage.failing_jobs)} [#{committers}]") else building_failed_jobs = stage.building_jobs.collect(&:name) & stage.failing_jobs.collect(&:name) status << failing_builds(job_info(stage.failing_jobs)) status << build_running("(#{job_info(building_failed_jobs)})") status << failing_builds(" [#{committers}]") end end status << "\n" end status rescue => e status = "Unexpected error: #{e.}" << "\n" status << e.backtrace.join("\n") << "\n" status << "\n" status << "pipeline status xml:\n" status << pipeline_status_xml << "\n" status end |
#truncate(string, width = 15) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/cruise_face/console.rb', line 80 def truncate(string, width=15) if string.length <= width string else string[0, width-3] + "..." end end |