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