cogShows different solutions to access JIRA from an XWiki instance
TypeSnippet
Category
Developed by

Vincent Massol

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

There are several solutions to access data from your online JIRA server:

In addition to this you can simply use JIRA's RSS URLs as demonstrated below. Also make sure to check out the JIRA Macro which uses the JIRA RSS URLs.

If all you need is query the JIRA server using the JIRA's RSS URLs is by far the best method (it's also the more performant one). On the other hand if you need to make modifications to JIRA then you should use one of the other methods.

Examples

Displays the summary of an issue

{{groovy}}
def url = "http://jira.xwiki.org/si/jira.issueviews:issue-xml/XWIKI-1000/XWIKI-1000.xml".toURL().text
def root = new XmlSlurper().parseText(url)

println "${root.channel.item.summary}"
{{/groovy}}

Displays the content of a list of issues

{{groovy}}
def jql = URLEncoder.encode("issueKey=XWIKI-1000 OR issueKey=XWIKI-1001", "UTF-8")
def columns = "field=type&field=key&field=summary&field=assignee&field=status&field=link"

def url = "http://jira.xwiki.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=${jql}&${columns}".toURL().text
def root = new XmlSlurper().parseText(url)

println "|=Type|=Id|=Summary|=Assignee|=Status"
root.channel.item.each() {
    println "|[[image:${[email protected]}]]|[[${it.key}>>${it.link}]]|${it.summary}|${it.assignee}|[[image:${[email protected]}]]"
}
{{/groovy}}

Result:

issuelist.png

Computes total time spent

{{groovy}}
import groovy.json.*

def jql = "project = NUMPORTAL AND component = 17-002 AND component = 'Out of Scope'"
def url = "https://jira.xwikisas.com/rest/api/2/search?jql=${java.net.URLEncoder.encode(jql)}&os_username=<usernamehere>&os_password=<userpasswordhere>&os_authType=basic&field=timespent".toURL().text
def root = new JsonSlurper().parseText(url)

int totalTimespent = 0
root.issues.each() { issue ->
  def spent = issue.fields.timespent
 if (spent) {
    totalTimespent += spent
 }
}
println "Total time spent = ${totalTimespent} seconds"
{{/groovy}}
Tags: jira REST
     

Get Connected