From 125859d31a6339dd2444c3658a2396c3ae0f7337 Mon Sep 17 00:00:00 2001 From: Kevin Jalbert Date: Thu, 19 Feb 2015 22:18:31 -0500 Subject: [PATCH] Initial commit -- Prototype for code ownership Basic RubyGem setup. An initial prototype which determines the ownership of a segment of code is present as a git command: `git evolution ` --- .gitignore | 34 ++++++++++++++++++++++++++++ .ruby-version | 1 + Gemfile | 4 ++++ LICENSE | 22 ++++++++++++++++++ README.md | 31 ++++++++++++++++++++++++++ Rakefile | 2 ++ bin/git-evolution | 5 +++++ bin/git_evolution | 5 +++++ git_evolution.gemspec | 23 +++++++++++++++++++ lib/git_evolution.rb | 43 ++++++++++++++++++++++++++++++++++++ lib/git_evolution/version.rb | 3 +++ 11 files changed, 173 insertions(+) create mode 100644 .gitignore create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/git-evolution create mode 100755 bin/git_evolution create mode 100644 git_evolution.gemspec create mode 100644 lib/git_evolution.rb create mode 100644 lib/git_evolution/version.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2c1360 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ccbccc3 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.2.0 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4638b8e --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in git_evolution.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e0aac97 --- /dev/null +++ b/LICENSE @@ -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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..67e2469 --- /dev/null +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..809eb56 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require "bundler/gem_tasks" + diff --git a/bin/git-evolution b/bin/git-evolution new file mode 100755 index 0000000..e929d18 --- /dev/null +++ b/bin/git-evolution @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'git_evolution' + +GitEvolution.new.run(ARGV) diff --git a/bin/git_evolution b/bin/git_evolution new file mode 100755 index 0000000..e929d18 --- /dev/null +++ b/bin/git_evolution @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'git_evolution' + +GitEvolution.new.run(ARGV) diff --git a/git_evolution.gemspec b/git_evolution.gemspec new file mode 100644 index 0000000..416c7c7 --- /dev/null +++ b/git_evolution.gemspec @@ -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 = ['kevin.j.jalbert@gmail.com'] + 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 diff --git a/lib/git_evolution.rb b/lib/git_evolution.rb new file mode 100644 index 0000000..ef3b9be --- /dev/null +++ b/lib/git_evolution.rb @@ -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 diff --git a/lib/git_evolution/version.rb b/lib/git_evolution/version.rb new file mode 100644 index 0000000..4d11ed1 --- /dev/null +++ b/lib/git_evolution/version.rb @@ -0,0 +1,3 @@ +class GitEvolution + VERSION = '0.0.1' +end