class AtlassianAppVersions::AbstractProduct

A Plugin or App. This class assumes the MPAC API will have info about the product.

Constants

JAC_URL

Attributes

key[RW]

Public Class Methods

new(key) click to toggle source

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

allVersions() click to toggle source
# File lib/atlassian_app_versions.rb, line 131
def allVersions
    raise "Override me!"
end
allissuesJQL(fromVer=nil, toVer=nil) click to toggle source

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
allissuesURL(fromVer=nil, toVer=nil) click to toggle source

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
bugsJQL(fromVer=nil, toVer=nil) click to toggle source

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
bugsURL(fromVer=nil, toVer=nil) click to toggle source

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
featuresJQL(fromVer=nil, toVer=nil) click to toggle source

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
featuresURL(fromVer=nil, toVer=nil) click to toggle source

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
jacKey() click to toggle source

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
jacVersions() click to toggle source

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
keys() click to toggle source

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
latest() click to toggle source
# File lib/atlassian_app_versions.rb, line 134
def latest
    allVersions.first
end
marketplaceJSON() click to toggle source
# 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
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# 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
product_type() click to toggle source

“plugins” or “applications”

# File lib/atlassian_app_versions.rb, line 171
def product_type
    raise "Override me!"
end
projectJQL(fromVer=nil, toVer=nil) click to toggle source

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
recentbugsJQL(fromVer, toVer=nil, includedVersionCount=3, pastVersionsToIgnore=50) click to toggle source

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
recentbugsURL(fromVer=nil, toVer=nil) click to toggle source

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
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# 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) click to toggle source

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
version(ver) click to toggle source

Find a specific version

# File lib/atlassian_app_versions.rb, line 126
def version(ver)
    allVersions.find { |v| v.version == ver }
end
versions(fromVer=nil, toVer=nil) click to toggle source

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
versionsListJQL(versions) click to toggle source

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