Extension:Jira Ticket

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
Jira Ticket

Release status:Extension status stable

ImplementationTemplate:Extension#type Parser extension, Tag
DescriptionTemplate:Extension#description Links a single Jira ticket with status and priority into an article
Author(s)Template:Extension#username David Seymore with RNSolutions, Patch by St├ęphane Galland (DavidSeymoretalk)
Latest versionTemplate:Extension#version 2008-03-11 (2008-03-11)
MediaWikiTemplate:Extension#mediawiki tested on 1.11.1
LicenseTemplate:Extension#license GPLv2
Download see below

Translate the Jira Ticket extension if it is available at translatewiki.net

Check usage and version matrix.

Like the Jira Extension, Jira Ticket extension allows you to link a MediaWiki instance with Jira. This extension allows a single ticket to be incorporated into an article by its ticket number. The ticket's status, priority, and number are displayed to the user as a URL to the ticket in Jira, and with the title of the ticket as the alternate text.

Installation[edit]

require_once('extensions/jiraticket.php');
  • Touch a file in the extensions directory named jiraticket.php
  • Edit the file and place the following in it:
    • Remember to edit the variables for jiraHost (root URL), jiraUser, jiraPass
    • NOTE: The example below does not work out of the box! Use the one from the Discussion page instead!
<?php


