devloop 0.1.1 → 0.1.3

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: 7bdfbb6b5c25d903818042b071bf95090cccb324fd993957d8a6c9232310d6b3
4
- data.tar.gz: dc18174f6087bca3656a47d072baa8c9b3ef177252ba20a50bdac21660417d9d
3
+ metadata.gz: 4c05521d9743b10962d9a0fb72bdbe848684923192ad72b4dccb5cf577481a93
4
+ data.tar.gz: 850d44822f193f71a61f75846bef409b52e5f9782f1b73a083694a18c0c9610a
5
5
  SHA512:
6
- metadata.gz: dee4939c6e441d48e24d96d70ae4d215376adbbca9fc31f3f69374d0dfd7cc643dd5e2f2fd41975dd5476f477858b95e8bfe1c49716a5657721b74d28a551edc
7
- data.tar.gz: 8f94d9393b420e40028c53748f27415e0e587252ce94cb67b0b7ebf86f4aa6ff05e9bc1c7617c81d75c4835050b4a7d736d0874eb4807915e50968160ec42e7d
6
+ metadata.gz: 3f9a620c03e1a48ca1e22eb247789b75f828f1991215d2abcc9331bb68b496849b69db06c80968fea0dda6b3d8515022576b7e7ce417083a88fd73862e3032a3
7
+ data.tar.gz: 0f34eb18349d10c0bf37e08726c1892e56e5d52c70762b7f0405f3839ed3396fda4fbb951a3f1badff3142b2e66734cf2381fa4c4609c13b56002965600fba27
@@ -4,24 +4,35 @@ module Devloop
4
4
  new.call(diff)
5
5
  end
6
6
 
7
+ Diff = Struct.new(:filename, :line_number)
8
+
7
9
  def call(diff)
8
- _, results = diff.split("\n").reduce(["", []]) do |(file, results), line|
10
+ _, diffs_data = diff.split("\n").reduce(["", []]) do |(file, diffs_data), line|
9
11
  if line.start_with?("+++ b/")
10
- [line[6..-1], results]
12
+ [line[6..-1], diffs_data]
11
13
  elsif line.start_with?("@@ -")
12
14
  line_number = line.match(/@@ -(\d+)/)[1]
13
- if line_number == "1"
14
- [file, results << "#{relative_path(file)}"]
15
- else
16
- [file, results << "#{relative_path(file)}:#{line_number}"]
17
- end
15
+ [file, diffs_data << Diff.new(relative_path(file), line_number)]
18
16
  else
19
- [file, results]
17
+ [file, diffs_data]
20
18
  end
21
19
  end.uniq
22
20
 
21
+ results = diffs_data.group_by do |el|
22
+ el.filename
23
+ end.map do |key, value|
24
+ line_numbers = value.map(&:line_number).map(&:to_i)
25
+ if line_numbers.include?(0) || line_numbers.include?(1)
26
+ key
27
+ else
28
+ lines_range = (line_numbers.min..line_numbers.max).to_a.join(":")
29
+
30
+ "#{key}:#{lines_range}"
31
+ end
32
+ end
33
+
23
34
  # Remove filenames with line number if filename without line number is present
24
- results.reject { |result| results.include?(result.split(":").first) && result.include?(":") }
35
+ res = results.reject { |result| results.include?(result.split(":").first) && result.include?(":") }
25
36
  end
26
37
 
27
38
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devloop
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -68,7 +68,7 @@ describe Devloop::DiffParser do
68
68
 
69
69
  it "parses the diff correctly" do
70
70
  expect(Devloop::DiffParser.call(diff1)).to eq(["spec/models/team_spec.rb:10", "spec/models/user_spec.rb:167"])
