Skip to content

Instantly share code, notes, and snippets.

@oieioi
Forked from necojackarc/search_commit_msg
Last active October 7, 2016 09:25
Show Gist options
  • Save oieioi/16ecb07dd27f69ab85fd to your computer and use it in GitHub Desktop.
Save oieioi/16ecb07dd27f69ab85fd to your computer and use it in GitHub Desktop.
Getting commit massage samples script powered by http://commit-m.minamijoyo.com/
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "nokogiri"
params = { keyword: ARGV.join("\s") }
uri = URI.parse("http://commit-m.minamijoyo.com/commits/search")
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri)
html = Nokogiri::HTML.parse(response)
puts number_result = html.css(".container").inner_text[/[0-9]+ results/]
puts html.css("tbody > tr").map { |e|
message = e.css('td').first.inner_text.strip
meta = "#{e.css('td:nth-child(2)').inner_text}"
commit_url = "#{e.css('td:nth-child(3) a').first.attribute('href')}"
# 検索ワードに色付ける
params[:keyword].
split("\s").
each { |key| message.gsub!(/(#{key})/i, "\e[33m\\1\e[0m") }
"#{message} \e[36m(#{meta})\e[0m #{commit_url}"
}.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment