git-age 0.1.0 → 0.1.3

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
  SHA256:
3
- metadata.gz: 9ee1f171ee1fc257032663614b5b13ccadf62e2181450af785d45b98a5c91e17
4
- data.tar.gz: 5607965e9be16da07a2d3a757cd8372fdf160e5263c897f51868179b6a310ebc
3
+ metadata.gz: 4085ff2fcbb2716f679f72390a9f896892a2623fea3635ae234539471cf154a7
4
+ data.tar.gz: 4666d870907b6aecf5490eb01ddbcb6dfe6957705616ea697d935bc98b2ee6b4
5
5
  SHA512:
6
- metadata.gz: 652a2263c2d1cac464b48fc98caeaaf0eb1af076fa06d14982fb2051f31e402a83e5fe73cb911de1111d868f190905d0dd8999ca02af3eda12345079fc2aea39
7
- data.tar.gz: 9ba360f91613ca3928e02237ac232d9076d9ac92782f638ba85d3a95da7500b81dbc2c849abd62350d097c77f807665a1cae301fb2130d0e17230bc21c34a8ef
6
+ metadata.gz: 7f8636eddb349efa34d91d05cfbf49d165834bf3d22d188bf1160276eb4ff1dfea73761283cac50b49638a158a44582478d09284e626e0843430c6d935489c12
7
+ data.tar.gz: e9c065d66218683e39b6a3b719e8ae95abfd89163d14505f4221fc0856a9749ae5f4409c6f3cc4e0e255c72c5227136fcdf74a0b153277a0f1033c1d4369bfd0
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -21,6 +21,8 @@ Go to your repository and run:
21
21
 
22
22
  ```
23
23
  Usage: git-age [options]
24
+ -b, --branch=BRANCH Git branch
25
+ -m, --map Create a file with processed files and dates
24
26
  -o, --output=FILE Output file
25
27
  -i, --image=FILE Image file
26
28
  -g, --graph=PROCESSOR Graphic processor
@@ -32,8 +34,27 @@ Usage: git-age [options]
32
34
  Example:
33
35
 
34
36
  ```