71
- expect(Devloop::DiffParser.call(diff2)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
71
+ expect(Devloop::DiffParser.call(diff2)).to eq(["spec/models/team_spec.rb:19:20:21:22:23:24"])
72
72
  end
73
73
  end
74
74
 
@@ -93,7 +93,86 @@ describe Devloop::DiffParser do
93
93
  it "parses the diff correctly" do
94
94
  allow_any_instance_of(Devloop::DiffParser).to receive(:git_root_path).and_return("/Users/username/projects/")
95
95
  allow_any_instance_of(Devloop::DiffParser).to receive(:project_path).and_return("src/")
96
- expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
96
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/team_spec.rb:19:20:21:22:23:24"])
97
+ end
98
+ end
99
+
100
+ context "removes 0 line numbers" do
101
+ let(:diff) do
102
+ <<~DIFF
103
+ diff --git a/spec/config_spec.rb b/spec/config_spec.rb
104
+ index d9716e7..b470ec2 100644
105
+ --- a/spec/config_spec.rb
106
+ +++ b/spec/config_spec.rb
107
+ @@ -5 +5 @@ require "spec_helper"
108
+ -describe "PgLocksMonitor::Confiuration" do
109
+ +describe "PgLocksMonitor::Configuration" do
110
+ @@ -8,2 +8,5 @@ describe "PgLocksMonitor::Confiuration" do
111
+ - expect(config.notify_locks).to eq true
112
+ - expect(config.notify_blocking).to eq true
113
+ + expect(config.monitor_locks).to eq true
114
+ + expect(config.monitor_blocking).to eq true
115
+ + expect(config.locks_min_duration_ms).to eq 200
116
+ + expect(config.blocking_min_duration_ms).to eq 100
117
+ + expect(config.notifier_class).to eq PgLocksMonitor::DefaultNotifier
118
+ @@ -14 +17 @@ describe "PgLocksMonitor::Confiuration" do
119
+ - config.notify_locks = false
120
+ + config.monitor_locks = false
121
+ @@ -17 +20 @@ describe "PgLocksMonitor::Confiuration" do
122
+ - expect(PgLocksMonitor.configuration.notify_locks).to eq false
123
+ + expect(PgLocksMonitor.configuration.monitor_locks).to eq false
124
+ diff --git a/spec/default_notifier_spec.rb b/spec/default_notifier_spec.rb
125
+ new file mode 100644
126
+ index 0000000..d99d3a1
127
+ --- /dev/null
128
+ +++ b/spec/default_notifier_spec.rb
129
+ @@ -0,0 +1,11 @@
130
+ +# frozen_string_literal: true
131
+ +
132
+ +require "spec_helper"
133
+ +
134
+ +describe PgLocksMonitor::DefaultNotifier do
135
+ + it "requires correct config if Slack notifications enabled" do
136
+ + expect {
137
+ + PgLocksMonitor::DefaultNotifier.call({})
138
+ + }.not_to raise_error
139
+ + end
140
+ +end
141
+ DIFF
142
+ end
143
+
144
+ it "parses the diff correctly" do
145
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/config_spec.rb:5:6:7:8:9:10:11:12:13:14:15:16:17", "spec/default_notifier_spec.rb"])
146
+ end
147
+ end
148
+
149
+ context "executes each matching spec" do
150
+ let(:diff) do
151
+ <<~DIFF
152
+ diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
153
+ index 410ffa8c..0266ea38 100644
154
+ --- a/spec/models/user_spec.rb
155
+ +++ b/spec/models/user_spec.rb
156
+ @@ -10,3 +10,3 @@ describe User do
157
+ - it "has a valid factory" do
158
+ - expect(user).to be_valid
159
+ - end
160
+ + it "has a valid factory" do #
161
+ + expect(user).to be_valid #
162
+ + end #
163
+ @@ -14,2 +14,2 @@ describe User do
164
+ - it "has pending_feedbacks" do
165
+ - expect(create(:user).pending_feedbacks).to eq []
166
+ + it "has pending_feedbacks" do#
167
+ + expect(create(:user).pending_feedbacks).to eq [] #
168
+ @@ -17 +17 @@ describe User do
169
+ -
170
+ +#
171
+ DIFF
172
+ end
173
+
174
+ it "parses the diff correctly" do
175
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/user_spec.rb:10:11:12:13:14:15:16:17"])
97
176
  end
98
177
  end
99
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen