Commits

roadrunner  committed 515a905

[svn r9470] Added option to list all changesets that caused the build.

This closes #7293.

  • Participants
  • Parent commits d307659

Comments (0)

Files changed (1)

File 0.10/HudsonTrac/HudsonTracPlugin.py

 from trac.util.text import unicode_quote
 from trac.web.chrome import INavigationContributor, ITemplateProvider
 from trac.web.chrome import add_stylesheet
+from trac.wiki.formatter import wiki_to_oneliner
 try:
     from trac.timeline.api import ITimelineEventProvider
 except ImportError:
                           'successfully" etc messages.')
     disp_building = BoolOption('hudson', 'display_building', False,
                                'Also show in-progress builds')
+    list_changesets = BoolOption('hudson', 'list_changesets', False,
+                                 'List the changesets for each build')
 
     def __init__(self):
         # get base api url
         if '/job/' not in api_url:
             tree = 'jobs[' + tree + ']'
 
-        tree = tree % {'b':
-            'builds[building,timestamp,duration,result,description,url,fullDisplayName]'}
+        items = 'builds[building,timestamp,duration,result,description,url,' \
+                'fullDisplayName'
+        if self.list_changesets:
+            items += ',changeSet[items[revision,id]]'
+        items += ']'
 
         # assemble final url
+        tree = tree % {'b': items}
         self.info_url = '%s?tree=%s' % (api_url, tree)
 
         self.env.log.debug("Build-info url: '%s'", self.info_url)
         if req.perm.has_permission('BUILD_VIEW'):
             yield ('build', 'Hudson Builds')
 
+    def __fmt_changeset(self, rev, req):
+        # use format_to_oneliner and drop num_args hack when we drop Trac 0.10
+        # support
+        import inspect
+        num_args = len(inspect.getargspec(wiki_to_oneliner)[0])
+        if num_args > 5:
+            return wiki_to_oneliner('[%s]' % rev, self.env, req=req)
+        else:
+            return wiki_to_oneliner('[%s]' % rev, self.env)
+
     def get_timeline_events(self, req, start, stop, filters):
         if 'build' not in filters or not req.perm.has_permission('BUILD_VIEW'):
             return
                 message = entry['description'] and \
                             unicode(entry['description'], cset) or message
 
+            # get changesets
+            changesets = ''
+            if self.list_changesets:
+                paths = ['changeSet.items.revision', 'changeSet.items.id']
+                revs = [unicode(str(r), cset) for r in __find_all(entry, paths)]
+                if revs:
+                    revs = [self.__fmt_changeset(r, req) for r in revs]
+                    changesets = '<br/>Changesets: ' + ', '.join(revs)
+
             # format response
             if result == 'IN-PROGRESS':
-                comment = "%s since %s, duration %s" % (
-                              message, format_datetime(started),
-                              pretty_timedelta(started, completed))
+                comment = Markup("%s since %s, duration %s%s" % (
+                                 message, format_datetime(started),
+                                 pretty_timedelta(started, completed),
+                                 changesets))
             else:
-                comment = "%s at %s, duration %s" % (
-                              message, format_datetime(completed),
-                              pretty_timedelta(started, completed))
+                comment = Markup("%s at %s, duration %s%s" % (
+                                 message, format_datetime(completed),
+                                 pretty_timedelta(started, completed),
+                                 changesets))
 
             href  = entry['url']
             title = 'Build "%s" (%s)' % \