37
+ $ git-age -o /tmp/data.csv -t 'Test project' -x 'Dates here' -y 'Lines here' -i /tmp/data.png
35
38
  ```
36
39
 
40
+ Supported image processors:
41
+
42
+ - [graph-cli](https://github.com/mcastorina/graph-cli)
43
+
44
+ Example image:
45
+
46
+ ![graph-cli graph](https://github.com/taq/git-age/blob/master/graph-cli.png?raw=true)
47
+
48
+ Default options are:
49
+
50
+ - branch: master
51
+ - output: git-age.csv
52
+ - image: git-age.png
53
+ - graph: graph-cli
54
+ - title: Git age statistics
55
+ - xtitle: Dates
56
+ - ytitle: Lines
57
+
37
58
  ## Development
38
59
 
39
60
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/git-age CHANGED
@@ -13,6 +13,11 @@ opts.on('-b', '--branch=BRANCH', 'Git branch') do |branch|
13
13
  options.branch = branch
14
14
  end
15
15
 
16
+ opts.on('-m', '--map', 'Create a file with processed files and dates') do
17
+ STDOUT.puts "Creating map file"
18
+ options.map = true
19
+ end
20
+
16
21
  opts.on('-o', '--output=FILE', 'Output file') do |file|
17
22
  STDOUT.puts "Output to #{file}"
18
23
  options.output = file
data/graph-cli.png ADDED
Binary file
@@ -11,11 +11,10 @@ module Git
11
11
  options = Git::Age::Options.instance
12
12
  STDOUT.puts "Creating image #{options.image} ..."
13
13
 
14
- cmd = "graph #{input} --bar -o #{options.image} --title '#{options.title}' --xlabel='#{options.xtitle}' --ylabel='#{options.ytitle}' --xtick-fontsize 5 --time-format-output '%Y-%m-%d' --legend=''"
14
+ cmd = "graph #{input} --bar -o #{options.image} --title '#{options.title}' --xlabel='#{options.xtitle}' --ylabel='#{options.ytitle}' --xtick-fontsize 5 --time-format-output '%Y-%m-%d' --legend='' 2> /dev/null"
15
15
  rst = IO.popen(cmd) do |io|
16
16
  io.read
17
17
  end
18
- STDOUT.puts rst
19
18
  end
20
19
  end
21
20
  end
data/lib/git/age/main.rb CHANGED
@@ -1,13 +1,17 @@
1
+ require 'date'
2
+ require 'io/console'
3
+
1
4
  module Git
2
5
  module Age
3
6
  class Main
4
- JUSTIFICATION = 150
7
+ attr_reader :dates, :files
5
8
 
6
9
  def initialize
7
10
  STDOUT.puts "Waiting, analysing your repository ..."
8
11
 
9
- @dates = Hash.new(0)
10
- @files = files
12
+ @dates = Hash.new(0)
13
+ @files = files
14
+ @winsize = IO.console.winsize
11
15
  end
12
16
 
13
17
  def run
@@ -15,6 +19,7 @@ module Git
15
19
  sort_dates
16
20
  create_csv
17
21
  create_image
22
+ show_stats
18
23
  rescue => e
19
24
  STDERR.puts "Error: #{e}"
20
25
  end
@@ -22,24 +27,33 @@ module Git
22
27
  private
23
28
 
24
29
  def read_files
25
- cnt = 0
26
- total = @files.size
30
+ cnt = 0
31
+ total = @files.size
32
+ mapfile = Git::Age::Options.instance.map ? File.open("/tmp/git-age.map", 'w') : nil
27
33
 
28
34
  @files.each do |file|
29
35
  cnt += 1
30
36
  next unless text?(file)
31
37
 
32
- print "Checking [#{cnt}/#{total}] #{file.ljust(JUSTIFICATION)} ...\r"
38
+ print "Checking [#{cnt}/#{total}] #{file} ...".ljust(@winsize[1]) + "\r"
39
+
40
+ begin
41
+ IO.popen("git blame #{file} | iconv -t utf8") do |io|
42
+ io.read.split("\n")
43
+ end.each do |line|
44
+ matches = line.match(/[\w^]+\s\([\w\s]+(?<date>\d{4}-\d{2})-\d{2}/)
45
+ next unless matches
33
46
 
34
- IO.popen("git blame #{file} | iconv -t utf8") do |io|
35
- io.read.split("\n")
36
- end.each do |line|
37
- matches = line.match(/\(.*(?<date>\d{4}-\d{2})-\d{2}.*\)/)
38
- next unless matches
47
+ mapfile << "#{file}: #{line}\n" if mapfile
39
48
 
40
- @dates[matches[:date]] += 1
49
+ @dates[matches[:date]] += 1
50
+ end
51
+ rescue => blame
52
+ print "Error on file: #{file}\r"
41
53
  end
42
54
  end
55
+
56
+ mapfile.close if mapfile
43
57
  rescue => e
44
58
  STDERR.puts "Error reading files: #{e}"
45
59
  end
@@ -50,11 +64,13 @@ module Git
50
64
 
51
65
  def create_csv
52
66
  output = Git::Age::Options.instance.output
53
- STDOUT.puts "Creating CSV file #{output} ...".ljust(JUSTIFICATION)
67
+ STDOUT.puts "Creating CSV file #{output} ...".ljust(@winsize[1])
54
68
 
55
69
  File.open(output, 'w') do |file|
70
+ file << "\"date\",\"lines\"\n"
71
+
56
72
  @dates.each do |key, value|
57
- file << "#{key},#{value}\n"
73
+ file << "\"#{key}\",#{value}\n"
58
74
  end
59
75
  end
60
76
  rescue => e
@@ -96,6 +112,19 @@ module Git
96
112
  io.read
97
113
  end.match?(/\Atext/)
98
114
  end
115
+
116
+ def show_stats
117
+ stats = Git::Age::Stats.new(self)
118
+ first = Date.parse(stats.first_commit)
119
+ last = Date.parse(stats.last_commit)
120
+ diff = (last - first).to_i
121
+ ustats = stats.unchanged_stats
122
+
123
+ puts "First commit in: #{first}"
124
+ puts "Last commit in: #{last}"
125
+ puts "Repository is #{diff} days old"
126
+ puts "Month with more lines unchanged: #{ustats[:bigger][:date]} (#{ustats[:bigger][:lines]} lines)"
127
+ end
99
128
  end
100
129
  end
101
130
  end
@@ -4,7 +4,7 @@ module Git
4
4
  module Age
5
5
  class Options
6
6
  include Singleton
7
- attr_accessor :branch, :output, :title, :processor, :image, :xtitle, :ytitle
7
+ attr_accessor :branch, :output, :title, :processor, :image, :xtitle, :ytitle, :map
8
8
 
9
9
  def initialize
10
10
  @branch = 'master'
@@ -14,6 +14,7 @@ module Git
14
14
  @image = 'git-age.png'
15
15
  @xtitle = 'Dates'
16
16
  @ytitle = 'Lines'
17
+ @map = false
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,32 @@
1
+ module Git
2
+ module Age
3
+ class Stats
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ def first_commit
9
+ commit_date('--reverse')
10
+ end
11
+
12
+ def last_commit
13
+ commit_date
14
+ end
15
+
16
+ def unchanged_stats
17
+ max = @data.dates.max_by { |key, value| value }
18
+ { bigger: { date: max[0], lines: max[1] } }
19
+ end
20
+
21
+ private
22
+
23
+ def commit_date(order = nil)
24
+ cmd = "git log #{order} --pretty=format:%ad --date=short | head -n1"
25
+
26
+ IO.popen(cmd) do |io|
27
+ io.read.chomp.strip
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Age
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
data/lib/git/age.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require_relative 'age/main'
2
2
  require_relative 'age/options'
3
+ require_relative 'age/stats'
3
4
  require_relative 'age/graph_cli'
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-age
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eustaquio Rangel
@@ -58,10 +58,12 @@ files:
58
58
  - bin/setup
59
59
  - gem-public_cert.pem
60
60
  - git-age.gemspec
61
+ - graph-cli.png
61
62
  - lib/git/age.rb
62
63
  - lib/git/age/graph_cli.rb
63
64
  - lib/git/age/main.rb
64
65
  - lib/git/age/options.rb
66
+ - lib/git/age/stats.rb
65
67
  - lib/git/age/version.rb
66
68
  homepage: https://github.com/taq/git-age
67
69
  licenses: []
metadata.gz.sig CHANGED
Binary file