atlassian_plugin_installer 0.1.0 → 0.1.1

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: 6d9e9674f7327b86c97ceaecf0222b6e64896c89
4
- data.tar.gz: 18320e51a9a662d065f0262703cf2cdb2e63fef4
3
+ metadata.gz: 2b07b132bbd8fc58db14b6f41eb0b5b766cd1445
4
+ data.tar.gz: fda0c0d47c79e8fb799e61f05124eca70356a6f6
5
5
  SHA512:
6
- metadata.gz: 07c913308e6e16667b42779127a0e74f6c4f6c2be6a17a9b3adc23d1fdfa1bd21317bd8619f92b9d90f019e94cc3e7f7064a7efcb85a23d8b27b8d3946161112
7
- data.tar.gz: 7a3910f7d3956dd2d24d487f3f7396755a29d0fa89ee3e22e1b400ebdde6531c532dc805df2862feab724691d042657029279f8a0ff6b185bf04a547d52e7d3c
6
+ metadata.gz: 30c8a4670edab8993e805cd5fd91eaf6d393fe56927ebfb66036bffc13d6f16131922a1fa6563af024c01ee8ce12d9f289ca7cdd00f39f2bf022446da7a0618c
7
+ data.tar.gz: f8d1c767b274d573d7b562f44e63d7d582a57882a9c665962ed62b8a9532fb3f95be7d35c853ee5f232c3d5fd45a334a852ffb0bac2558ac5a6b6a9fa63d8de5
@@ -12,7 +12,7 @@ rvm:
12
12
  deploy:
13
13
  provider: rubygems
14
14
  api_key:
15
- secure: RiPkeHQ754HszIdlHOs955XTVnquIUZiIwd5hXFatTIw6dp0hBEKVILqkB5OzO2vo2rlPImiEb8KBHL33izEYyAIS9pKM8kGwAIef8Q/qFxzknVAJMPQVoLusApS3XQ2MZUe08ChBnaPrpUQxWFWKvMH3kuHC44QfQqaOnO/jQJ+kTlHXsSI2norcpQfhTGsoZL68w4oiuQ0me+dt0xf3tbgMaNYc3QoWdzQFZB6H9anGBKYzAjh5vs4JV4BA8oDnRgDMWG0x0OtHq4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OztmqhUeyOLzB1ou4Y4SsLB6vBdd378uEjSgw=
16
16
  gem: atlassian_plugin_installer
17
17
  on:
18
18
  tags: true
data/README.md CHANGED
@@ -14,6 +14,7 @@ atlassian_plugin_installer admin_username admin_password application_url plugin_
14
14
  * marketplace_username = "mbrehovsky@adaptavist.com"
15
15
  * marketplace_password = "super_secret_password"
16
16
  * # timebomb license
17
+ * application_version = "7.2.7"
17
18
 
18
19
  license = "AAABCA0ODAoPeNpdj01PwkAURffzKyZxZ1IyUzARkllQ24gRaQMtGnaP8VEmtjPNfFT59yJVFyzfu
19
20
  bkn796Ux0Bz6SmbUM5nbDzj97RISxozHpMUnbSq88poUaLztFEStUN6MJZ2TaiVpu/YY2M6tI6sQ
@@ -10,20 +10,45 @@ plugin_version = ARGV[4]
10
10
  marketplace_username = ARGV[5]
11
11
  marketplace_password = ARGV[6] == "" ? ENV['MARKETPLACE_PASS'] : ARGV[6]
12
12
  license = ARGV[7]
13
+ application_version = ARGV[8]
13
14
 
14
- if !(admin_username and admin_password and application_url and plugin_key and plugin_version and marketplace_username and marketplace_password)
15
- puts "Usage: atlassian_plugin_installer admin_username admin_password application_url plugin_key plugin_version marketplace_username marketplace_password"
15
+ if !(admin_username and admin_password and application_url and plugin_key and (plugin_version or application_version) and marketplace_username and marketplace_password)
16
+ puts "Usage: atlassian_plugin_installer admin_username admin_password application_url plugin_key plugin_version marketplace_username marketplace_password <license> <application_version>"
17
+ puts "Admin pass can be passed as ADMIN_PASS, marketplace access password as MARKETPLACE_PASS environment variable."
16
18
  exit
17
19
  end
18
20
 
19
21
  # retrieve build number for plugin version
20
22
  marketplace = AtlassianPluginInstaller::MarketplaceAccessor.new(marketplace_username, marketplace_password)
21
- plugin_build_number = marketplace.resolve_build_number_from_marketplace(plugin_key, plugin_version)
23
+ if (plugin_version and plugin_version != "")
24
+ plugin_build_number = marketplace.resolve_build_number_from_marketplace(plugin_key, plugin_version)
25
+ elsif (application_version and application_version != "")
26
+ plugin_build_number = marketplace.get_compatible_plugin_build_number_for_atlassian_product_version(plugin_key, application_version, "jira", "server")
27
+ else
28
+ puts "plugin_version or application_version must not be empty"
29
+ end
30
+
31
+ raise "Can not determine build number for #{plugin_key} with provided version #{plugin_version} and/or application version #{application_version}" unless plugin_build_number
22
32
 
23
33
  installer = AtlassianPluginInstaller::AtlassianPluginInstaller.new(application_url, admin_username, admin_password)
24
- # request access token
25
- token = installer.fetch_application_access_token
34
+ # wait for the application to start and fetch the token
35
+ token = nil
36
+ counter = 0
37
+ retries = 20
38
+ sleep_time = 10
39
+ while (!token and counter < retries) do
40
+ status, token = installer.fetch_application_access_token
41
+ if status != 200
42
+ puts "Token not found, status received: #{status}, retrying in #{sleep_time}, try #{counter}/#{retries}"
43
+ sleep(sleep_time)
44
+ end
45
+ counter=counter+1
46
+ end
26
47
 
48
+ unless token
49
+ puts "Can not fetch the token from #{application_url}. Is it running and are the creds ok?"
50
+ exit
51
+ end
27
52
  # install plugin using the token
28
53
  installer.install_plugin(plugin_key, plugin_build_number, token)
29
54
 
@@ -31,6 +56,6 @@ unless (installer.installation_completed(plugin_key))
31
56
  raise "Installation failed, plugin not available."
32
57
  end
33
58
 
34
- if license
59
+ if license and license != ""
35
60
  installer.install_license(plugin_key, license)
36
61
  end
@@ -21,9 +21,7 @@ module AtlassianPluginInstaller
21
21
  request.initialize_http_header({"Accept" => "application/vnd.atl.plugins.installed+json"})
22
22
  request.basic_auth(@admin_username, @admin_password)
23
23
  response = http.request(request)
24
- token = response['upm-token'] # parse access token
25
- raise "Can not retrieve token from #{@application_url} with #{@admin_username}" unless token
26
- token
24
+ return response.code, response['upm-token'] # parse access token
27
25
  end
28
26
 
29
27
  # Installs plugin
@@ -1,3 +1,3 @@
1
1
  module AtlassianPluginInstaller
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -15,20 +15,90 @@ module AtlassianPluginInstaller
15
15
 
16
16
  def resolve_build_number_from_marketplace(plugin_key, plugin_version)
17
17
  puts "Getting build_number from marketplace for #{plugin_key} and version #{plugin_version}"
18
+ details = get_plugin_details_for_version(plugin_key, plugin_version)
19
+ plugin_build_number = details['buildNumber']
20
+ raise "Can not find build number for plugin #{plugin_key} #{plugin_version}" unless plugin_build_number
21
+ plugin_build_number
22
+ end
23
+
24
+ def get_plugin_details_for_version(plugin_key, plugin_version)
25
+ puts "Getting plugin details from marketplace for #{plugin_key} and version #{plugin_version}"
18
26
  if plugin_version == "latest"
19
27
  url = "#{MARKETPLACE_ADDONS_URL}/#{plugin_key}/versions/latest"
20
28
  else
21
29
  url = "#{MARKETPLACE_ADDONS_URL}/#{plugin_key}/versions/name/#{plugin_version}"
22
30
  end
31
+ make_get_request(url)
32
+ end
33
+
34
+ # returns list of versions for plugin
35
+ def get_plugin_versions(plugin_key)
36
+ result = []
37
+ # https://marketplace.atlassian.com/rest/2/addons/com.onresolve.jira.groovy.groovyrunner/versions
38
+ url = "#{MARKETPLACE_ADDONS_URL}/#{plugin_key}/versions"
39
+ response = make_get_request(url)
40
+ if response['_embedded'] and response['_embedded']['versions']
41
+ response['_embedded']['versions'].each do |version|
42
+ result << version['name']
43
+ end
44
+ end
45
+ result
46
+ end
47
+
48
+ # Plugin details contains:
49
+ # "compatibilities": [
50
+ # {
51
+ # "application": "jira",
52
+ # "hosting": {
53
+ # "server": {
54
+ # "min": {
55
+ # "build": 64014,
56
+ # "version": "6.4"
57
+ # },
58
+ # "max": {
59
+ # "build": 64029,
60
+ # "version": "6.4.14"
61
+ # }
62
+ # }
63
+ # }
64
+ # }
65
+ # ]
66
+ def get_compatible_plugin_build_number_for_atlassian_product_version(plugin_key, product_version, product_name="jira", product_hosting="server")
67
+ puts "Seraching for compatible plugin version for plugin #{plugin_key} and product version #{product_version}"
68
+ required_version = Gem::Version.new(product_version)
69
+ get_plugin_versions(plugin_key).each do |version|
70
+ puts "Inspecting #{plugin_key} version #{version}"
71
+ version_details = get_plugin_details_for_version(plugin_key, version)
72
+ compatibilities = version_details['compatibilities']
73
+ if compatibilities
74
+ compatibilities.each do |comp|
75
+ if ( comp['application'] and comp['application'] == product_name and comp['hosting'] and comp['hosting'][product_hosting])
76
+ compatibility_with = comp['hosting'][product_hosting]
77
+ min_version = compatibility_with["min"]["version"]
78
+ max_version = compatibility_with["max"]["version"]
79
+ if (Gem::Version.new(max_version) >= required_version and
80
+ Gem::Version.new(min_version) <= required_version)
81
+ # add condition and dont break if searching for the highest
82
+ # if found return the buildNumber
83
+ return version_details['buildNumber']
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ nil
90
+ end
91
+
92
+ private
93
+
94
+ def make_get_request(url)
23
95
  uri = URI(url)
24
96
  http = Net::HTTP.new(uri.host, uri.port)
25
97
  http.use_ssl = url.start_with? "https"
26
98
  request = Net::HTTP::Get.new(uri.request_uri)
27
99
  request.basic_auth(@marketplace_username, @marketplace_password)
28
100
  response = http.request(request)
29
- plugin_build_number = JSON.parse(response.body)['buildNumber'] # parse access token
30
- raise "Can not find build number for plugin #{plugin_key} #{plugin_version}" unless plugin_build_number
31
- plugin_build_number
101
+ JSON.parse(response.body)
32
102
  end
33
103
  end
34
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlassian_plugin_installer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Brehovsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.6.8
79
+ rubygems_version: 2.4.5
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Installs JIRA plugin using UPM