Class: AtlassianAppVersions::AbstractProduct
- Inherits:
-
Object
- Object
- AtlassianAppVersions::AbstractProduct
- Defined in:
- lib/atlassian_app_versions.rb
Overview
A Plugin or App. This class assumes the MPAC API will have info about the product.
Constant Summary collapse
- JAC_URL =
"https://jira.atlassian.com"
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#allissuesJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL for all issues resolved after
fromVer
up to and includingtoVer
. -
#allissuesURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all issues resolved after
fromVer
up to and includingtoVer
. - #allVersions ⇒ Object
-
#bugsJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL for all Bugs resolved after
fromVer
up to and includingtoVer
. -
#bugsURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all Bugs resolved after
fromVer
up to and includingtoVer
. -
#featuresJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL for all features resolved after
fromVer
up to and includingtoVer
. -
#featuresURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all features resolved after
fromVer
up to and includingtoVer
. -
#initialize(key) ⇒ AbstractProduct
constructor
Initialize with a MPAC key (e.g. “jira” or “com.pyxis.greenhopper.jira”).
-
#jacKey ⇒ Object
private.
-
#jacVersions ⇒ Object
Fetch the versions as they exist on JAC.
-
#keys ⇒ Object
Display all ‘properties’ of the app/plugin.
- #latest ⇒ Object
- #marketplaceJSON ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
-
#product_type ⇒ Object
“plugins” or “applications”.
-
#projectJQL(fromVer = nil, toVer = nil) ⇒ Object
Return a ‘project in (…)’ JQL clause.
-
#recentbugsJQL(fromVer, toVer = nil, includedVersionCount = 3, pastVersionsToIgnore = 50) ⇒ Object
JQL for all new, unresolved Bugs introduced in the (up to) 3 versions before
toVer
, but afterfromVer
. -
#recentbugsURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all new, unresolved Bugs introduced after
fromVer
up to and includingtoVer
. - #respond_to_missing?(name, include_private = false) ⇒ Boolean
-
#templateJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL common between bugs and features.
-
#version(ver) ⇒ Object
Find a specific version.
-
#versions(fromVer = nil, toVer = nil) ⇒ Object
Find versions in a range, from
fromVer
(exclusive) totoVer
(inclusive). -
#versionsListJQL(versions) ⇒ Object
Return a comma-separated list of JAC version strings, given an Array of versions.
Constructor Details
#initialize(key) ⇒ AbstractProduct
Initialize with a MPAC key (e.g. “jira” or “com.pyxis.greenhopper.jira”)
24 25 26 |
# File 'lib/atlassian_app_versions.rb', line 24 def initialize(key) @key=key end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/atlassian_app_versions.rb', line 143 def method_missing(name, *args, &block) if keys and keys.member? name.to_s then marketplaceJSON[name.to_s] else super end end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
22 23 24 |
# File 'lib/atlassian_app_versions.rb', line 22 def key @key end |
Instance Method Details
#allissuesJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL for all issues resolved after fromVer
up to and including toVer
.
29 30 31 |
# File 'lib/atlassian_app_versions.rb', line 29 def allissuesJQL(fromVer=nil, toVer=nil) templateJQL(fromVer, toVer) end |
#allissuesURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all issues resolved after fromVer
up to and including toVer
.
52 53 54 |
# File 'lib/atlassian_app_versions.rb', line 52 def allissuesURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(allissuesJQL(fromVer, toVer))}" end |
#allVersions ⇒ Object
131 132 133 |
# File 'lib/atlassian_app_versions.rb', line 131 def allVersions raise "Override me!" end |
#bugsJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL for all Bugs resolved after fromVer
up to and including toVer
.
34 35 36 |
# File 'lib/atlassian_app_versions.rb', line 34 def bugsJQL(fromVer=nil, toVer=nil) "issuetype=Bug AND " + templateJQL(fromVer, toVer) end |
#bugsURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all Bugs resolved after fromVer
up to and including toVer
.
57 58 59 |
# File 'lib/atlassian_app_versions.rb', line 57 def bugsURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(bugsJQL(fromVer, toVer))}" end |
#featuresJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL for all features resolved after fromVer
up to and including toVer
.
39 40 41 |
# File 'lib/atlassian_app_versions.rb', line 39 def featuresJQL(fromVer=nil, toVer=nil) "issuetype!=Bug AND " + templateJQL(fromVer, toVer) end |
#featuresURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all features resolved after fromVer
up to and including toVer
.
62 63 64 |
# File 'lib/atlassian_app_versions.rb', line 62 def featuresURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(featuresJQL(fromVer, toVer))}" end |
#jacKey ⇒ Object
private
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/atlassian_app_versions.rb', line 157 def jacKey case @key when "jira-core" then "JRASERVER" when "jira-software" then ["JRASERVER", "JSWSERVER"] when "confluence" then ["CONFSERVER", "CRA"] when "gh" then"GHS" when "stash" then "BSERV" when "bitbucket" then "BSERV" when "fisheye" then "FE" when "com.pyxis.greenhopper.jira" then "JSWSERVER" end end |
#jacVersions ⇒ Object
Fetch the versions as they exist on JAC
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/atlassian_app_versions.rb', line 72 def jacVersions if ! @jacVersions then @jacVersions = jacKey.collect { |jacKey| url = JAC_URL + "/rest/api/2/project/#{jacKey}/versions" jsonStr = open(url).read JSON.parse(jsonStr).collect { |v| v["name"] } }.flatten.uniq end @jacVersions end |
#keys ⇒ Object
Display all ‘properties’ of the app/plugin. These can be used as methods, e.g. ‘jira.name’ or ‘plugin.summary’
139 140 141 |
# File 'lib/atlassian_app_versions.rb', line 139 def keys marketplaceJSON.keys end |
#latest ⇒ Object
134 135 136 |
# File 'lib/atlassian_app_versions.rb', line 134 def latest allVersions.first end |
#marketplaceJSON ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/atlassian_app_versions.rb', line 83 def marketplaceJSON if !@marketplaceJSON then mpacKey = case key when "jira-core", "jira-software" then # mpac still only knows about 'jira' "jira" when "stash" then "bitbucket" # MPAC actually redirects stash to bitbucket, but be nice and do it here. else key end url = "https://marketplace.atlassian.com/rest/1.0/#{product_type}/#{mpacKey}" begin jsonStr = open(url).read rescue OpenURI::HTTPError => error if error.io.status[0] == "404" then raise "No plugin with key '#{key}' found" else raise error end end @marketplaceJSON = JSON.parse( jsonStr ) end @marketplaceJSON end |
#product_type ⇒ Object
“plugins” or “applications”
171 172 173 |
# File 'lib/atlassian_app_versions.rb', line 171 def product_type raise "Override me!" end |
#projectJQL(fromVer = nil, toVer = nil) ⇒ Object
Return a ‘project in (…)’ JQL clause.
177 178 179 |
# File 'lib/atlassian_app_versions.rb', line 177 def projectJQL(fromVer=nil, toVer=nil) (jacKey.respond_to?(:each) ? "project in (#{jacKey.join(',')})" : "project=#{jacKey}") end |
#recentbugsJQL(fromVer, toVer = nil, includedVersionCount = 3, pastVersionsToIgnore = 50) ⇒ Object
JQL for all new, unresolved Bugs introduced in the (up to) 3 versions before toVer
, but after fromVer
. This means bugs reported against a version in the range, but not reported against an earlier version (up to pastVersionsToIgnore
old versions are considered, since some really old versions are missing from JAC and break the query).
44 45 46 47 48 49 |
# File 'lib/atlassian_app_versions.rb', line 44 def recentbugsJQL(fromVer, toVer=nil, includedVersionCount=3, pastVersionsToIgnore=50) new = versions(fromVer, toVer).first(includedVersionCount) old = versions.select { |v| v < new.last }.first(pastVersionsToIgnore) projectJQL(fromVer) + " AND issuetype=Bug AND affectedVersion in (#{versionsListJQL(new)}) AND affectedVersion not in (#{versionsListJQL(old)}) AND resolution is empty ORDER BY votes DESC, priority DESC, key DESC" end |
#recentbugsURL(fromVer = nil, toVer = nil) ⇒ Object
URL for all new, unresolved Bugs introduced after fromVer
up to and including toVer
. This means bugs reported against a version in the range, but not reported against an earlier version.
67 68 69 |
# File 'lib/atlassian_app_versions.rb', line 67 def recentbugsURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(recentbugsJQL(fromVer, toVer))}" end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
151 152 153 |
# File 'lib/atlassian_app_versions.rb', line 151 def respond_to_missing?(name, include_private = false) keys.member? name.to_s || super end |
#templateJQL(fromVer = nil, toVer = nil) ⇒ Object
JQL common between bugs and features
189 190 191 192 193 |
# File 'lib/atlassian_app_versions.rb', line 189 def templateJQL(fromVer=nil, toVer=nil) vers = versionsListJQL(versions(fromVer, toVer)) projectJQL(fromVer, toVer) + " AND fixVersion in (#{vers}) AND status in (Resolved, Closed, Soaking, \"Released to Server\") ORDER BY votes DESC, priority DESC, key DESC" end |
#version(ver) ⇒ Object
Find a specific version
126 127 128 |
# File 'lib/atlassian_app_versions.rb', line 126 def version(ver) allVersions.find { |v| v.version == ver } end |
#versions(fromVer = nil, toVer = nil) ⇒ Object
Find versions in a range, from fromVer
(exclusive) to toVer
(inclusive). If toVer
is omitted, all versions up to the latest are found. If fromVer
and toVer
are omitted, all versions are returned.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/atlassian_app_versions.rb', line 109 def versions(fromVer=nil, toVer=nil) # fromVer and toVer may be a string or a *Version if (!fromVer && !toVer) then allVersions else # allVersions is ordered most to least recent # If 'fromVer' was unspecified, count from the end (allVersions.size = last = oldest) fromIdx = fromVer ? allVersions.find_index { |v| v.version == fromVer.to_s } || ( raise "Couldn't find #{@key} fromVer #{fromVer}" ) : allVersions.size # If toVer was unspecified, count from the beginning (0 = newest) toIdx = toVer ? allVersions.find_index{ |v| v.version == toVer.to_s } || ( raise "Couldn't find #{@key} toVer #{toVer}" ) : 0 # fromIdx may be greater than toIdx, which the slice doesn't like, so get the max/min here from = [fromIdx, toIdx].min to = [fromIdx, toIdx].max allVersions.slice(from, (to - from)) end end |
#versionsListJQL(versions) ⇒ Object
Return a comma-separated list of JAC version strings, given an Array of versions
182 183 184 185 186 |
# File 'lib/atlassian_app_versions.rb', line 182 def versionsListJQL(versions) versions.inject([]) { |all, v| all << jacVersions.select { |jacVer| jacVer.start_with? v.version } }.flatten.uniq.collect { |vstr| "'#{vstr}'" }.join(", ") end |