gergich 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gergich.rb +20 -6
  3. data/spec/gergich_spec.rb +45 -6
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae5718f79f93916a7fdfbbe3bf316ef3b136001
4
- data.tar.gz: 632d2883f68a0f4d59a2873d5191b5ecffdc9d66
3
+ metadata.gz: ef236cdff9358a9799255dcd4ce0683f89eca6d2
4
+ data.tar.gz: 53cf76a1f2b0b490f03883f24b75b0d399b5e0fc
5
5
  SHA512:
6
- metadata.gz: 60daade2ff2d41045d134a34912d0251f08db4559bbadcb3d6fffcd596e1d5701dd0f26c3d4236fed832f73bc271791cc1e65d0e035bf88ac65d4ba3e131405c
7
- data.tar.gz: e92bd1b2b1bac1e9cb5037b2543f196966583908c8e20768334926ea0b03f328d981f2ae588eea3fcc5c52c57a41f8cc755104f456f0f0c2f33ab9f957bd4540
6
+ metadata.gz: fee27eccf19e051b3972975e4531de705ec5a20e517410994d3cc36d088d1e1fb3b9f06fa1a581930b1345b08be3793c01b432bfbf89fd33f608ca519170dd10
7
+ data.tar.gz: 90dc1b48b44b42504feb9d26b2aa0ebc39ff7acc7d2af648b818b0b1edcf71d8372ff1d0b2dca78c4ad27d6e7f08f15105f14a046ff08b0270e1338c4ed3bfb2
data/lib/gergich.rb CHANGED
@@ -239,14 +239,28 @@ module Gergich
239
239
  raise(GergichError, "need to set GERRIT_BASE_URL or GERRIT_HOST")
240
240
  end
241
241
 
242
+ def auth_config
243
+ if ENV["GERGICH_DIGEST_AUTH"]
244
+ {
245
+ digest_auth: {
246
+ username: GERGICH_USER,
247
+ password: ENV.fetch("GERGICH_KEY")
248
+ }
249
+ }
250
+ else
251
+ {
252
+ basic_auth: {
253
+ username: GERGICH_USER,
254
+ password: ENV.fetch("GERGICH_KEY")
255
+ }
256
+ }
257
+ end
258
+ end
259
+
242
260
  def prepare_options(options)
243
261
  options = {
244
- base_uri: base_uri + "/a",
245
- digest_auth: {
246
- username: GERGICH_USER,
247
- password: ENV.fetch("GERGICH_KEY")
248
- }
249
- }.merge(options)
262
+ base_uri: base_uri + "/a"
263
+ }.merge(auth_config).merge(options)
250
264
  if options[:body]
251
265
  options[:headers] ||= {}
252
266
  options[:headers]["Content-Type"] ||= "application/json"
data/spec/gergich_spec.rb CHANGED
@@ -1,13 +1,52 @@
1
1
  RSpec.describe Gergich::API do
2
- let(:result) { double(:result, body: "Not Found: 1234") }
2
+ context "bad change-id" do
3
+ let(:result) { double(:result, body: "Not Found: 1234") }
3
4
 
4
- before :each do
5
- allow(HTTParty).to receive(:send).and_return(result)
6
- allow(described_class).to receive(:prepare_options).and_return({})
5
+ before :each do
6
+ allow(HTTParty).to receive(:send).and_return(result)
7
+ allow(described_class).to receive(:prepare_options).and_return({})
8
+ end
9
+
10
+ it "provides helpful error when Change-Id not found" do
11
+ expect { described_class.get("/a/changes/1234") }
12
+ .to raise_error(/Cannot find Change-Id: 1234/)
13
+ end
7
14
  end
8
15
 
9
- it "provides helpful error when Change-Id not found" do
10
- expect { described_class.get("/a/changes/1234") }.to raise_error(/Cannot find Change-Id: 1234/)
16
+ context "GERGICH_DIGEST_AUTH exists" do
17
+ it "uses digest auth" do
18
+ original_basic_auth = ENV["GERGICH_DIGEST_AUTH"]
19
+ ENV["GERGICH_DIGEST_AUTH"] = "1"
20
+ original_gergich_key = ENV["GERGICH_KEY"]
21
+ ENV["GERGICH_KEY"] = "foo"
22
+ allow(described_class).to receive(:base_uri).and_return("https://gerrit.foobar.com")
23
+
24
+ expect(described_class.send(:prepare_options, {}))
25
+ .to match(
26
+ hash_including(
27
+ digest_auth: { username: "gergich", password: ENV["GERGICH_KEY"] }
28
+ )
29
+ )
30
+
31
+ ENV["GERGICH_DIGEST_AUTH"] = original_basic_auth
32
+ ENV["GERGICH_KEY"] = original_gergich_key
33
+ end
34
+ end
35
+
36
+ context "GERGICH_DIGEST_AUTH does not exist" do
37
+ it "uses basic auth" do
38
+ original_basic_auth = ENV["GERGICH_DIGEST_AUTH"]
39
+ ENV["GERGICH_DIGEST_AUTH"] = nil
40
+ original_gergich_key = ENV["GERGICH_KEY"]
41
+ ENV["GERGICH_KEY"] = "foo"
42
+ allow(described_class).to receive(:base_uri).and_return("https://gerrit.foobar.com")
43
+
44
+ expect(described_class.send(:prepare_options, {}))
45
+ .to match(hash_including(basic_auth: { username: "gergich", password: ENV["GERGICH_KEY"] }))
46
+
47
+ ENV["GERGICH_DIGEST_AUTH"] = original_basic_auth
48
+ ENV["GERGICH_KEY"] = original_gergich_key
49
+ end
11
50
  end
12
51
  end
13
52
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gergich
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -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.6.12
158
+ rubygems_version: 2.5.1
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Command-line tool for adding Gerrit comments