olde_code_finder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 024cfb48a1a1c3d945b162387c8ddc55047361e1
4
- data.tar.gz: 3a42572139ec44e254c1f61adcadd1b9f9fe17ee
3
+ metadata.gz: c120f362e2baec2817818015fc8018335efbffd9
4
+ data.tar.gz: ea8381dd41766942e9c4eb6404e20e1cc6c0055f
5
5
  SHA512:
6
- metadata.gz: 76cb36fb48b903b9e6be35477650a4f9fb523294e42f3a1d9b0d4206b14de626e5351a033a174ae9aeadc793fcd1804fbbedc3583129f59c4bc54a1ffbd41376
7
- data.tar.gz: 5a136df3f5b3a37728b7668437559f1514907d76071c671be54cd11807c1b345c4a1a7ea48ade7f6e9eb00b7eef2e7be8c59f7e862a03ffef35568b4fbeae193
6
+ metadata.gz: 8a767acc5f4b4052efe0b0d273de3fdc6b77711917b430d32c3f0c6c95ba54512fde9ed7817461bf735f495729f302b3a755beb09280835385c44923563ec07a
7
+ data.tar.gz: 6c73c453675c6151bfdea4dc28d9214ed97747b155956e6829b20427564069b8ef96e3c92619963009191cc2cd26636314715ca815c14f6089beefdd8f7cf5d6
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
- ??, 2014: 0.0.1
1
+ Sep 20, 2014: 0.0.2
2
+ New task to support find old code by date, not by authors - thanks to Jonathan Rochkind for the idea!
3
+
4
+ Sep 17, 2014: 0.0.1
2
5
  Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- olde_code_finder (0.0.1)
