git-age 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4085ff2fcbb2716f679f72390a9f896892a2623fea3635ae234539471cf154a7
4
- data.tar.gz: 4666d870907b6aecf5490eb01ddbcb6dfe6957705616ea697d935bc98b2ee6b4
3
+ metadata.gz: 3ec06da504e9bb782269c3fdbad5e0eb887a935c06557f3ec0b0b2e104898e1e
4
+ data.tar.gz: f606f81e71b79085eb7d6977236311e7f13b50b51118bb9d97dec35e75f15122
5
5
  SHA512:
6
- metadata.gz: 7f8636eddb349efa34d91d05cfbf49d165834bf3d22d188bf1160276eb4ff1dfea73761283cac50b49638a158a44582478d09284e626e0843430c6d935489c12
7
- data.tar.gz: e9c065d66218683e39b6a3b719e8ae95abfd89163d14505f4221fc0856a9749ae5f4409c6f3cc4e0e255c72c5227136fcdf74a0b153277a0f1033c1d4369bfd0
6
+ metadata.gz: '09a406545ef14ce5a469b949648049cdade634333f2ca49868580dbd058e554dddf48031130800c90b27879f19fcdfb8681d93104d86a8ed9f605487ab6ecfbf'
7
+ data.tar.gz: 6fdbc40ef845a5368420d6d4608268bc920f74a81c23a2ad0a25ac1acf59b88f7393f54d46d5adf8ded4dba7b23c62697c905a45ac6b055658437c8ca3699ee8
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-age (0.1.0)
4
+ git-age (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -29,6 +29,10 @@ Usage: git-age [options]
29
29
  -t, --title=TITLE Graphic title
30
30
  -x, --xtitle=TITLE X axis title
31
31
  -y, --ytitle=TITLE Y axis title
32
+ -c, --code=PATTERN Code dir pattern
33
+ -e, --test=PATTERN Test dir pattern
34
+ -y, --type=TYPE Graph type, default to bar
35
+ -v, --version Show version
32
36
  ```
33
37
 
34
38
  Example:
@@ -37,9 +41,25 @@ Example:
37
41
  $ git-age -o /tmp/data.csv -t 'Test project' -x 'Dates here' -y 'Lines here' -i /tmp/data.png
38
42
  ```
39
43
 
44
+ Sending a dir pattern as your test dir, creating a test column to compare:
45
+
46
+ ```
47
+ $ git-age -o /tmp/data.csv -t 'Test project' -x 'Dates here' -y 'Lines here' -i /tmp/data.png -e test
48
+ ```
49
+
50
+ If you're sending a test dir, it can be unfair if you don't also send a dir
51
+ pattern to your code dir, because all other files (configurations, temporary
52
+ files) will count as code and your code to test ratio will implode. So, sending
53
+ a code dir pattern:
54
+
55
+ ```
56
+ $ git-age -o /tmp/data.csv -t 'Test project' -x 'Dates here' -y 'Lines here' -i /tmp/data.png -e test -c app
57
+ ```
58
+
40
59
  Supported image processors:
41
60
 
42
61
  - [graph-cli](https://github.com/mcastorina/graph-cli)
62
+ Supports bar graphs (`-y bar`, default) and line graphs (`-y line`).
43
63
 
44
64
  Example image:
45
65
 
data/bin/git-age CHANGED
@@ -48,6 +48,26 @@ opts.on('-y', '--ytitle=TITLE', 'Y axis title') do |title|
48
48
  options.ytitle = title
49
49
  end
50
50
 
51
+ opts.on('-e', '--test=PATTERN', 'Test dir pattern') do |pattern|
52
+ STDOUT.puts "Using test dir pattern #{pattern}"
53
+ options.test = pattern
54
+ end
55
+
56
+ opts.on('-c', '--code=PATTERN', 'Code dir pattern') do |pattern|
57
+ STDOUT.puts "Using code dir pattern #{pattern}"
58
+ options.code = pattern
59
+ end
60
+
61
+ opts.on('-y', '--type=TYPE', 'Graph type, defaults to bar') do |type|
62
+ STDOUT.puts "Using graph type #{type}"
63
+ options.type = type
64
+ end
65
+
66
+ opts.on('-v', '--version', 'Show version') do
67
+ STDOUT.puts "Version #{Git::Age::VERSION}"
68
+ return
69
+ end
70
+
51
71
  opts.parse!
52
72
 
53
73
  Git::Age::Main.new.run
@@ -9,10 +9,12 @@ module Git
9
9
 
10
10
  def self.create(input)
11
11
  options = Git::Age::Options.instance
12
+ legend = options.test ? 'code' : ''
13
+ type = options.type == 'bar' ? '--bar' : ''
12
14
  STDOUT.puts "Creating image #{options.image} ..."
13
15
 
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
- rst = IO.popen(cmd) do |io|
16
+ cmd = "graph #{input} #{type} -o #{options.image} --title '#{options.title}' --xlabel='#{options.xtitle}' --ylabel='#{options.ytitle}' --xtick-fontsize 5 --time-format-output '%Y-%m-%d' --legend='#{legend}' 2> /dev/null"
17
+ IO.popen(cmd) do |io|
16
18
  io.read
17
19
  end
18
20
  end
data/lib/git/age/main.rb CHANGED
@@ -9,9 +9,14 @@ module Git
9
9
  def initialize
10
10
  STDOUT.puts "Waiting, analysing your repository ..."
11
11
 
12
- @dates = Hash.new(0)
13
- @files = files
12
+ @dates = Hash.new { |hash, key| hash[key] = { code: 0, test: 0 } }
13
+ @files = fill_files
14
14
  @winsize = IO.console.winsize
15
+ @test = Git::Age::Options.instance.test
16
+ @code = Git::Age::Options.instance.code
17
+
18
+ @test_regexp = @test ? %r{^#{@test}} : nil
19
+ @code_regexp = @code ? %r{^#{@code}} : nil
15
20
  end
16
21
 
17
22
  def run
@@ -22,10 +27,19 @@ module Git
22
27
  show_stats
23
28
  rescue => e
24
29
  STDERR.puts "Error: #{e}"
30
+ puts e.backtrace
25
31
  end
26
32
 
27
33
  private
28
34
 
35
+ def file_type(file)
36
+ return :t if @test_regexp && file.match(@test_regexp)
37
+
38
+ return :c unless @code_regexp
39
+
40
+ @code_regexp && file.match(@code_regexp) ? :c : :u
41
+ end
42
+
29
43
  def read_files
30
44
  cnt = 0
31
45
  total = @files.size
@@ -44,12 +58,14 @@ module Git
44
58
  matches = line.match(/[\w^]+\s\([\w\s]+(?<date>\d{4}-\d{2})-\d{2}/)
45
59
  next unless matches
46
60
 
47
- mapfile << "#{file}: #{line}\n" if mapfile
61
+ type = file_type(file)
62
+ mapfile << "#{file}[#{type}]: #{line}\n" if mapfile
48
63
 
49
- @dates[matches[:date]] += 1
64
+ @dates[matches[:date]][:test] += 1 if type == :t
65
+ @dates[matches[:date]][:code] += 1 if type == :c
50
66
  end
51
- rescue => blame
52
- print "Error on file: #{file}\r"
67
+ rescue => exc
68
+ print "Error on file: #{file}: #{exc}\r"
53
69
  end
54
70
  end
55
71
 
@@ -64,13 +80,17 @@ module Git
64
80
 
65
81
  def create_csv
66
82
  output = Git::Age::Options.instance.output
67
- STDOUT.puts "Creating CSV file #{output} ...".ljust(@winsize[1])
83
+ STDOUT.puts "Creating CSV file #{output} with #{@dates.size} lines ...".ljust(@winsize[1])
68
84
 
69
85
  File.open(output, 'w') do |file|
70
- file << "\"date\",\"lines\"\n"
71
-
72
- @dates.each do |key, value|
73
- file << "\"#{key}\",#{value}\n"
86
+ header = "\"date\",\"code\""
87
+ header << ",\"test\"" if @test
88
+ file << "#{header}\n"
89
+
90
+ @dates.each do |key, data|
91
+ line = "\"#{key}\",#{data[:code]}"
92
+ line << ",#{data[:test]}" if @test
93
+ file << "#{line}\n"
74
94
  end
75
95
  end
76
96
  rescue => e
@@ -96,7 +116,7 @@ module Git
96
116
  processor.create(options.output)
97
117
  end
98
118
 
99
- def files
119
+ def fill_files
100
120
  branch = Git::Age::Options.instance.branch
101
121
  STDOUT.puts "Reading files info from #{branch} branch ..."
102
122
 
@@ -117,13 +137,18 @@ module Git
117
137
  stats = Git::Age::Stats.new(self)
118
138
  first = Date.parse(stats.first_commit)
119
139
  last = Date.parse(stats.last_commit)
120
- diff = (last - first).to_i
140
+ diff = (last - first).to_i + 1
121
141
  ustats = stats.unchanged_stats
122
142
 
123
143
  puts "First commit in: #{first}"
124
144
  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)"
145
+ puts "Repository has #{diff} days with commits"
146
+ puts "Month with more code lines unchanged: #{ustats[:bigger][:date]} (#{ustats[:bigger][:lines]} lines)"
147
+
148
+ if @test_regexp && @code_regexp
149
+ ratio = stats.code_to_test_ratio
150
+ puts "Code to test ratio: 1:#{ratio[:ratio]} (#{ratio[:code]}/#{ratio[:test]})"
151
+ end
127
152
  end
128
153
  end
129
154
  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, :map
7
+ attr_accessor :branch, :output, :title, :processor, :image, :xtitle, :ytitle, :map, :test, :code, :type
8
8
 
9
9
  def initialize
10
10
  @branch = 'master'
@@ -14,6 +14,9 @@ module Git
14
14
  @image = 'git-age.png'
15
15
  @xtitle = 'Dates'
16
16
  @ytitle = 'Lines'
17
+ @test = nil
18
+ @code = nil
19
+ @type = 'bar'
17
20
  @map = false
18
21
  end
19
22
  end
data/lib/git/age/stats.rb CHANGED
@@ -14,8 +14,20 @@ module Git
14
14
  end
15
15
 
16
16
  def unchanged_stats
17
- max = @data.dates.max_by { |key, value| value }
18
- { bigger: { date: max[0], lines: max[1] } }
17
+ max = @data.dates.max_by { |key, value| value[:code] }
18
+ { bigger: { date: max[0], lines: max[1][:code] } }
19
+ end
20
+
21
+ def code_to_test_ratio
22
+ stats = @data.dates.reduce({code: 0, test: 0}) do |memo, data|
23
+ memo[:code] += data[1][:code]
24
+ memo[:test] += data[1][:test]
25
+ memo
26
+ end
27
+
28
+ { code: stats[:code], test: stats[:test], ratio: (stats[:test].to_f / stats[:code].to_f).round(2) }
29
+ rescue
30
+ { code: 0, test: 0, ratio: 0.0 }
19
31
  end
20
32
 
21
33
  private
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Age
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-age
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eustaquio Rangel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -36,7 +36,7 @@ cert_chain:
36
36
  7NRJmY9c84Zb3sCf0DV6UH+d2id9Dndp9ewchgDOSwGznt+oJmjDFZ9gYd8IP2Ol
37
37
  1eLrW8x4LHV+EVEIaiVTvmKt
38
38
  -----END CERTIFICATE-----
39
- date: 2022-08-25 00:00:00.000000000 Z
39
+ date: 2022-12-22 00:00:00.000000000 Z
40
40
  dependencies: []
41
41
  description: Check all the repository files lines dates and group it by year and month,
42
42
  allowing check how old code is still in use
@@ -70,7 +70,7 @@ licenses: []
70
70
  metadata:
71
71
  homepage_uri: https://github.com/taq/git-age
72
72
  source_code_uri: https://github.com/taq/git-age
73
- post_install_message:
73
+ post_install_message:
74
74
  rdoc_options: []
75
75
  require_paths:
76
76
  - lib
@@ -85,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.3.7
89
- signing_key:
88
+ rubygems_version: 3.3.3
89
+ signing_key:
90
90
  specification_version: 4
91
91
  summary: Create a CSV file with line year and month from your Git repository
92
92
  test_files: []
metadata.gz.sig CHANGED
Binary file