devloop 0.0.6 → 0.0.7

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: cdbcf2a0d7f3ee56a98ad2db128f8835b348f990efab6fd77ab9a57dbc2f6aa3
4
- data.tar.gz: 7b041ec78b9ac2c25e6423e9d3dc4b8be64c1283668d88a259200efa4feade24
3
+ metadata.gz: 329272a8c3033e7d6d4cb63d2ca284b87f8d4883e64fc613ad00e2f2eaf7ca8b
4
+ data.tar.gz: 3fa337ca6600ffd440c53170ed6d1aa59cdf09207d64738c8248cf3f027e2ab6
5
5
  SHA512:
6
- metadata.gz: 381c4b59391e866838d90084e8251f193d7d3ba31da4ddc7905e28311e6e0d7ab42fb2a5ca18773fe58706f62a270e8a6b7ff9d4412e842954dbb4a86e6a9108
7
- data.tar.gz: 6f1d6304053545f310d5416a5649e704d84481a1d654d0c2e4530e64b5f0ee429d41c5106f5465a4c174f097df8a9f5402c0c6890491fe4f29a5283f50139c0a
6
+ metadata.gz: 48664a8ba229cd1730994c47d60f1a1f0fcb7e225f038c6903ae17125f27ae3091b8ef75d75558932b21e6e82ad15e5e3de47fdfc337450b15dacf3b88644a29
7
+ data.tar.gz: c75e9d90a51e8aa003e0f069490004957241dbc54543fe202058efd82ab943678b094d7ff45f2a1aad44fd31240f9d7c656b8b7e08a8fa9f2f4432f37596ae21
@@ -5,18 +5,31 @@ module Devloop
5
5
  end
6
6
 
7
7
  def call(diff)
8
- lines = diff.split("\n")
9
- results = []
10
- file = ""
11
- lines.each_with_index do |line, index|
8
+ _, results = diff.split("\n").reduce(["", []]) do |(file, results), line|
12
9
  if line.start_with?("+++ b/")
13
- file = line[6..-1]
10
+ [line[6..-1], results]
14
11
  elsif line.start_with?("@@ -")
15
12
  line_number = line.match(/@@ -(\d+)/)[1]
16
- results << "#{file}:#{line_number}"
13
+ [file, results << "#{relative_path(file)}:#{line_number}"]
14
+ else
15
+ [file, results]
17
16
  end
18
17
  end
19
18
  results
20
19
  end
20
+
21
+ private
22
+
23
+ def relative_path(path)
24
+ path.gsub(project_path, "")
25
+ end
26
+
27
+ def project_path
28
+ @project_path ||= Dir.pwd.gsub("#{git_root_path}/", "") + "/"
29
+ end
30
+
31
+ def git_root_path
32
+ @git_root_path ||= `git rev-parse --show-toplevel`.strip
33
+ end
21
34
  end
22
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devloop
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
@@ -4,46 +4,73 @@ require "spec_helper"
4
4
  require "devloop/diff_parser"
5
5
 
6
6
  describe Devloop::DiffParser do
