bard 1.7.1 → 1.7.3

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
  SHA256:
3
- metadata.gz: 175897a8e48c72c6af96276c46f3f2507f2f4cc1d31e0de2de9b8d16048a051c
4
- data.tar.gz: 4e315cf487080f1b819b4d25d23bfb5671785926b13dadc89202c12d30e4ba1f
3
+ metadata.gz: 68411db6b0d930d06cc7708835eaa23d10cbedc42eb905bec4065c47834f488a
4
+ data.tar.gz: e2488bd0f625e3aa7a87aa6f3334178dbdff49a19a7c020d2424b073dea3f999
5
5
  SHA512:
6
- metadata.gz: 1af07ec394121b0f6e283708d372243fd43cda458f014dacf6e97f3f67a27ad618b99e4fad5e8c74e279873bdee68e5af16705b0018016858ca75b2626e97106
7
- data.tar.gz: 72e2df39e321de356e01046e4b66e0ce378ad116643c777023a5b6a80a65af2d46544a36ab9831dd8df27a0be236841bc393e76cf5cb6073c83a3a887177de2e
6
+ metadata.gz: 1cc1f667c31694e70f54621b13d3871e74c011f4fd25ab80b66b6caa325fc89d878f4f4199d4adec314b599c4c9e8162ee12dd3e5830b255e9cfcde1c9504e06
7
+ data.tar.gz: 9f9be575ee8baa54d8f175c6a4c9227daa22b360343a1143736168d68b5f91697840819f9ed1f165b07e2cea2660c92bce2e466b72e87bf236f459cff304fed5
data/lib/bard/github.rb CHANGED
@@ -7,6 +7,12 @@ require "bard/ci/retryable"
7
7
  module Bard
8
8
  class Github < Struct.new(:project_name)
9
9
  include CI::Retryable
10
+
11
+ def initialize(project_name, api_key: nil)
12
+ super(project_name)
13
+ @api_key = api_key
14
+ end
15
+
10
16
  def get path, params={}
11
17
  request(path) do |uri|
12
18
  uri.query = URI.encode_www_form(params)
@@ -100,8 +106,8 @@ module Bard
100
106
 
101
107
  private
102
108
 
103
- def github_apikey
104
- @github_apikey ||= begin
109
+ def api_key
110
+ @api_key ||= begin
105
111
  raw = `git ls-remote -t git@github.com:botandrosedesign/secrets`
106
112
  raw[/github-apikey\|(.+)$/, 1]
107
113
  end
@@ -124,7 +130,7 @@ module Bard
124
130
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
125
131
  req = block.call(uri)
126
132
  req["Accept"] = "application/vnd.github+json"
127
- req["Authorization"] = "Bearer #{github_apikey}"
133
+ req["Authorization"] = "Bearer #{api_key}"
128
134
  req["X-GitHub-Api-Version"] = "2022-11-28"
129
135
  http.request(req)
130
136
  end
data/lib/bard/ping.rb CHANGED
@@ -8,16 +8,26 @@ module Bard
8
8
  end
9
9
 
10
10
  def call
11
- server.ping.reject do |url|
12
- response = get_response_with_redirect(url) rescue nil
13
- response.is_a?(Net::HTTPSuccess)
14
- end
11
+ server.ping.reject { |url| reachable?(url) }
15
12
  end
16
13
 
17
14
  private
18
15
 
16
+ def reachable?(url)
17
+ attempts = 0
18
+ begin
19
+ attempts += 1
20
+ response = get_response_with_redirect(url)
21
+ response.is_a?(Net::HTTPSuccess)
22
+ rescue StandardError
23
+ retry if attempts < 2
24
+ false
25
+ end
26
+ end
27
+
19
28
  def get_response_with_redirect uri_str, limit=5
20
- response = Net::HTTP.get_response(URI(uri_str))
29
+ uri = URI(uri_str)
30
+ response = http_get(uri)
21
31
 
22
32
  case response
23
33
  when Net::HTTPRedirection
@@ -25,11 +35,32 @@ module Bard
25
35
  puts "too many HTTP redirects"
26
36
  response
27
37
  else
28
- get_response_with_redirect(response["location"], limit - 1)
38
+ location = response["location"]
39
+ return response unless location
40
+
41
+ next_uri = begin
42
+ uri + location
43
+ rescue URI::InvalidURIError
44
+ URI(location)
45
+ end
46
+
47
+ get_response_with_redirect(next_uri, limit - 1)
29
48
  end
30
49
  else
31
50
  response
32
51
  end
33
52
  end
53
+
54
+ def http_get(uri)
55
+ Net::HTTP.start(
56
+ uri.host,
57
+ uri.port,
58
+ use_ssl: uri.scheme == "https",
59
+ open_timeout: 5,
60
+ read_timeout: 5,
61
+ ) do |http|
62
+ http.get(uri.request_uri)
63
+ end
64
+ end
34
65
  end
35
66
  end
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "1.7.1"
2
+ VERSION = "1.7.3"
3
3
  end
4
4
 
@@ -3,29 +3,58 @@ require "bard/ping"
3
3
 
4
4
  describe Bard::Ping do
5
5
  let(:server) { double("server", ping: ["http://example.com"]) }
6
+ let(:ping) { described_class.new(server) }
7
+
8
+ def success_response
9
+ Net::HTTPSuccess.new(1.0, "200", "OK")
10
+ end
11
+
12
+ def not_found_response
13
+ Net::HTTPNotFound.new(1.0, "404", "Not Found")
14
+ end
6
15
 
7
16
  context "when the server is reachable" do
8
- it "should return an empty array" do
9
- allow(Net::HTTP).to receive(:get_response).and_return(Net::HTTPSuccess.new(1.0, "200", "OK"))
10
- expect(Bard::Ping.call(server)).to be_empty
17
+ it "returns an empty array" do
18
+ allow(ping).to receive(:http_get).and_return(success_response)
19
+ expect(ping.call).to be_empty
11
20
  end
12
21
  end
13
22
 
14
23
  context "when the server is not reachable" do
15
- it "should return the url" do
16
- allow(Net::HTTP).to receive(:get_response).and_return(Net::HTTPNotFound.new(1.0, "404", "Not Found"))
17
- expect(Bard::Ping.call(server)).to eq(["http://example.com"])
24
+ it "returns the url" do
25
+ allow(ping).to receive(:http_get).and_return(not_found_response)
26
+ expect(ping.call).to eq(["http://example.com"])
18
27
  end
19
28
  end
20
29
 
21
30
  context "when there is a redirect" do
22
- it "should follow the redirect and return an empty array" do
31
+ it "follows the redirect and returns an empty array" do
23
32
  redirect_response = Net::HTTPRedirection.new(1.0, "301", "Moved Permanently")
24
- redirect_response["location"] = "http://example.com/new"
25
- success_response = Net::HTTPSuccess.new(1.0, "200", "OK")
26
- allow(Net::HTTP).to receive(:get_response).with(URI("http://example.com")).and_return(redirect_response)
27
- allow(Net::HTTP).to receive(:get_response).with(URI("http://example.com/new")).and_return(success_response)
28
- expect(Bard::Ping.call(server)).to be_empty
33
+ redirect_response["location"] = "/new"
34
+ allow(ping).to receive(:http_get).with(URI("http://example.com")).and_return(redirect_response)
35
+ allow(ping).to receive(:http_get).with(URI("http://example.com/new")).and_return(success_response)
36
+ expect(ping.call).to be_empty
37
+ end
38
+ end
39
+
40
+ context "when a transient error occurs" do
41
+ it "retries once before marking down" do
42
+ calls = 0
43
+ allow(ping).to receive(:http_get) do
44
+ calls += 1
45
+ raise Errno::ECONNRESET if calls == 1
46
+
47
+ success_response
48
+ end
49
+
50
+ expect(ping.call).to be_empty
51
+ end
52
+ end
53
+
54
+ context "when errors persist across retries" do
55
+ it "returns the url" do
56
+ allow(ping).to receive(:http_get).and_raise(Errno::ECONNREFUSED)
57
+ expect(ping.call).to eq(["http://example.com"])
29
58
  end
30
59
  end
31
60
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-12-11 00:00:00.000000000 Z
10
+ date: 2025-12-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor