gergich 0.1.9 → 0.1.10

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: e2d7f7876019c563dcfb6312aee7d29b1aa49303
4
- data.tar.gz: dde10dbf52e3f9b56694b656acf54a7bbb39a7bb
3
+ metadata.gz: 4a83e06009221c6f023ad9abb756eb7056d73c41
4
+ data.tar.gz: ddaf87be3594c80b6f4fad98f989d02cf5980e3b
5
5
  SHA512:
6
- metadata.gz: 27c67980ae7aeaaa6c2846dff79f945d35c6ce95957213a1f2c7ee39498ef899824cfcedae2e1560fcd997e722d4ed58d2e8ee8f93917db88f896fd008a64e40
7
- data.tar.gz: c990a1379e48090395d45cb2438630d6bdda86a645717180e1d3a8b4d2e1aa0bf09d2812453f595fb00a7f12757a0bc6f5310e314b3b8170babce7f7a0d5f066
6
+ metadata.gz: d4858b253d58eb97c5f8c8c41eb89edddd100061fbcf80609a7c9f61c7cda2cd7a61537352c15a036e7ad4ac33714a134f4e8d2c8700e74976d9bfd2fab72a3f
7
+ data.tar.gz: bfb624112eaf912a283836a46be4768eb7898b6042494b5e9f230c9f4f18e482f5c1e5aa744622f3c364df702e273a5c0c3a36e8734e8a2b4a6fa29dce7facd9
@@ -51,7 +51,7 @@ module Gergich
51
51
  if Gergich.use_git?
52
52
  Gergich.git("diff-tree --no-commit-id --name-only -r #{ref}").split
53
53
  else
54
- raw = API.get("/changes/#{change_id}/revisions/#{revision_id}/patch", { raw: true })
54
+ raw = API.get("/changes/#{change_id}/revisions/#{revision_id}/patch", raw: true)
55
55
  Base64.decode64(raw)
56
56
  .scan(%r{^diff --git a/.*? b/(.*?)$})
57
57
  .flatten
@@ -204,11 +204,11 @@ module Gergich
204
204
  end
205
205
 
206
206
  def post(url, body, options = {})
207
- perform(:post, url, options.merge({ body: body }))
207
+ perform(:post, url, options.merge(body: body))
208
208
  end
209
209
 
210
210
  def put(url, body, options = {})
211
- perform(:put, url, options.merge({ body: body }))
211
+ perform(:put, url, options.merge(body: body))
212
212
  end
213
213
 
214
214
  private
@@ -1,3 +1,4 @@
1
+ require_relative "../gergich"
1
2
  require "English"
2
3
 
3
4
  module Gergich
@@ -20,31 +21,44 @@ module Gergich
20
21
  end
21
22
 
22
23
  class << self
23
- def run(format, command)
24
+ def run(format, command, add_comments: true, suppress_output: false)
24
25
  captor = load_captor(format)
25
26
 
