danger-todoist 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/todoist/diff_todo_finder.rb +18 -11
- data/lib/todoist/gem_version.rb +1 -1
- data/lib/todoist/plugin.rb +4 -1
- data/spec/diff_todo_finder_spec.rb +37 -3
- data/spec/todoist_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ee3034cbc74c2f326f4ae999d205832415ff0d8
|
4
|
+
data.tar.gz: c81b838cf5d97b239d02348ee2599210d32be027
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99523e0d23a2e0feba7df3af2dbc3ad70291066c866437cee9cbce839a32373b837ee2e8dedc82151b2abe9faf1003794ad0cb05e570b197ebb38a86d2a12f03
|
7
|
+
data.tar.gz: 485f0e6e33c18224e5593a3e33afcc9d35098fe0f10aa56c7cab22fabf20e3cb633d2f700a72d7ece2f3d9abea25cc3f3a4cce779358b5838d427feafd1609c4
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
module Danger
|
2
2
|
# Identify todos in a set of diffs
|
3
3
|
class DiffTodoFinder
|
4
|
-
TODO_REGEXP =
|
4
|
+
TODO_REGEXP = /
|
5
|
+
^\+ # we only look at additions, marked by + in diffs
|
6
|
+
\s* # followed by optional space
|
7
|
+
[^a-z0-9]* # anything looking like a comment indicator
|
8
|
+
\s+ # followed by at least one space
|
9
|
+
(TODO|FIXME) # our todo indicator
|
10
|
+
[\s:]{1} # followed by a space or colon
|
11
|
+
(?<text>.*)$ # matching any text until the end of the line
|
12
|
+
/ix
|
5
13
|
|
6
14
|
def find_diffs_containing_todos(diffs)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
private
|
15
|
+
todos = []
|
16
|
+
diffs.each do |diff|
|
17
|
+
matches = diff.patch.match(TODO_REGEXP)
|
18
|
+
next if matches.nil?
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
20
|
+
text = matches[1] if matches[1]
|
21
|
+
todos << Todo.new(diff.path, text.strip)
|
22
|
+
end
|
23
|
+
todos
|
17
24
|
end
|
18
25
|
|
19
|
-
class Todo < Struct.new(:file)
|
26
|
+
class Todo < Struct.new(:file, :text)
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
data/lib/todoist/gem_version.rb
CHANGED
data/lib/todoist/plugin.rb
CHANGED
@@ -11,7 +11,23 @@ module Danger
|
|
11
11
|
Git::Diff::DiffFile.new(
|
12
12
|
"base",
|
13
13
|
path: "some/file.rb",
|
14
|
-
patch: "+ #{marker} some todo"
|
14
|
+
patch: "+ # #{marker} some todo"
|
15
|
+
)
|
16
|
+
]
|
17
|
+
|
18
|
+
todos = subject.find_diffs_containing_todos(diffs)
|
19
|
+
|
20
|
+
expect(todos).to_not be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
%w(# {{ -- //).each do |comment|
|
25
|
+
it "identifies todos in languages with '#{comment}' as comments" do
|
26
|
+
diffs = [
|
27
|
+
Git::Diff::DiffFile.new(
|
28
|
+
"base",
|
29
|
+
path: "some/file.rb",
|
30
|
+
patch: "+ #{comment} TODO: some todo"
|
15
31
|
)
|
16
32
|
]
|
17
33
|
|
@@ -38,9 +54,13 @@ module Danger
|
|
38
54
|
[
|
39
55
|
"+ class TodosController",
|
40
56
|
"+ function foo(todo) {",
|
41
|
-
"+ def todo()"
|
57
|
+
"+ def todo()",
|
58
|
+
"+ def todo foo",
|
59
|
+
"+ * this looks like a todo but isnt",
|
60
|
+
"+ TODO_REGEXP = /",
|
61
|
+
"+ todos = subject.find_diffs_containing_todos(diffs)"
|
42
62
|
].each do |patch|
|
43
|
-
it "does not identify occurences in
|
63
|
+
it "does not identify occurences in '#{patch}'" do
|
44
64
|
diffs = [
|
45
65
|
Git::Diff::DiffFile.new(
|
46
66
|
"base",
|
@@ -54,6 +74,20 @@ module Danger
|
|
54
74
|
expect(todos).to be_empty
|
55
75
|
end
|
56
76
|
end
|
77
|
+
|
78
|
+
it "identifies the todo text as well" do
|
79
|
+
diffs = [
|
80
|
+
Git::Diff::DiffFile.new(
|
81
|
+
"base",
|
82
|
+
path: "some/file.rb",
|
83
|
+
patch: "+ # TODO: practice you must"
|
84
|
+
)
|
85
|
+
]
|
86
|
+
|
87
|
+
todos = subject.find_diffs_containing_todos(diffs)
|
88
|
+
|
89
|
+
expect(todos.first.text).to eql("practice you must")
|
90
|
+
end
|
57
91
|
end
|
58
92
|
end
|
59
93
|
end
|
data/spec/todoist_spec.rb
CHANGED
@@ -17,12 +17,12 @@ module Danger
|
|
17
17
|
modified = Git::Diff::DiffFile.new(
|
18
18
|
"base",
|
19
19
|
path: "some/file.rb",
|
20
|
-
patch: "+ TODO: some todo"
|
20
|
+
patch: "+ # TODO: some todo"
|
21
21
|
)
|
22
22
|
added = Git::Diff::DiffFile.new(
|
23
23
|
"base",
|
24
24
|
path: "another/stuff.rb",
|
25
|
-
patch: "+ fixme: another todo"
|
25
|
+
patch: "+ # fixme: another todo"
|
26
26
|
)
|
27
27
|
|
28
28
|
allow(@dangerfile.git).to receive(:diff_for_file)
|
@@ -59,8 +59,8 @@ module Danger
|
|
59
59
|
expect(markdowns).to eq(
|
60
60
|
[
|
61
61
|
"#### Todos left in files",
|
62
|
-
"- some/file.rb",
|
63
|
-
"- another/stuff.rb"
|
62
|
+
"- some/file.rb: some todo",
|
63
|
+
"- another/stuff.rb: another todo"
|
64
64
|
]
|
65
65
|
)
|
66
66
|
end
|