Skip to content

Commit 3df23e4

Browse files
committed
Fix beta release asset name parsing
1 parent a4e760e commit 3df23e4

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ gem 'rb-inotify', :require => false
1313
gem 'rb-fsevent', :require => false
1414
gem 'rb-fchange', :require => false
1515
gem 'nanoc-cachebuster'
16+
17+
group :test do
18+
gem 'rspec'
19+
end

Gemfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ GEM
1010
colored (1.2)
1111
cri (2.6.1)
1212
colored (~> 1.2)
13+
diff-lcs (1.2.5)
1314
em-websocket (0.5.1)
1415
eventmachine (>= 0.12.9)
1516
http_parser.rb (~> 0.6.0)
@@ -61,6 +62,19 @@ GEM
6162
rb-inotify (0.9.5)
6263
ffi (>= 0.5.0)
6364
redcarpet (3.2.0)
65+
rspec (3.5.0)
66+
rspec-core (~> 3.5.0)
67+
rspec-expectations (~> 3.5.0)
68+
rspec-mocks (~> 3.5.0)
69+
rspec-core (3.5.4)
70+
rspec-support (~> 3.5.0)
71+
rspec-expectations (3.5.0)
72+
diff-lcs (>= 1.2.0, < 2.0)
73+
rspec-support (~> 3.5.0)
74+
rspec-mocks (3.5.0)
75+
diff-lcs (>= 1.2.0, < 2.0)
76+
rspec-support (~> 3.5.0)
77+
rspec-support (3.5.0)
6478
slop (3.6.0)
6579
thor (0.19.1)
6680
timers (4.0.1)
@@ -84,3 +98,7 @@ DEPENDENCIES
8498
rb-fsevent
8599
rb-inotify
86100
redcarpet
101+
rspec
102+
103+
BUNDLED WITH
104+
1.11.2

lib/helpers/download.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,23 @@ def kind
100100
'Binary'
101101
end
102102

103-
# TODO(ts): validate
104103
def os
105-
name.split('.')[3].split('-').first
104+
base_name.split('.').last.split('-').first
106105
end
107106

108-
# TODO(ts): validate
109107
def arch
110-
name.split('.')[3].split('-').last
108+
base_name.split('.').last.split('-').last
111109
end
112110

113111
def size
114112
@data['size']
115113
end
114+
115+
private
116+
117+
def base_name
118+
name.chomp('.tar.gz').chomp('.zip')
119+
end
116120
end
117121

118122
module Helper

specs/download_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'rspec'
2+
require 'helpers/download'
3+
4+
describe Downloads::Asset do
5+
let(:asset) do
6+
Downloads::Asset.new({
7+
'name' => ' prometheus-1.2.0.freebsd-armv5.tar.gz',
8+
})
9+
end
10+
11+
let(:beta) do
12+
Downloads::Asset.new({
13+
'name' => 'alertmanager-0.5.0-beta.0.darwin-amd64.tar.gz',
14+
})
15+
end
16+
17+
describe '#os' do
18+
it 'extracts the operating system name' do
19+
expect(asset.os).to eql('freebsd')
20+
expect(beta.os).to eql('darwin')
21+
end
22+
end
23+
24+
describe '#arch' do
25+
it 'extracts the architecture' do
26+
expect(asset.arch).to eql('armv5')
27+
expect(beta.arch).to eql('amd64')
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)