segiddins-test-gem 2016.06.09.23.06.25 → 2016.06.09.23.21.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/app.rb +34 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 584a886edbba461b6409fb60d7aedb0ac63be28f
4
- data.tar.gz: b0bc849813f3743cc50febe352dc814658d5c3b0
3
+ metadata.gz: 5709fba2e5dac8403ef75478b1a3a7013e2d172d
4
+ data.tar.gz: 138c5f2f06751f4b996583f0f874fff7b4bfa933
5
5
  SHA512:
6
- metadata.gz: 9f6e18145d4257973db304c14622306b37535bbae01d19038f154c43e4764500a3a7aef021bdfd1cbe796162c5406a29acb3d3ba89c2402974b43c9d9f6c5e48
7
- data.tar.gz: 41a5c92a98d3194e6e402847367e0734aab3019584f12a95cbf129706928324aaf320b5ed03b3f3199f6198ea266af5bad5e5fb2e2ce0574e7899b71273adadd
6
+ metadata.gz: c961622b31ca03de5fe44990b646135fa8a4ea7e3a236e1f725d9e7a70490a57c9f85eb7b414b68acd2c1319158a4bd7e819247b262b90efbaf072ab08dda256
7
+ data.tar.gz: 5f4b282c4dc4887d62f73cce660a92af15195821dea87a7651d7217d129b3b743af8c41ad9f90354998ef296a1989ca39d8a330cf25c30f953045ef19ee1052e
data/app.rb CHANGED
@@ -7,6 +7,7 @@ require "rubygems/package"
7
7
  require 'rubygems/gem_runner'
8
8
 
9
9
  Dotenv.load
10
+ Gem.configuration.rubygems_api_key = ENV.fetch("RUBYGEMS_API_KEY")
10
11
 
11
12
  def get_json(host, path)
12
13
  json = Net::HTTP.get(host, path)
@@ -24,13 +25,23 @@ def push!(name, version)
24
25
  s.summary = 'test'
25
26
  end
26
27
  file = Gem::Package.build(spec)
27
- Gem::GemRunner.new.run(%W(push #{file}))
28
+ Gem::GemRunner.new.run(%W(push #{file} --verbose))
29
+ ensure
30
+ File.delete(file)
28
31
  end
29
32
 
30
33
  def get_dependency_api(gem_name)
31
34
  get_json('index.rubygems.org', "/api/v1/dependencies.json?gems=#{gem_name}")
32
35
  end
33
36
 
37
+ def get_versions
38
+ Net::HTTP.get('index.rubygems.org', '/versions')
39
+ end
40
+
41
+ def get_info(name)
42
+ Net::HTTP.get('index.rubygems.org', "/info/#{name}")
43
+ end
44
+
34
45
  get "/" do
35
46
  halt 401, "token does not match" unless ENV["TOKEN"] == params['token']
36
47
 
@@ -38,9 +49,29 @@ get "/" do
38
49
  gem_name = ENV.fetch('GEM_NAME') { 'segiddins-test-gem' }
39
50
 
40
51
  dependency_endpoint = get_dependency_api(gem_name)
52
+ versions = get_versions.lines
53
+ info = get_info(gem_name).lines
41
54
 
42
55
  push!(gem_name, version)
43
56
 
44
- new_gem = dependency_endpoint - get_dependency_api(gem_name)
45
- halt new_gem.to_json
57
+ new_gem = get_dependency_api(gem_name) - dependency_endpoint
58
+ case new_gem.size
59
+ when 0 then halt 404, "gem not added to dependency API"
60
+ when 1 then halt 404, "wrong gem added: #{new_gem}" unless new_gem.values_at('name', 'version') == [gem_name, version]
61
+ else halt 404, "too many new gems added: #{new_gem}"
62
+ end
63
+
64
+ new_versions = versions - get_versions.lines
65
+ unless new_versions.find { |l| l == "#{gem_name} #{version}" }
66
+ halt 404, "gem not added to versions file"
67
+ end
68
+
69
+ new_info = get_info(gem_name).lines - info
70
+ case new_info.size
71
+ when 0 then halt 404, "gem not added to dependency API"
72
+ when 1 then halt 404, "wrong gem added: #{new_info}" unless new_info =~ /^#{gem_name} #{version}/
73
+ else halt 404, "too many new gems added: #{new_info}"
74
+ end
75
+
76
+ halt "successfully pushed #{gem_name}-#{version}"
46
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: segiddins-test-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 2016.06.09.23.06.25
4
+ version: 2016.06.09.23.21.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - example@example.com