class AtlassianAppVersions::AbstractProduct
A Plugin
or App
. This class assumes the MPAC API will have info about the product.
Constants
- JAC_URL
Attributes
Public Class Methods
Initialize with a MPAC key (e.g. “jira” or “com.pyxis.greenhopper.jira”)
# File lib/atlassian_app_versions.rb, line 24 def initialize(key) @key=key end
Public Instance Methods
# File lib/atlassian_app_versions.rb, line 131 def allVersions raise "Override me!" end
JQL for all issues resolved after fromVer
up to and including toVer
.
# File lib/atlassian_app_versions.rb, line 29 def allissuesJQL(fromVer=nil, toVer=nil) templateJQL(fromVer, toVer) end
URL for all issues resolved after fromVer
up to and including toVer
.
# File lib/atlassian_app_versions.rb, line 52 def allissuesURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(allissuesJQL(fromVer, toVer))}" end
JQL for all Bugs resolved after fromVer
up to and including toVer
.
# File lib/atlassian_app_versions.rb, line 34 def bugsJQL(fromVer=nil, toVer=nil) "issuetype=Bug AND " + templateJQL(fromVer, toVer) end
URL for all Bugs resolved after fromVer
up to and including toVer
.
# File lib/atlassian_app_versions.rb, line 57 def bugsURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(bugsJQL(fromVer, toVer))}" end
JQL for all features resolved after fromVer
up to and including toVer
.
# File lib/atlassian_app_versions.rb, line 39 def featuresJQL(fromVer=nil, toVer=nil) "issuetype!=Bug AND " + templateJQL(fromVer, toVer) end
URL for all features resolved after fromVer
up to and including toVer
.
# File lib/atlassian_app_versions.rb, line 62 def featuresURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(featuresJQL(fromVer, toVer))}" end
private
# 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
Fetch the versions as they exist on JAC
# 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
Display all 'properties' of the app/plugin. These can be used as methods, e.g. 'jira.name' or 'plugin.summary'
# File lib/atlassian_app_versions.rb, line 139 def keys marketplaceJSON.keys end
# File lib/atlassian_app_versions.rb, line 134 def latest allVersions.first end
# 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
# 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
“plugins” or “applications”
# File lib/atlassian_app_versions.rb, line 171 def product_type raise "Override me!" end
Return a 'project in (…)' JQL clause.
# 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
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).
# 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
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.
# File lib/atlassian_app_versions.rb, line 67 def recentbugsURL(fromVer=nil, toVer=nil) JAC_URL + "/issues/?jql=#{CGI::escape(recentbugsJQL(fromVer, toVer))}" end
# File lib/atlassian_app_versions.rb, line 151 def respond_to_missing?(name, include_private = false) keys.member? name.to_s || super end
JQL common between bugs and features
# 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
Find a specific version
# File lib/atlassian_app_versions.rb, line 126 def version(ver) allVersions.find { |v| v.version == ver } end
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.
# 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
Return a comma-separated list of JAC version strings, given an Array of versions
# 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