bugzilla.xsl
author ali@yendor.vm.bytemark.co.uk
Thu Nov 16 08:30:26 2006 +0000 (2006-11-16)
changeset 0 ae7b3fa753dc
permissions -rw-r--r--
First cut. Distintly raw around the edges:
* Assumes it will be running in /home/ali/wk/slashem/web.scripts
* Assumes cache directory will be in topdir
* No build system (simple compiling and linking against libxml2)
* No configure system (eg., tagsoup)
* Output XML untested
* Doesn't set bugzilla maintainer or exporter
* Handling of artifact priorities and resolution is suspect
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet version="1.0"
     3 		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     4 		xmlns:xi="http://www.w3.org/2001/XInclude"
     5 		xmlns:date="http://exslt.org/dates-and-times"
     6 		xmlns:sf2bz="http://project.juiblex.co.uk/sf2bz"
     7 		extension-element-prefixes="date">
     8 
     9 <xsl:import href="sf2bz.xsl"/>
    10 
    11 <!-- Return the last change made in an artifact's history -->
    12 <xsl:template name="lastchange">
    13   <xsl:variable name="dates">
    14     <xsl:for-each
    15       select="field[@name='artifact_history']/history/field[@name='entrydate']">
    16       <xsl:sort data-type='number' order='descending'/>
    17       <xsl:value-of select="."/>
    18       <xsl:text>:</xsl:text>
    19     </xsl:for-each>
    20   </xsl:variable>
    21   <xsl:call-template name="bugzilla-timestamp">
    22     <xsl:with-param name="secs" select="substring-before($dates,':')"/>
    23   </xsl:call-template>
    24 </xsl:template>
    25 
    26 <!-- Process a sourceforge artifact, outputting a bugzilla bug -->
    27 <xsl:template name="process-artifact">
    28   <bug>
    29     <xsl:apply-templates/>
    30     <delta_ts>
    31       <xsl:choose>
    32 	<xsl:when test="field[@name='artifact_history']">
    33 	  <xsl:call-template name="lastchange"/>
    34 	</xsl:when>
    35 	<xsl:otherwise>
    36 	  <xsl:call-template name="bugzilla-timestamp">
    37 	    <xsl:with-param name="secs" select="field[@name='open_date']"/>
    38 	  </xsl:call-template>
    39 	</xsl:otherwise>
    40       </xsl:choose>
    41     </delta_ts>
    42     <xsl:for-each
    43       select="field[@name='artifact_history']/history[field[@name='field_name']='File Added']">
    44       <xsl:element namespace="http://www.w3.org/2001/XInclude" name="include">
    45 	<xsl:attribute name="href">
    46 	  <xsl:text>cache/attachments/</xsl:text>
    47 	  <xsl:value-of
    48 	    select="substring-before(field[@name='old_value'],':')"/>
    49 	  <xsl:text>.xml</xsl:text>
    50 	</xsl:attribute>
    51 	<xsl:attribute name="xpointer">xpointer(/attachment)</xsl:attribute>
    52 	<xsl:element namespace="http://www.w3.org/2001/XInclude"
    53 	  name="fallback"/>
    54       </xsl:element>
    55     </xsl:for-each>
    56   </bug>
    57 </xsl:template>
    58 
    59 <!-- Output a user node -->
    60 <xsl:template name="bugzilla-user">
    61   <xsl:param name="element">who</xsl:param>
    62   <xsl:param name="user" select="."/>
    63   <sf2bz:element>
    64     <xsl:attribute name="name">
    65       <xsl:value-of select="$element"/>
    66     </xsl:attribute>
    67     <sf2bz:copy-from>
    68       <xsl:element namespace="http://www.w3.org/2001/XInclude" name="include">
    69 	<xsl:attribute name="href">users.xml</xsl:attribute>
    70 	<xsl:attribute name="xpointer">
    71 	  <xsl:text>xpointer(/users/user[.="</xsl:text>
    72 	  <xsl:value-of select="$user"/>
    73 	  <xsl:text>@users.sourceforge.net"])</xsl:text>
    74 	</xsl:attribute>
    75       </xsl:element>
    76     </sf2bz:copy-from>
    77   </sf2bz:element>
    78 </xsl:template>
    79 
    80 <xsl:template match="project_export">
    81   <bugzilla version="2.23.3">
    82     <xsl:if test="news/field[@name='group_id']/@group_id">
    83       <xsl:attribute name="urlbase">
    84         <xsl:text>https://sourceforge.net/tracker/?group_id=</xsl:text>
    85 	<xsl:value-of select="news/field[@name='group_id']/@group_id"/>
    86       </xsl:attribute>
    87     </xsl:if>
    88     <xsl:apply-templates/>
    89   </bugzilla>
    90 </xsl:template>
    91 
    92 <xsl:template match="artifacts">
    93   <xsl:apply-templates/>
    94 </xsl:template>
    95 
    96 <xsl:template match="artifact">
    97   <xsl:variable name="type"
    98     select="normalize-space(field[@name='artifact_type'])"/>
    99   <xsl:choose>
   100     <xsl:when test="$type = 'Feature Requests'">
   101       <xsl:call-template name="process-artifact"/>
   102     </xsl:when>
   103     <xsl:when test="$type = 'Patches'">
   104       <xsl:call-template name="process-artifact"/>
   105     </xsl:when>
   106     <xsl:when test="$type = 'Bugs'">
   107       <xsl:call-template name="process-artifact"/>
   108     </xsl:when>
   109   </xsl:choose>
   110 </xsl:template>
   111 
   112 <xsl:template match="field[@name='artifact_id']">
   113   <bug_id><xsl:value-of select="."/></bug_id>
   114 </xsl:template>
   115 
   116 <xsl:template match="field[@name='submitted_by']">
   117   <xsl:call-template name="bugzilla-user">
   118     <xsl:with-param name="element">reporter</xsl:with-param>
   119   </xsl:call-template>
   120 </xsl:template>
   121 
   122 <xsl:template match="field[@name='assigned_to']">
   123   <xsl:if test="normalize-space(.)!='nobody'">
   124     <xsl:call-template name="bugzilla-user">
   125       <xsl:with-param name="element">assigned_to</xsl:with-param>
   126     </xsl:call-template>
   127   </xsl:if>
   128 </xsl:template>
   129 
   130 <xsl:template match="field[@name='priority']">
   131   <priority>
   132     <xsl:choose>
   133       <xsl:when test="number(.)>8">P5</xsl:when>
   134       <xsl:when test="number(.)>5">P4</xsl:when>
   135       <xsl:when test="number(.)=5">P3</xsl:when>
   136       <xsl:when test="number(.)>1">P2</xsl:when>
   137       <xsl:otherwise>P1</xsl:otherwise>
   138     </xsl:choose>
   139   </priority>
   140 </xsl:template>
   141 
   142 <xsl:template match="field[@name='status']">
   143   <bug_status>
   144     <xsl:choose>
   145       <xsl:when test="normalize-space(.)='Open'">
   146 	<xsl:choose>
   147 	  <xsl:when
   148 	    test="normalize-space(../field[@name='assigned_to'])='nobody'">
   149 	    <xsl:text>UNCONFIRMED</xsl:text>
   150 	  </xsl:when>
   151 	  <xsl:otherwise>ASSIGNED</xsl:otherwise>
   152 	</xsl:choose>
   153       </xsl:when>
   154       <xsl:when test="normalize-space(.)='Pending'">NEW</xsl:when>
   155       <xsl:otherwise>RESOLVED</xsl:otherwise>
   156     </xsl:choose>
   157   </bug_status>
   158 </xsl:template>
   159 
   160 <xsl:template match="field[@name='summary']">
   161   <short_desc><xsl:value-of select="."/></short_desc>
   162 </xsl:template>
   163 
   164 <xsl:template match="field[@name='open_date']">
   165   <creation_ts>
   166     <xsl:call-template name="bugzilla-timestamp"/>
   167   </creation_ts>
   168 </xsl:template>
   169 
   170 <xsl:template match="field[@name='artifact_type']">
   171   <xsl:variable name="pri"
   172     select="normalize-space(../field[@name='priority'])"/>
   173   <bug_severity>
   174     <xsl:choose>
   175       <xsl:when test="normalize-space(.)='Bugs'">
   176 	<xsl:choose>
   177 	  <xsl:when test="$pri&gt;=9">blocker</xsl:when>
   178 	  <xsl:when test="$pri=8">critical</xsl:when>
   179 	  <xsl:when test="$pri&lt;8 and $pri&gt;5">major</xsl:when>
   180 	  <xsl:when test="$pri&lt;5 and $pri&gt;2">minor</xsl:when>
   181 	  <xsl:when test="$pri&lt;=2">trivial</xsl:when>
   182 	  <xsl:otherwise>normal</xsl:otherwise>
   183 	</xsl:choose>
   184       </xsl:when>
   185       <xsl:otherwise>enhancement</xsl:otherwise>
   186     </xsl:choose>
   187   </bug_severity>
   188 </xsl:template>
   189 
   190 <xsl:template match="field[@name='category']">
   191   <component><xsl:value-of select="."/></component>
   192 </xsl:template>
   193 
   194 <xsl:template match="field[@name='artifact_group_id']">
   195   <version><xsl:value-of select="."/></version>
   196 </xsl:template>
   197 
   198 <xsl:template match="field[@name='details']">
   199   <long-desc>
   200     <xsl:call-template name="bugzilla-user">
   201       <xsl:with-param name="user" select="../field[@name='submitted_by']"/>
   202     </xsl:call-template>
   203     <bug_when>
   204       <xsl:call-template name="bugzilla-timestamp">
   205 	<xsl:with-param name="secs" select="../field[@name='open_date']"/>
   206       </xsl:call-template>
   207     </bug_when>
   208     <thetext><xsl:value-of select="."/></thetext>
   209   </long-desc>
   210 </xsl:template>
   211 
   212 <xsl:template match="field[@name='artifact_messages']">
   213   <xsl:apply-templates/>
   214 </xsl:template>
   215 
   216 <xsl:template match="message">
   217   <long-desc>
   218     <xsl:call-template name="bugzilla-user">
   219       <xsl:with-param name="user" select="field[@name='user_name']"/>
   220     </xsl:call-template>
   221     <bug_when>
   222       <xsl:call-template name="bugzilla-timestamp">
   223 	<xsl:with-param name="secs" select="field[@name='adddate']"/>
   224       </xsl:call-template>
   225     </bug_when>
   226     <thetext>
   227       <!-- Sourceforge puts either "Logged In: YES \n;user_id=%user\n\n" or
   228            "Logged In: NO\n\n" at the start of each message body. -->
   229       <xsl:value-of select="substring-after(field[@name='body'],'&#10;&#10;')"/>
   230     </thetext>
   231   </long-desc>
   232 </xsl:template>
   233 
   234 <xsl:template match="node()|text()" priority="-1"></xsl:template>
   235 
   236 </xsl:stylesheet>