Skip to content

Commit

Permalink
Initial commit -- Prototype for code ownership
Browse files Browse the repository at this point in the history
Basic RubyGem setup.

An initial prototype which determines the ownership of a segment of code
is present as a git command:

`git evolution <start_line> <end_line> <file_name>`
  • Loading branch information
kevinjalbert committed Feb 20, 2015
0 parents commit 125859d
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
/tmp/

## Specific to RubyMotion:
.dat*
.repl_history
build/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalisation:
/.bundle/
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.0
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in git_evolution.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Kevin Jalbert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# GitEvolution

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'git_evolution'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install git_evolution

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it ( https://github.com/kevinjalbert/git_evolution/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"

5 changes: 5 additions & 0 deletions bin/git-evolution
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'git_evolution'

GitEvolution.new.run(ARGV)
5 changes: 5 additions & 0 deletions bin/git_evolution
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'git_evolution'

GitEvolution.new.run(ARGV)
23 changes: 23 additions & 0 deletions git_evolution.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'git_evolution/version'

Gem::Specification.new do |spec|
spec.name = 'git_evolution'
spec.version = GitEvolution::VERSION
spec.authors = ['Kevin Jalbert']
spec.email = ['[email protected]']
spec.summary = 'Gem that provides the ability to determine the evolution of code within a git repository'
spec.description = 'Gem that provides the ability to determine the evolution of code within a git repository'
spec.homepage = ''
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
end
43 changes: 43 additions & 0 deletions lib/git_evolution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class GitEvolution
def run(args)
start_line = args[0]
end_line = args[1]
file = args[2]

results = `git --no-pager log -L#{start_line},#{end_line}:#{file} --follow #{file}`

commit_shas = results.scan(/^commit ([0-9a-f]{40})/)
commit_shas = commit_shas.flatten

commit_info = {}
commit_shas.each do |sha|
commit = `git --no-pager show -s --format=%an%n%n%at%n%n%s%n%n%b #{sha}`
commit_data = commit.split("\n\n")
commit_info[sha] = {
author: commit_data[0],
date: commit_data[1],
title: commit_data[2],
body: commit_data[3..-1].join
}
end

ownership = Hash.new(0)

puts 'Commits:'
commit_info.each do |sha, data|
puts "#{data[:author]} (#{Time.at(data[:date].to_i)}) - #{sha}"
puts "#{data[:title]}"
puts

ownership[data[:author]] = ownership[data[:author]] + 1
end

puts '-' * 80

puts
puts 'Ownership:'
ownership.each do |author, count|
puts "#{author} - #{count}/#{commit_info.size} (#{(count.to_f / commit_info.size * 100).round(2)}%)"
end
end
end
3 changes: 3 additions & 0 deletions lib/git_evolution/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class GitEvolution
VERSION = '0.0.1'
end

0 comments on commit 125859d

Please sign in to comment.