7
- let(:diff1) do
8
- <<~DIFF
9
- diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb
10
- index 19772f2a..a32824f9 100644
11
- --- a/spec/models/team_spec.rb
12
- +++ b/spec/models/team_spec.rb
13
- @@ -10,2 +10,2 @@ describe Team do
14
- - it "has a valid factory" do
15
- - expect(team).to be_valid
16
- + it "has valid factory" do
17
- + expect(team).not_to be_valid
18
- diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
19
- index 410ffa8c..610d9e19 100644
20
- --- a/spec/models/user_spec.rb
21
- +++ b/spec/models/user_spec.rb
22
- @@ -167 +167 @@ describe User do
23
- - web_auth_token_generated_at: 50.minutes.ago,
24
- + web_auth_token_generated_at: 10.minutes.ago,
25
- DIFF
26
- end
7
+ context "when the project root is the same as git root" do
8
+ let(:diff1) do
9
+ <<~DIFF
10
+ diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb
11
+ index 19772f2a..a32824f9 100644
12
+ --- a/spec/models/team_spec.rb
13
+ +++ b/spec/models/team_spec.rb
14
+ @@ -10,2 +10,2 @@ describe Team do
15
+ - it "has a valid factory" do
16
+ - expect(team).to be_valid
17
+ + it "has valid factory" do
18
+ + expect(team).not_to be_valid
19
+ diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
20
+ index 410ffa8c..610d9e19 100644
21
+ --- a/spec/models/user_spec.rb
22
+ +++ b/spec/models/user_spec.rb
23
+ @@ -167 +167 @@ describe User do
24
+ - web_auth_token_generated_at: 50.minutes.ago,
25
+ + web_auth_token_generated_at: 10.minutes.ago,
26
+ DIFF
27
+ end
28
+
29
+ let(:diff2) do
30
+ <<~DIFF
31
+ diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb
32
+ index 19772f2a..9f614e20 100644
33
+ --- a/spec/models/team_spec.rb
34
+ +++ b/spec/models/team_spec.rb
35
+ @@ -19 +19 @@ describe Team do
36
+ - it "has_many emojis" do
37
+ + it "has_many eojis" do
38
+ @@ -24,2 +24,2 @@ describe Team do
39
+ - describe "normalize attributes" do
40
+ - it "does not allow empty string values" do
41
+ + describe "normalize attrbtes" do
42
+ + it "does not allw empty sting values" do
43
+ DIFF
44
+ end
27
45
 
28
- let(:diff2) do
29
- <<~DIFF
30
- diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb
31
- index 19772f2a..9f614e20 100644
32
- --- a/spec/models/team_spec.rb
33
- +++ b/spec/models/team_spec.rb
34
- @@ -19 +19 @@ describe Team do
35
- - it "has_many emojis" do
36
- + it "has_many eojis" do
37
- @@ -24,2 +24,2 @@ describe Team do
38
- - describe "normalize attributes" do
39
- - it "does not allow empty string values" do
40
- + describe "normalize attrbtes" do
41
- + it "does not allw empty sting values" do
42
- DIFF
46
+ it "parses the diff correctly" do
47
+ expect(Devloop::DiffParser.call(diff1)).to eq(["spec/models/team_spec.rb:10", "spec/models/user_spec.rb:167"])
48
+ expect(Devloop::DiffParser.call(diff2)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
49
+ end
43
50
  end
44
51
 
45
- it "parses the diff correctly" do
46
- expect(Devloop::DiffParser.call(diff1)).to eq(["spec/models/team_spec.rb:10", "spec/models/user_spec.rb:167"])
47
- expect(Devloop::DiffParser.call(diff2)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
52
+ context "when the project root is different from the git root" do
53
+ let(:diff) do
54
+ <<~DIFF
55
+ diff --git a/src/spec/models/team_spec.rb b/src/spec/models/team_spec.rb
56
+ index 19772f2a..9f614e20 100644
57
+ --- a/src/spec/models/team_spec.rb
58
+ +++ b/src/spec/models/team_spec.rb
59
+ @@ -19 +19 @@ describe Team do
60
+ - it "has_many emojis" do
61
+ + it "has_many eojis" do
62
+ @@ -24,2 +24,2 @@ describe Team do
63
+ - describe "normalize attributes" do
64
+ - it "does not allow empty string values" do
65
+ + describe "normalize attrbtes" do
66
+ + it "does not allw empty sting values" do
67
+ DIFF
68
+ end
69
+
70
+ it "parses the diff correctly" do
71
+ allow_any_instance_of(Devloop::DiffParser).to receive(:git_root_path).and_return("/Users/username/projects/")
72
+ allow_any_instance_of(Devloop::DiffParser).to receive(:project_path).and_return("src/")
73
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
74
+ end
48
75
  end
49
76
  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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-07 00:00:00.000000000 Z
11
+ date: 2024-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake