debtective 0.2.3 → 0.2.3.1
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 +4 -4
- data/bin/debtective +3 -1
- data/lib/debtective/build_todo.rb +1 -0
- data/lib/debtective/find_todos.rb +1 -0
- data/lib/debtective/output_todos.rb +30 -80
- data/lib/debtective/print_table.rb +87 -0
- data/lib/debtective/version.rb +1 -1
- data/lib/tasks/debtective/todo_list.rake +7 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5337f50843d65198958e3c2a2f63b1b618f69070ec5445203c2615cc548ce833
|
4
|
+
data.tar.gz: 128f58647d0da0046a99088fa1e7cd0c06c8fe0a557a8e1e3304e0f84a2644b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34e11cc316b6a64489873769db16d2125a61643c8f70abf602f399df51d033a2e57df267520ca46caf2b4186600f38b9c00b8cc23159d8729316c25dfafb81d5
|
7
|
+
data.tar.gz: 74a9440b99fb2b9d4888b19e64efa5c6de67742cdad82e8c89b706293074a902292b7826f0e5092ec31cbd45f863aa5ea14878b30c988d5922d14dd9acc47505
|
data/bin/debtective
CHANGED
@@ -1,112 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "json"
|
4
|
-
require "debtective/
|
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
|
-
|
14
|
-
|
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
|
23
|
-
|
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
|
-
|
34
|
+
Debtective::PrintTable.new(@user_name).call
|
39
35
|
end
|
40
36
|
|
41
37
|
# @return [void]
|
42
|
-
def
|
43
|
-
|
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
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
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 [
|
103
|
-
def
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
data/lib/debtective/version.rb
CHANGED
@@ -11,6 +11,12 @@ end
|
|
11
11
|
namespace :debtective do
|
12
12
|
desc "Todo List"
|
13
13
|
task :todo_list do
|
14
|
-
|
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-
|
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
|