4
+ olde_code_finder (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # OldeCodeFinder
2
2
 
3
- OldeCodeFinder finds files which were mostly written by a particular person. So if Fred left the company 3 years ago,
4
- files which consist mostly of lines which were written by him made be worth revisiting.
3
+ OldeCodeFinder finds old code. This means files which are largely older than a specific date.
4
+
5
+ It can also find files which were mostly written by a particular person. So if Fred left the company 3 years ago, files which consist mostly of lines which were written by him may be worth revisiting.
5
6
 
6
7
  ## Installation
7
8
 
@@ -25,28 +26,32 @@ Or install it yourself as:
25
26
 
26
27
  See if more than 80% of `app/models/foo.rb` was written by Benjamin Franklin:
27
28
 
28
- bundle exec rake olde_code_finder:find['app/models/foo.rb','Benjamin Franklin','80']
29
+ bundle exec rake olde_code_finder:find_by_author['app/models/foo.rb','Benjamin Franklin','80']
29
30
 
30
31
  Or you can use a glob:
31
32
 
32
- bundle exec rake olde_code_finder:find['app/models/*.rb','Benjamin Franklin','80']
33
+ bundle exec rake olde_code_finder:find_by_author['app/models/*.rb','Benjamin Franklin','80']
33
34
 
34
35
  Or you can specify a lower percentage threshold:
35
36
 
36
- bundle exec rake olde_code_finder:find['app/models/*.rb','Benjamin Franklin','60']
37
+ bundle exec rake olde_code_finder:find_by_author['app/models/*.rb','Benjamin Franklin','60']
37
38
 
38
39
  The author name is a regex, so this will find 'Benjamin Franklin' as well as 'Ben Franklin':
39
40
 
40
- bundle exec rake olde_code_finder:find['app/models/*.rb','Frank','80']
41
+ bundle exec rake olde_code_finder:find_by_author['app/models/*.rb','Frank','80']
42
+
43
+ Or you can run a different task and find code older than a certain date instead:
44
+
45
+ bundle exec rake olde_code_finder:find_by_date['app/models/*.rb','4 years','80']
41
46
 
42
47
  The output will be a list of files that meet the criteria:
43
48
 
44
- foo> $ bundle exec rake olde_code_finder:find['app/models/*.rb','Benjamin Franklin','80']
49
+ foo> $ bundle exec rake olde_code_finder:find_by_author['app/models/*.rb','Benjamin Franklin','80']
45
50
  More than 80% of app/models/foobar.rb was written by Benjamin Franklin
46
51
 
47
52
  ## How does it work?
48
53
 
49
- It uses `git blame` to see who last touched each line of a file.
54
+ It uses `git blame` to see who last touched each line of a file and when.
50
55
 
51
56
  ## Contributing
52
57
 
@@ -0,0 +1,37 @@
1
+ require 'date'
2
+
3
+ module OldeCodeFinder
4
+ class Finder
5
+
6
+ attr_accessor :file, :pctg
7
+
8
+ def initialize(file, pctg)
9
+ @file = file
10
+ @pctg = pctg
11
+ end
12
+
13
+ def check_by_author(author)
14
+ total_lines = git_blame_output.size
15
+ author_lines = git_blame_output.grep(/#{author}/).size
16
+ if (author_lines / total_lines.to_f) > (pctg.to_f / 100.0)
17
+ puts "More than #{pctg}% of #{file} was written by #{author}"
18
+ end
19
+ end
20
+
21
+ def check_by_date(date_string)
22
+ years_ago = date_string.match(/^(\d+)/)[1].to_i
23
+ date_threshold = (Date.today - (years_ago*365))
24
+ total_lines = git_blame_output.size
25
+ older_lines = git_blame_output.select {|line| Date.strptime(line.match(/.*(\d{4}-\d{2}-\d{2})/)[1]) < date_threshold }.size
26
+ if (older_lines / total_lines.to_f) > (pctg.to_f / 100.0)
27
+ puts "More than #{pctg}% of #{file} was written more than #{years_ago} years ago"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def git_blame_output
34
+ @git_blame_output ||= `git blame --date=short #{file}`.split("\n")
35
+ end
36
+ end
37
+ end
@@ -1,19 +1,16 @@
1
1
  namespace :olde_code_finder do
2
2
 
3
- def checkit(file, author, pctg)
4
- blame_output = `git blame #{file}`.split("\n")
5
- total_lines = blame_output.size
6
- author_lines = blame_output.grep(/#{author}/).size
7
- if (author_lines / total_lines.to_f) > (pctg.to_f / 100.0)
8
- puts "More than #{pctg}% of #{file} was written by #{author}"
3
+ desc "Find code that's mostly by a particular person"
4
+ task :find_by_author, [:glob, :author, :pctg] => :environment do |task, args|
5
+ Dir[args[:glob]].each do |file|
6
+ OldeCodeFinder::Finder.new(file, args[:pctg]).check_by_author(args[:author])
9
7
  end
10
8
  end
11
9
 
12
- # e.g., bundle exec rake olde_code_finder:find['app/models/partner*','Ben Franklin','80']
13
- desc "Find old code by a particular person"
14
- task :find, [:glob, :author, :pctg] => :environment do |task, args|
10
+ desc "Find code older than a particular date"
11
+ task :find_by_date, [:glob, :date_string, :pctg] => :environment do |task, args|
15
12
  Dir[args[:glob]].each do |file|
16
- checkit(file, args[:author], args[:pctg])
13
+ OldeCodeFinder::Finder.new(file, args[:pctg]).check_by_date(args[:date_string])
17
14
  end
18
15
  end
19
16
  end
@@ -1,3 +1,3 @@
1
1
  module OldeCodeFinder
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,2 +1,3 @@
1
1
  require 'olde_code_finder/version'
2
- require 'olde_code_finder/tasks'
2
+ require 'olde_code_finder/tasks'
3
+ require 'olde_code_finder/finder'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: olde_code_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Copeland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,6 +53,7 @@ files:
53
53
  - README.md
54
54
  - Rakefile
55
55
  - lib/olde_code_finder.rb
56
+ - lib/olde_code_finder/finder.rb
56
57
  - lib/olde_code_finder/tasks.rb
57
58
  - lib/olde_code_finder/version.rb
58
59
  - olde_code_finder.gemspec