Sha256: ec40ab8dfbe6ea268b250de191ccbf97ac62e1aba7e985e3144332cb90bfe172
Contents?: true
Size: 1.49 KB
Versions: 4
Compression:
Stored size: 1.49 KB
Contents
#!/usr/bin/env ruby require 'rubygems' gem 'instrumental_agent' require 'instrumental_agent' token = ENV["INSTRUMENTAL_TOKEN"] || ARGV[0] if !token puts 'Usage: gitstrumental API_KEY' exit 1 end lines = `git log --format="REC %at %h '%cn'" --numstat`.chomp.split(/\n+/).reject(&:empty?) branch = File.basename(`git symbolic-ref HEAD`.chomp).gsub(/[^a-z0-9]/i, "_") if fetch_url = `git remote show origin`.chomp.split(/\n+/).grep(/Fetch URL:/).first repo = File.basename(fetch_url.split("/").last, ".git") else repo = File.basename(Dir.pwd, ".git") end prolog = [repo, branch].join(".") I = Instrumental::Agent.new(token) curstat = {} lines.each do |line| if line =~ /^REC/ if !curstat.empty? name, ts, changes = curstat[:name], curstat[:timestamp], curstat[:changes] I.increment("git.#{prolog}.commits.#{name}", 1, ts) adds, deletes = changes.reduce do |prev, pair| [prev[0] + pair[0], prev[1] + pair[1]] end I.increment("git.#{prolog}.commits.#{name}.add", adds, ts) I.increment("git.#{prolog}.commits.#{name}.delete", deletes, ts) I.increment("git.#{prolog}.num_commits", 1, ts) end rec, ts, hash, *name_parts = line.split(" ") name = name_parts.join(" ").gsub(/^'([^']+)'$/, "\\1").gsub(/[^a-z0-9]/i, "_") curstat = { :name => name, :timestamp => ts.to_i, :hash => hash, :changes => [] } else adds, deletes, file = line.split(/\s+/) curstat[:changes] << [ adds.to_i, deletes.to_i ] end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
instrumental_tools-0.5.3 | bin/gitstrumental |
instrumental_tools-0.5.2 | bin/gitstrumental |
instrumental_tools-0.5.1 | bin/gitstrumental |
instrumental_tools-0.5.0 | bin/gitstrumental |