debtective 0.2.3 → 0.2.3.1

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: 4c9cd2c9eaaa35023797d69a854fd1b749269c03e029a1fd9447b993d653b917
4
- data.tar.gz: 7b3cff2afb3474d1ec0ba8449f88e4795f91d35c4b49af4337e9eb64693443e2
3
+ metadata.gz: 5337f50843d65198958e3c2a2f63b1b618f69070ec5445203c2615cc548ce833
4
+ data.tar.gz: 128f58647d0da0046a99088fa1e7cd0c06c8fe0a557a8e1e3304e0f84a2644b3
5
5
  SHA512:
6
- metadata.gz: 3ad250e7e42470f6404de2eaff106319c5c7f6f543276e02ef28afba2a6fc301f3bb35ecea069737e21f5ceeb70126fc968e70118f3f4196f75eeebd0ad1c724
7
- data.tar.gz: d648747191b567134e238e4692014ef211c5715bd5524245e524626de5b8ee8fd87979641a6a3238755a2512171266081072c9ca3a5fc47f3b16d7ce7084f752
6
+ metadata.gz: 34e11cc316b6a64489873769db16d2125a61643c8f70abf602f399df51d033a2e57df267520ca46caf2b4186600f38b9c00b8cc23159d8729316c25dfafb81d5
7
+ data.tar.gz: 74a9440b99fb2b9d4888b19e64efa5c6de67742cdad82e8c89b706293074a902292b7826f0e5092ec31cbd45f863aa5ea14878b30c988d5922d14dd9acc47505
data/bin/debtective CHANGED
@@ -4,4 +4,6 @@
4
4
  require "debtective"
5
5
  require "debtective/output_todos"
6
6
 
7
- Debtective::OutputTodos.new.call
7
+ user_name = `git config user.name`.strip if ARGV.include?("--me")
8
+ quiet = ARGV.include?("--quiet")
9
+ Debtective::OutputTodos.new(user_name, quiet: quiet).call
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
3
4
  require "debtective/todo"
4
5
  require "debtective/find_end_of_statement"
5
6
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
3
4
  require "debtective/build_todo"
4
5
 
5
6
  module Debtective
@@ -1,112 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
- require "debtective/todo_list"
4
+ require "debtective/print_table"
5
+ require "pry"
5
6
 
6
7
  module Debtective
7
8
  # Generate todolist
8
9
  class OutputTodos
9
10
  FILE_PATH = "todos.json"
10
11
 
12
+ # @param user_name [String] git user email to filter
13
+ def initialize(user_name = nil, quiet: false)
14
+ @user_name = user_name
15
+ @quiet = quiet
16
+ end
17
+
11
18
  # @return [void]
12
19
  def call
13
- log_table_headers
14
- log_table_rows
20
+ @todo_list = log_table
21
+ @todo_list ||= Debtective::TodoList.new(Debtective.configuration&.paths || ["./**/*"])
22
+ filter_todo_list!
15
23
  log_counts
16
24
  update_json_file
25
+ puts FILE_PATH
17
26
  end
18
27
 
19
28
  private
20
29
 
21
30
  # @return [void]
22
- def update_json_file
23
- File.open(FILE_PATH, "w") do |file|
24
- file.puts(
25
- JSON.pretty_generate(
26
- todo_list.todos.map(&:to_h)
27
- )
28
- )
29
- end
30
- puts FILE_PATH
31
- puts separator
32
- end
33
-
34
- # @return [void]
35
- def create_directory
36
- return if File.directory?(DIRECTORY_PATH)
31
+ def log_table
32
+ return if @quiet
37
33
 
38
- FileUtils.mkdir_p(DIRECTORY_PATH)
34
+ Debtective::PrintTable.new(@user_name).call
39
35
  end
40
36
 
41
37
  # @return [void]
42
- def log_table_headers
43
- puts separator
44
- puts table_row("location", "author", "days", "size")
45
- puts separator
46
- end
47
-
48
- # @return [void]
49
- def log_table_rows
50
- with_trace_logs(
51
- lambda do |todo|
52
- puts(
53
- table_row(
54
- todo.location,
55
- todo.commit.author.name || "?",
56
- todo.days || "?",
57
- todo.size
58
- )
59
- )
60
- end
61
- ) do
62
- todo_list.todos
63
- end
64
- puts separator
65
- end
66
-
67
- # @param lambda [Lambda]
68
- # @yield
69
- def with_trace_logs(lambda)
70
- trace =
71
- TracePoint.new(:return) do |trace_point|
72
- next unless trace_point.defined_class == Debtective::BuildTodo && trace_point.method_id == :call
73
-
74
- todo = trace_point.return_value
75
- lambda.call(todo)
76
- end
77
- trace.enable
78
- yield
79
- trace.disable
80
- end
81
-
82
- # @return [Debtective::Todo]
83
- def todo_list
84
- @todo_list ||= Debtective::TodoList.new(
85
- Debtective.configuration&.paths || ["./**/*"]
86
- )
38
+ def filter_todo_list!
39
+ !@user_name.nil? && @todo_list.todos.select! { _1.commit.author.name == @user_name }
87
40
  end
88
41
 
89
42
  # @return [void]
90
43
  def log_counts
91
- puts "count: #{todo_list.todos.count}"
92
- puts "combined lines count: #{todo_list.combined_count}"
93
- puts "extended lines count: #{todo_list.extended_count}"
94
- puts separator
95
- end
44
+ @return if @quiet
96
45
 
97
- # @return [String]
98
- def separator
99
- @separator ||= Array.new(table_row(nil, nil, nil, nil).size) { "-" }.join
46
+ puts "total: #{@todo_list.todos.count}"
47
+ puts "combined lines count: #{@todo_list.combined_count}"
48
+ puts "extended lines count: #{@todo_list.extended_count}"
100
49
  end
101
50
 
102
- # @return [String]
103
- def table_row(col1, col2, col3, col4)
104
- [
105
- format("%-80.80s", col1.to_s),
106
- format("%-20.20s", col2.to_s),
107
- format("%-12.12s", col3.to_s),
108
- format("%-12.12s", col4.to_s)
109
- ].join(" | ")
51
+ # @return [void]
52
+ def update_json_file
53
+ File.open(FILE_PATH, "w") do |file|
54
+ file.puts(
55
+ JSON.pretty_generate(
56
+ @todo_list.todos.map(&:to_h)
57
+ )
58
+ )
59
+ end
110
60
  end
111
61
  end
112
62
  end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "debtective/todo_list"
4
+
5
+ module Debtective
6
+ # Print todos as a table in the stdout
7
+ class PrintTable
8
+ # @param user_name [String] git user email to filter
9
+ def initialize(user_name = nil)
10
+ @user_name = user_name
11
+ end
12
+
13
+ # @return [Debtective::TodoList]
14
+ def call
15
+ log_table_headers
16
+ log_table_rows
17
+ todo_list
18
+ end
19
+
20
+ private
21
+
22
+ # @return [void]
23
+ def log_table_headers
24
+ puts separator
25
+ puts table_row("location", "author", "days", "size")
26
+ puts separator
27
+ end
28
+
29
+ # @return [void]
30
+ def log_table_rows
31
+ trace.enable
32
+ todo_list.todos
33
+ trace.disable
34
+ puts separator
35
+ end
36
+
37
+ # use a trace to log each todo as soon as it is found
38
+ # @return [Tracepoint]
39
+ def trace
40
+ TracePoint.new(:return) do |trace_point|
41
+ next unless trace_point.defined_class == Debtective::BuildTodo && trace_point.method_id == :call
42
+
43
+ todo = trace_point.return_value
44
+ log_todo(todo)
45
+ end
46
+ end
47
+
48
+ # if a user_name is given and is not the commit author
49
+ # the line is temporary and will be replaced by the next one
50
+ # @return [void]
51
+ def log_todo(todo)
52
+ row = table_row(
53
+ todo.location,
54
+ todo.commit.author.name || "?",
55
+ todo.days || "?",
56
+ todo.size
57
+ )
58
+ if @user_name.nil? || @user_name == todo.commit.author.name
59
+ puts row
60
+ else
61
+ print "#{row}\r"
62
+ end
63
+ end
64
+
65
+ # @return [Debtective::Todo]
66
+ def todo_list
67
+ @todo_list ||= Debtective::TodoList.new(
68
+ Debtective.configuration&.paths || ["./**/*"]
69
+ )
70
+ end
71
+
72
+ # @return [String]
73
+ def table_row(location, author, days, size)
74
+ [
75
+ format("%-80.80s", location),
76
+ format("%-20.20s", author),
77
+ format("%-12.12s", days),
78
+ format("%-12.12s", size)
79
+ ].join(" | ")
80
+ end
81
+
82
+ # @return [String]
83
+ def separator
84
+ @separator ||= Array.new(table_row(nil, nil, nil, nil).size) { "-" }.join
85
+ end
86
+ end
87
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Debtective
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.3.1"
5
5
  end
@@ -11,6 +11,12 @@ end
11
11
  namespace :debtective do
12
12
  desc "Todo List"
13
13
  task :todo_list do
14
- Debtective::OutputTodos.new.call
14
+ if ARGV.include?("--me")
15
+ user_name = `git config user.name`.strip
16
+ puts "Searching TODOs from #{user_name}..."
17
+ else
18
+ puts "Searching TODOs..."
19
+ end
20
+ Debtective::OutputTodos.new(user_name, quiet: ARGV.include?("--quiet")).call
15
21
  end
16
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debtective
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Piron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -111,7 +111,8 @@ dependencies:
111
111
  description: Find TODOs and compute debt size
112
112
  email:
113
113
  - ed.piron@gmail.com
114
- executables: []
114
+ executables:
115
+ - debtective
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -123,6 +124,7 @@ files:
123
124
  - lib/debtective/find_todos.rb
124
125
  - lib/debtective/git_commit.rb
125
126
  - lib/debtective/output_todos.rb
127
+ - lib/debtective/print_table.rb
126
128
  - lib/debtective/railtie.rb
127
129
  - lib/debtective/stderr_helper.rb
128
130
  - lib/debtective/todo.rb