ShawnCplus 456 Code Monkey Team Colleague

Small script to pull information from Trac. Note that this will only work if you set up your trac environment to use a MySQL database (It is pretty simple to switch from SQLite to MySQL though).
It uses template format just to make it easy to customize. I originally had commit comments running through a Wiki parser but removed it just so there are zero dependencies for the script.

<?php $db = mysql_connect('<host>', '<user>', '<password>') or die('Unable to sync with Trac') ?>
<?php $latest_revision = mysql_query("SELECT rev, time, author, message FROM trac.revision ORDER BY time DESC LIMIT 0,1",$db) ?>

<?php if($latest_revision) while($revision = mysql_fetch_assoc($latest_revision)): ?>
<br />
  <table border='0'>
    <thead>
      <tr><td style='font-size:larger;text-decoration:underline;'><b>Repository</b></td></tr>
    </thead>
    <tr>
      <td><b>Revision:</b></td>
      <td><?php echo $revision['rev']; ?></td>
    </tr>
    <tr>
      <td><b>Author:</b></td>
      <td><?php echo $revision['author'] == ''?'Anonymous':$revision['author'] ?></td>
    </tr>
    <tr>
      <td><b>Date of Change:</b></td>
      <td><?php echo date('F jS @ g:ia', $revision['time']) ?></td>
    </tr>
    <tr><td><b>Commit Message:</b></td></tr>
    <tr><td colspan='2'><?php echo nl2br($revision['message']) ?></td></tr>
    <tr><td colspan='2'>
          <a href='http://<url to trac server>/trac/changeset/<?php echo $revision['rev'] ?>' target="_blank">View Summary of Changes</a>
    </td></tr>
  </table>
<?php endwhile; ?>

<?php $latest_doc = mysql_query("SELECT name, time, author, comment FROM trac.wiki ORDER BY time DESC LIMIT 0,1",$db) ?>

<?php if($latest_doc) while($wiki = mysql_fetch_assoc($latest_doc)): ?>
<br />
  <table border='0'>
    <thead>
      <tr><td style='font-size:larger;text-decoration:underline;'><b>Documentation</b></td></tr>
    </thead>
    <tr>
      <td><b>Page:</b></td>
      <td><?php echo $wiki['name']; ?></td>
    </tr>
    <tr>
      <td><b>Author:</b></td>
      <td><?php echo $wiki['author'] == ''?'Anonymous':$wiki['author'] ?></td>
    </tr>
    <tr>
      <td><b>Date of Change:</b></td>
      <td><?php echo date('F jS @ g:ia', $wiki['time']) ?></td>
    </tr>
    <?php if($wiki['comment'] != '' && $wiki['comment'] != null ): ?>
      <tr><td><b>Change Comment:</b></td></tr>
      <tr><td colspan='2'><?php echo nl2br($wiki['comment']) ?></td></tr>
    <?php endif; ?>
    <tr><td colspan='2'>
          <a href='<url to trac server>/wiki/<?php echo $wiki['name'] ?>' target="_blank">View Page</a>
    </td></tr>
  </table>
<?php endwhile; ?>

Implementation: http://www.lazycode.info

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.