Skip to content
Browse files

use travis everywhere

  • Loading branch information...
1 parent cbc5e69 commit bb56d56111e36a7714c8eadbf99a3fdb46e53e35 Tim Labeeuw committed
Showing with 97 additions and 87 deletions.
  1. +0 −78 check_travis
  2. +88 −0 check_travis.rb
  3. +1 −1 outdated
  4. +7 −7 staged_shortlog
  5. +1 −1 update_sub
View
78 check_travis
@@ -1,78 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'net/http'
-require 'json'
-
-class TravisBuild
- TRAVIS_URL = "https://api.travis-ci.org/repos/%s/builds".freeze
- YELLOW = "\e[0;33m".freeze
- GREEN = "\e[0;32m".freeze
- RED = "\e[0;31m".freeze
- BLUE = "\e[0;34m".freeze
- RESET_COLOR = "\e[0m".freeze
-
- def initialize(git_short_log)
- @git_short_log = git_short_log
- @repo = `git remote -v`.match(/github.com[\/:]([^\s]+?).git/)[1]
- end
-
- def shortlog_with_travis_status
- output = []
-
- if travis?
- output << "#{YELLOW}https://travis-ci.org/#{@repo}#{RESET_COLOR}\n"
- else
- output << "#{BLUE}No Travis#{RESET_COLOR}\n"
- end
-
- @git_short_log.split("\n").each do |commit|
- sha, message = commit.split(" ", 2)
-
- output << "#{YELLOW}#{sha}#{RESET_COLOR} #{message}"
- output << travis_status(sha) if travis?
- output << "\n"
- end
-
- puts output.join if output.any?
- end
-
- private
-
- def json
- @json ||= begin
- uri = URI(TRAVIS_URL % @repo)
-
- http = Net::HTTP.new(uri.host, uri.port)
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- response = http.request(Net::HTTP::Get.new(uri.path))
-
- JSON.parse(response.body)
- end
- end
-
- def travis?
- @travis ||= json && json.any?
- end
-
- def travis_status(sha)
- build = json.find { |build| build["commit"].start_with?(sha) }
-
- message = case build && build["result"]
- when 0; "#{GREEN}Travis Success: #{build_url(build)}"
- when 1; "#{RED}Travis Failed: #{build_url(build)}"
- else; "#{BLUE}Travis #{build ? "#{build["state"]}: #{build_url(build)}" : "Unknown"}"
- end
-
- " ( #{message} #{RESET_COLOR})"
- end
-
- def build_url(build)
- "https://travis-ci.org/#{@repo}/builds/#{build["id"]}"
- end
-end
-
-if __FILE__ == $PROGRAM_NAME
- travis = TravisBuild.new(ARGF.read)
- travis.shortlog_with_travis_status
-end
View
88 check_travis.rb
@@ -0,0 +1,88 @@
+#!/usr/bin/env ruby
+
+require 'net/http'
+require 'json'
+require 'optparse'
+
+class String
+ COLORS = { yellow: "\e[0;33m", green: "\e[0;32m", red: "\e[0;31m", blue: "\e[0;34m", reset: "\e[0m" }.freeze
+
+ def self.color=(color); @color = color; end
+ def self.color?; !!@color; end
+
+ def color(color)
+ String.color? ? "#{COLORS[color]}#{self}#{COLORS[:reset]}" : self
+ end
+end
+
+class TravisBuild
+ TRAVIS_URL = "https://api.travis-ci.org/repos/%s/builds".freeze
+
+ def initialize(shas, color = true)
+ @shas = shas
+ @repo = `git remote -v`.match(/github.com[\/:]([^\s]+?).git/)[1]
+ String.color = color
+ end
+
+ def log_with_travis_status
+ output = [travis? ? "https://travis-ci.org/#{@repo}".color(:yellow) : "No Travis".color(:blue)]
+
+ `git log #{@shas} --oneline`.split("\n").each do |commit|
+ sha, message = commit.split(" ", 2)
+ output << "\n#{sha.color(:yellow)} #{message}#{travis_status(sha) if travis?}"
+ end
+
+ puts output.join
+ end
+
+ def log_sorted_by_author_with_travis_status
+ output = ["Bump #{@repo}:\n".color(:blue)]
+
+ commits_by_author = Hash.new("")
+ `git log #{@shas} --pretty=format:'%h %an: %s'`.split("\n").each do |commit|
+ sha, message = commit.split(" ", 2)
+ author, message = message.split(":", 2)
+ commits_by_author[author] += "\n #{message}#{travis_status(sha) if travis?}"
+ end
+
+ commits_by_author.each { |author, commit| output << " #{author.color(:yellow)}:#{commit}\n" }
+ puts output.join
+ end
+
+ private
+
+ def travis_json
+ @travis_json ||= begin
+ uri = URI(TRAVIS_URL % @repo)
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ JSON.parse(http.request(Net::HTTP::Get.new(uri.path)).body)
+ end
+ end
+
+ def travis?
+ @travis ||= travis_json && travis_json.any?
+ end
+
+ def travis_status(sha)
+ build = travis_json.find { |build| build["commit"].start_with?(sha) }
+
+ message = case build && build["result"]
+ when 0; "Travis Success: #{build_url(build)}".color(:green)
+ when 1; "Travis Failed: #{build_url(build)}".color(:red)
+ else; "Travis #{build ? "#{build["state"]}: #{build_url(build)}" : "Unknown"}".color(:blue)
+ end
+
+ " ( #{message} )"
+ end
+
+ def build_url(build)
+ "https://travis-ci.org/#{@repo}/builds/#{build["id"]}"
+ end
+end
+
+if __FILE__ == $PROGRAM_NAME
+ travis = TravisBuild.new(ARGV[0], true)
+ travis.log_with_travis_status
+end
View
2 outdated
@@ -4,7 +4,7 @@ export base=`pwd`
git submodule foreach ' \
git fetch origin master &> /dev/null && # make sure we are up-to-date \
- GIT_PAGER= git log head...FETCH_HEAD --oneline | $base/check_travis && # new \
+ GIT_PAGER= $base/check_travis.rb head...FETCH_HEAD && # new \
(git log head -1 --oneline | sed "s/^/-> /") && # current \
(git log head --skip=1 -2 --oneline | sed "s/^/ /") && # 2 commits before current \
echo \
View
14 staged_shortlog
@@ -1,13 +1,13 @@
#!/usr/bin/env ruby
-
+require_relative 'check_travis.rb'
diffs = `git diff --cached`.split('diff --git').select { |log| log =~ /Subproject/ }
-shortlogs = diffs.map do |diff|
+diffs.each do |diff|
/a\/(?<loc>.+?)\sb.*index\s(?<shas>\S+)/m.match diff do |matches|
- shortlog = "Bump #{matches[:loc]}:\n\n"
- shortlog += `cd #{matches[:loc]} && git shortlog #{matches[:shas]}`
+ Dir.chdir(matches[:loc]) do
+ travis = TravisBuild.new(matches[:shas], ARGV[0] == "-c")
+ travis.log_sorted_by_author_with_travis_status
+ end
end
-end.compact.join("\n")
-
-puts shortlogs
+end
View
2 update_sub
@@ -15,4 +15,4 @@ git submodule foreach \
' git add $sub;' \
'fi'
-./staged_shortlog
+./staged_shortlog -c

0 comments on commit bb56d56

Please sign in to comment.
Something went wrong with that request. Please try again.