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 +4 -4
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +1 -1
- data/README.md +13 -8
- data/lib/olde_code_finder/finder.rb +37 -0
- data/lib/olde_code_finder/tasks.rb +7 -10
- data/lib/olde_code_finder/version.rb +1 -1
- data/lib/olde_code_finder.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c120f362e2baec2817818015fc8018335efbffd9
|
4
|
+
data.tar.gz: ea8381dd41766942e9c4eb6404e20e1cc6c0055f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a767acc5f4b4052efe0b0d273de3fdc6b77711917b430d32c3f0c6c95ba54512fde9ed7817461bf735f495729f302b3a755beb09280835385c44923563ec07a
|
7
|
+
data.tar.gz: 6c73c453675c6151bfdea4dc28d9214ed97747b155956e6829b20427564069b8ef96e3c92619963009191cc2cd26636314715ca815c14f6089beefdd8f7cf5d6
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# OldeCodeFinder
|
2
2
|
|
3
|
-
OldeCodeFinder finds files which
|
4
|
-
|
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:
|
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:
|
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:
|
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:
|
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:
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
13
|
-
|
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
|
-
|
13
|
+
OldeCodeFinder::Finder.new(file, args[:pctg]).check_by_date(args[:date_string])
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
data/lib/olde_code_finder.rb
CHANGED
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.
|
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-
|
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
|