// Make sure we are being called properly
if( !defined( 'MEDIAWIKI' ) ) {
  echo(" This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
  die( -1 );
}

$wgExtensionCredits['other'][] = array(
        'name' => 'jira',
        'author' => 'David Seymore',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Jira_Ticket',
        'description' => 'Jira Status & Priority icon parser.',
);

$wgExtensionFunctions[] = "wfJira";

#SETUP - we need to know which thing we are looking at
$jiraHost='http://your.jira.hostname.org';

$jira = array(
        'user' => 'XXXXXXXXXX',
        'password' => 'XXXXXX',
        'url' => 'http://your.jira.hostname.org/rpc/soap/jirasoapservice-v2?wsdl'
       );



function wfJira() {
  global $wgParser;
    # register the extension with the WikiText parser
    # the first parameter is the name of the new tag.
    # In this case it defines the tag <jira>GS-1</jira>
    # the second parameter is the callback function for
    # processing the text between the tags
  $wgParser->setHook( "jira", "renderTick" );
}


# The callback function for converting the input text to HTML output
function renderTick( $input, $argv, &$parser ) {
global  $jiraHost, $jiraUser, $jiraPass;
      # You can disable the cache, but, rememeber that this'll hit jira everytime the page is read.. not exactly that smart
      # resaving an article will automatically pull down the fresh status of the jira ticket. 
      # $parser->disableCache();
       $jiraSoap = new SoapClient($jira['url']);
        $auth = $jiraSoap->login($jira['user'],$jira['password']);
        $issue = $jiraSoap->getIssue($auth,$input);

        $output = '<a href="'.$jiraHost.'/browse/'.$input.'" alt="'.$issue->summary.'" title="'.$issue->summary.'">'.$input.'</a>&nbsp;';
        $output .= '<img src="'.$jiraHost.'/images/icons/status_';

    #The status switch.. you may have reconfigured your custom statuses, so, edit here.. 
        switch($issue->status){
                case 1:
                        $output .= 'open';
                        break;
                case 3:
                        $output .= 'inprogress';
                        break;
                case 4:  
                        $output .= 'reopened';
                        break;
                case 5:  
                        $output .= 'resolved';
                        break;
                case 6:
                        $output .= 'closed';
                        break;
                default:
                        $output .= $issue->priority;
                        break;
        }
        $output .= '.gif">';

    #The priority switch... you may have reconfigured your custom priorities, so, edit here...
        $output .= '<img src="'.$jiraHost.'/images/icons/priority_';
        switch($issue->priority){
                case 1:
                        $output .= 'blocker';
                        break;
                case 2:  
                        $output .= 'critical';
                        break;
                case 3:
                        $output .= 'major';
                        break;
                case 4:
                        $output .= 'minor';
                        break;
                case 5:
                        $output .= 'trivial';
                        break;
                default:
                        $output .= $issue->priority;
                        break;
        }
        $output .= '.gif">';


  return $output;
}

Usage[edit]

  • Simply take the jira ticket you want to use, and enclose it in the jira tag.
   <jira>GS-763</jira>
  • You'll end up with:

Jira ticket extension in action.jpg

What's Next?[edit]

Parsing the data over HTTP is fine and dandy if you have a decent servers to handle it, but, using SOAP would make this extension MUCH faster. Expect that to come shortly.

Since 03/11/2008 it uses SOAP/RPC to make the calls, and it is about 20x faster.

Patch for compliance to other JIRA extensions[edit]

The following patch permits to the Jira Ticket extension to use the same global variables as Extension:JiraIssueList and Extension:JiraBugReport.

--- JiraTicket.php.orig	2010-08-03 10:50:37.000000000 +0200
+++ JiraTicket.php	2010-07-28 10:25:04.000000000 +0200
@@ -1,5 +1,15 @@
 <?php
- 
+
+/**
+ * Links a single Jira ticket with status and priority into an article.
+ *
+ * Author : David Seymore with RNSolutions
+ * Version : 2008-03-11
+ * License : GPLv2 
+ *
+ * Modified by Stephane GALLAND
+ * 2010-07-19 for janus-project.org usage.
+ */ 
  
 // Make sure we are being called properly
 if( !defined( 'MEDIAWIKI' ) ) {
@@ -7,98 +17,105 @@
   die( -1 );
 }
  

 $wgExtensionCredits['other'][] = array(
-        'name' => 'jira',
-        'author' => 'David Seymore',
+        'name' => 'JiraTicket',
+        'author' => array('David Seymore', 'Stephane Galland'),
         'url' => 'http://www.mediawiki.org/wiki/Extension:Jira_Ticket',
-        'description' => 'Jira Status & Priority icon parser.',
+        'description' => 'Jira Status & Priority icon parser, modifier to work on janus-project.org.',
 );
  
-$wgExtensionFunctions[] = "wfJira";
- 
-#SETUP - we need to know which thing we are looking at
-$jiraHost='http://your.jira.hostname.org';
- 
-$jira = array(
-        'user' => 'XXXXXXXXXX',
-        'password' => 'XXXXXX',
-        'url' => 'http://your.jira.hostname.org/rpc/soap/jirasoapservice-v2?wsdl'
-       );
- 
- 
+$wgExtensionFunctions[] = "wfSetupJiraTicket";
  
-function wfJira() {
+function wfSetupJiraTicket() {
   global $wgParser;
     # register the extension with the WikiText parser
     # the first parameter is the name of the new tag.
     # In this case it defines the tag <jira>GS-1</jira>
     # the second parameter is the callback function for
     # processing the text between the tags
-  $wgParser->setHook( "jira", "renderTick" );
+  $wgParser->setHook( 'jira', 'jiraTicket_render' );
 }
  
  
 # The callback function for converting the input text to HTML output
-function renderTick( $input, $argv, &$parser ) {
-global  $jiraHost, $jiraUser, $jiraPass;
+function jiraTicket_render( $input='', $argv='', $parser=null ) {
+	global  $jiraHost, $jiraUser, $jiraPass;
       # You can disable the cache, but, rememeber that this'll hit jira everytime the page is read.. not exactly that smart
       # resaving an article will automatically pull down the fresh status of the jira ticket. 
       # $parser->disableCache();
+#SETUP - we need to know which thing we are looking at
+        $jiraHost='http://localhost';
+        $jiraUser='';
+        $jiraPass=''; 
+
-        $jiraSoap = new SoapClient($jira['url']);
-        $auth = $jiraSoap->login($jira['user'],$jira['password']);
-        $issue = $jiraSoap->getIssue($auth,$input);
+
+	$jiraUrl = "$jiraHost/rpc/soap/jirasoapservice-v2?wsdl";
+
+       	try {
+		$jiraSoap = new SoapClient($jiraUrl);
+        	$auth = $jiraSoap->login($jiraUser,$jiraPass);
+		$issue = $jiraSoap->getIssue($auth,$input);
+	}
+	catch(Exception $e) {
+		return "<!-- ".$e->getMessage().
+			" --><span title=\"".$e->getMessage()."\"><s>$input</s></span>";
+	}
  
-        $output = '<a href="'.$jiraHost.'/browse/'.$input.'" alt="'.$issue->summary.'" title="'.$issue->summary.'">'.$input.'</a>&nbsp;';
-        $output .= '<img src="'.$jiraHost.'/images/icons/status_';
+	$issuelabel = "$input";
+        $output1 = '<a target="_blank" href="'.$jiraHost.'/browse/'.$input.'" alt="'.$issue->summary.'" title="'.$issue->summary.'">';
+        $output2 = '</a>&nbsp;<img src="'.$jiraHost.'/images/icons/status_';
  
     #The status switch.. you may have reconfigured your custom statuses, so, edit here.. 
         switch($issue->status){
                 case 1:
-                        $output .= 'open';
+                        $output2 .= 'open';
                         break;
                 case 3:
-                        $output .= 'inprogress';
+                        $output2 .= 'inprogress';
                         break;
                 case 4:  
-                        $output .= 'reopened';
+                        $output2 .= 'reopened';
                         break;
                 case 5:  
-                        $output .= 'resolved';
+                        $output2 .= 'resolved';
+			$issuelabel = "<s>$issuelabel</s>";
                         break;
                 case 6:
-                        $output .= 'closed';
+                        $output2 .= 'closed';
+			$issuelabel = "<s>$issuelabel</s>";
                         break;
                 default:
-                        $output .= $issue->priority;
+                        $output2 .= $issue->status;
                         break;
         }
-        $output .= '.gif">';
+        $output2 .= '.gif">';
  
     #The priority switch... you may have reconfigured your custom priorities, so, edit here...
-        $output .= '<img src="'.$jiraHost.'/images/icons/priority_';
+        $output2 .= '<img src="'.$jiraHost.'/images/icons/priority_';
         switch($issue->priority){
                 case 1:
-                        $output .= 'blocker';
+                        $output2 .= 'blocker';
                         break;
                 case 2:  
-                        $output .= 'critical';
+                        $output2 .= 'critical';
                         break;
                 case 3:
-                        $output .= 'major';
+                        $output2 .= 'major';
                         break;
                 case 4:
-                        $output .= 'minor';
+                        $output2 .= 'minor';
                         break;
                 case 5:
-                        $output .= 'trivial';
+                        $output2 .= 'trivial';
                         break;
                 default:
-                        $output .= $issue->priority;
+                        $output2 .= $issue->priority;
                         break;
         }
-        $output .= '.gif">';
+        $output2 .= '.gif">';
  
  
-  return $output;
+  return "$output1$issuelabel$output2";
 }
 
+?>

Related Extensions[edit]

The following extensions may use the Jira Ticket extension: