Last active
March 23, 2016 09:39
-
-
Save theist/614debff943408e52d9a to your computer and use it in GitHub Desktop.
CirclCI build list (not so tested)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require "colorize" | |
| require "net/http" | |
| require "json" | |
| require "httparty" | |
| token = '*****************************' # your API token here | |
| class Build | |
| attr_accessor :status, :subject, :reponame, :lifecycle, :failed, :canceled, :branch, :build_num, :author_name, :build_time_millis | |
| def initialize(jeison) | |
| %w(status subject reponame lifecycle failed canceled branch build_num author_name build_time_millis).each do |data| | |
| self.send((data+"=").to_sym, jeison[data]) | |
| end | |
| end | |
| def build_time_ms() | |
| return "%d:%02d" % (@build_time_millis/1000).divmod(60) if @build_time_millis | |
| return "-:--" | |
| end | |
| def okko() | |
| if @status == "failed" | |
| return "KO".red | |
| elsif @status == "success" | |
| return "OK".green | |
| else | |
| return "--".yellow | |
| end | |
| end | |
| end | |
| request = HTTParty.get "https://circleci.com/api/v1/recent-builds?circle-token=#{token}&limit=20" | |
| JSON.parse(request).reverse.each do |build| | |
| b = Build.new(build) | |
| puts "build(%s) %20s %-37s by %-34s %s %s" % [b.okko(),"##{b.build_num}".green , "%.12s:%.24s" %[b.reponame, b.branch], | |
| (b.author_name[0,20]).yellow, b.lifecycle.red, b.build_time_ms()] | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment