danger-todoist 0.0.3 → 0.1.0

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
  SHA1:
3
- metadata.gz: 45658ff29d4eb2568b06f4243fe8c986c1167cef
4
- data.tar.gz: 7e772b86afd289fa5340d70fe6b5234b28e64dc9
3
+ metadata.gz: 8ee3034cbc74c2f326f4ae999d205832415ff0d8
4
+ data.tar.gz: c81b838cf5d97b239d02348ee2599210d32be027
5
5
  SHA512:
6
- metadata.gz: 7547e35d1ed8baf09bdca508d9bc61a589f4a94ab5537552aad116dec55cc79b0028a7bbe3b684639c318cae57cf29214e662e0c672df29b45980584685ed4dc
7
- data.tar.gz: 279263f5a9fea83c92a67124661456e35e77c305b59bf34e7cfb2cc1d7c07fa7d0432f4b610d893ac3115353769fccff1bf12dfc2f044cc169259fe318124927
6
+ metadata.gz: 99523e0d23a2e0feba7df3af2dbc3ad70291066c866437cee9cbce839a32373b837ee2e8dedc82151b2abe9faf1003794ad0cb05e570b197ebb38a86d2a12f03
7
+ data.tar.gz: 485f0e6e33c18224e5593a3e33afcc9d35098fe0f10aa56c7cab22fabf20e3cb633d2f700a72d7ece2f3d9abea25cc3f3a4cce779358b5838d427feafd1609c4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## master
2
2
 
3
+ ## 0.1.0
4
+
5
+ * extract and show todo text as well - hanneskaeufler
6
+ * much more robust todo matching - hanneskaeufler
7
+
3
8
  ## 0.0.3
4
9
 
5
10
  * Only find newly introduced todos - hanneskaeufler
@@ -1,22 +1,29 @@
1
1
  module Danger
2
2
  # Identify todos in a set of diffs
3
3
  class DiffTodoFinder
4
- TODO_REGEXP = /\+.*(TODO|FIXME)[\s:]/i
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
- diffs
8
- .select { |diff| contains_new_todo(diff) }
9
- .map { |diff| Todo.new(diff.path) }
10
- end
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
- def contains_new_todo(diff)
15
- # TODO: This will match removed todos as well
16
- !(diff.patch =~ TODO_REGEXP).nil?
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
@@ -1,3 +1,3 @@
1
1
  module Todoist
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
@@ -55,7 +55,10 @@ module Danger
55
55
 
56
56
  markdown("#### Todos left in files")
57
57
 
58
- @todos.each { |todo| markdown("- #{todo.file}") }
58
+ @todos.each do |todo|
59
+ text = ": #{todo.text}" if todo.text
60
+ markdown("- #{todo.file}#{text}")
61
+ end
59
62
  end
60
63
 
61
64
  private
@@ -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 e.g. a new class name" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-todoist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Käufler