26
- exit_code, output = run_command(command)
27
+ exit_code, output = run_command(command, suppress_output: suppress_output)
27
28
  comments = captor.new.run(output.gsub(/\e\[\d+m/m, ""))
29
+ comments.each do |comment|
30
+ comment[:path] = relativize(comment[:path])
31
+ end
28
32
 
29
33
  draft = Gergich::Draft.new
30
34
  skip_paths = (ENV["SKIP_PATHS"] || "").split(",")
31
- comments.each do |comment|
32
- next if skip_paths.any? { |path| comment[:path].start_with?(path) }
33
- draft.add_comment comment[:path], comment[:position],
34
- comment[:message], comment[:severity]
35
+ if add_comments
36
+ comments.each do |comment|
37
+ next if skip_paths.any? { |path| comment[:path].start_with?(path) }
38
+ draft.add_comment comment[:path], comment[:position],
39
+ comment[:message], comment[:severity]
40
+ end
35
41
  end
36
42
 
37
- exit_code
43
+ [exit_code, comments]
44
+ end
45
+
46
+ def base_path
47
+ @base_path ||= File.expand_path(GERGICH_GIT_PATH) + "/"
48
+ end
49
+
50
+ def relativize(path)
51
+ path.sub(base_path, "")
38
52
  end
39
53
 
40
- def run_command(command)
54
+ def run_command(command, suppress_output: false)
41
55
  exit_code = 0
42
56
 
43
57
  if command == "-"
44
- output = wiretap($stdin)
58
+ output = wiretap($stdin, suppress_output)
45
59
  else
46
60
  IO.popen("#{command} 2>&1", "r+") do |io|
47
- output = wiretap(io)
61
+ output = wiretap(io, suppress_output)
48
62
  end
49
63
  exit_code = $CHILD_STATUS.exitstatus
50
64
  end
@@ -52,10 +66,10 @@ module Gergich
52
66
  [exit_code, output]
53
67
  end
54
68
 
55
- def wiretap(io)
69
+ def wiretap(io, suppress_output)
56
70
  output = ""
57
71
  io.each do |line|
58
- $stdout.puts line
72
+ $stdout.puts line unless suppress_output
59
73
  output << line
60
74
  end
61
75
  output
@@ -191,7 +191,8 @@ commands["capture"] = {
191
191
  summary: "Run a command and translate its output into `gergich comment` calls",
192
192
  action: ->(format, command) {
193
193
  require_relative "../../gergich/capture"
194
- exit Gergich::Capture.run(format, command)
194
+ status, = Gergich::Capture.run(format, command)
195
+ exit status
195
196
  },
196
197
  help: ->() {
197
198
  <<-TEXT
@@ -3,25 +3,24 @@ require_relative "../../lib/gergich/capture"
3
3
  RSpec.describe Gergich::Capture do
4
4
  let!(:draft) { double }
5
5
 
6
+ let :output do
7
+ <<-OUTPUT
8
+ #{path}
9
+ 4:21 error Missing semicolon semi
10
+ OUTPUT
11
+ end
12
+
6
13
  before do
7
14
  allow(Gergich::Draft).to receive(:new).and_return(draft)
15
+ $stdin = StringIO.new(output)
8
16
  end
9
17
 
10
- context "stdin" do
11
- let :output do
12
- <<-OUTPUT
13
- jsapp/models/user.js
14
- 4:21 error Missing semicolon semi
15
- OUTPUT
16
- end
17
-
18
- before do
19
- $stdin = StringIO.new(output)
20
- end
18
+ after do
19
+ $stdin = STDIN
20
+ end
21
21
 
22
- after do
23
- $stdin = STDIN
24
- end
22
+ context "stdin" do
23
+ let(:path) { "jsapp/models/user.js" }
25
24
 
26
25
  it "should catch errors" do
27
26
  expect(draft).to receive(:add_comment).with(
@@ -30,7 +29,7 @@ OUTPUT
30
29
  "[eslint] Missing semicolon",
31
30
  "error"
32
31
  )
33
- described_class.run("eslint", "-")
32
+ described_class.run("eslint", "-", suppress_output: true)
34
33
  end
35
34
 
36
35
  it "shouldn't eat stdin" do
@@ -39,4 +38,36 @@ OUTPUT
39
38
  described_class.run("eslint", "-")
40
39
  end
41
40
  end
41
+
42
+ context "absolute paths" do
43
+ before do
44
+ allow(described_class).to receive(:base_path).and_return("/the/directory/")
45
+ end
46
+
47
+ context "under us" do
48
+ let(:path) { "/the/directory/jsapp/models/user.js" }
49
+ it "should be relativized" do
50
+ expect(draft).to receive(:add_comment).with(
51
+ "jsapp/models/user.js",
52
+ 4,
53
+ "[eslint] Missing semicolon",
54
+ "error"
55
+ )
56
+ described_class.run("eslint", "-", suppress_output: true)
57
+ end
58
+ end
59
+
60
+ context "elsewhere" do
61
+ let(:path) { "/other/directory/jsapp/models/user.js" }
62
+ it "should not be relativized" do
63
+ expect(draft).to receive(:add_comment).with(
64
+ "/other/directory/jsapp/models/user.js",
65
+ 4,
66
+ "[eslint] Missing semicolon",
67
+ "error"
68
+ )
69
+ described_class.run("eslint", "-", suppress_output: true)
70
+ end
71
+ end
72
+ end
42
73
  end
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Gergich::API do
2
- let(:result) { double(:result, { body: "Not Found: 1234" }) }
2
+ let(:result) { double(:result, body: "Not Found: 1234") }
3
3
 
4
4
  before :each do
5
5
  allow(HTTParty).to receive(:send).and_return(result)
@@ -13,14 +13,15 @@ end
13
13
 
14
14
  RSpec.describe Gergich::Draft do
15
15
  let!(:draft) do
16
- commit = double(:commit, {
16
+ commit = double(
17
+ :commit,
17
18
  files: [
18
19
  "foo.rb",
19
20
  "bar/baz.lol"
20
21
  ],
21
22
  revision_id: "test",
22
23
  change_id: "test"
23
- })
24
+ )
24
25
  described_class.new commit
25
26
  end
26
27
 
@@ -36,12 +37,12 @@ RSpec.describe Gergich::Draft do
36
37
 
37
38
  it "includes file comments" do
38
39
  draft.add_comment "foo.rb", 1, "fix foo", "info"
39
- expect(subject).to eq({ "foo.rb" => [{ line: 1, message: "[INFO] fix foo" }] })
40
+ expect(subject).to eq("foo.rb" => [{ line: 1, message: "[INFO] fix foo" }])
40
41
  end
41
42
 
42
43
  it "includes COMMIT_MSG comments" do
43
44
  draft.add_comment "/COMMIT_MSG", 1, "fix commit", "info"
44
- expect(subject).to eq({ "/COMMIT_MSG" => [{ line: 1, message: "[INFO] fix commit" }] })
45
+ expect(subject).to eq("/COMMIT_MSG" => [{ line: 1, message: "[INFO] fix commit" }])
45
46
  end
46
47
 
47
48
  it "doesn't include orphaned file comments" do
@@ -89,10 +90,10 @@ RSpec.describe Gergich::Draft do
89
90
  draft.add_label "Code-Review", -2
90
91
  draft.add_label "Code-Review", 1
91
92
 
92
- expect(subject).to eq({
93
+ expect(subject).to eq(
93
94
  "QA-Review" => -1,
94
95
  "Code-Review" => -2
95
- })
96
+ )
96
97
  end
97
98
 
98
99
  it "disallows \"Verified\"" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gergich
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.5.1
158
+ rubygems_version: 2.2.5
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Command-line tool for adding Gerrit comments