<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[1121] sites/trunk/svn.wordpress.org/includes/slack-trac-hooks: Update Slack libraries.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/1121">1121</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/1121","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>nacin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-01-11 11:00:02 +0000 (Sun, 11 Jan 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Update Slack libraries.</pre>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/</li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachooksannounceconfigphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/config.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachooksannouncelibphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/lib.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookssendphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/send.php</a></li>
<li>sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/</li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstracbotphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/bot.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstraccommenthandlerphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/comment-handler.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstraccommithandlerphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit-handler.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstraccommitphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstracconfigphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/config.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstracnewticketphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/new-ticket.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstracresourcephp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/resource.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstracticketphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/ticket.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstractracphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/trac.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachooksuserphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/user.php</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookscommentsphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/comments.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookscommitsphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/commits.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachooksconfigphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/config.php</a></li>
<li><a href="#sitestrunksvnwordpressorgincludesslacktrachookstracphp">sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunksvnwordpressorgincludesslacktrachooksannounceconfigphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/config.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/config.php                               (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/config.php 2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,29 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Announce;
+
+// Required function: get_whitelist()
+// Optional function: get_avatar()
+
+/**
+ * Returns a whitelist of users by channel.
+ *
+ * The array keys are the channel name (omit #) and the
+ * values are an array of users.
+ */
+function get_whitelist() {
+       return array(
+               'cli' => array(
+                       'danielbachhuber',
+               ),
+               'core' => array(
+                       'johnbillion',
+               ),
+               'polyglots' => array(
+                       'petya',
+               ),
+               'wptv' => array(
+                       'jerrysarcastic',
+               ),
+       );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/config.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachooksannouncelibphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/lib.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/lib.php                          (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/lib.php    2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,85 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Announce;
+use Dotorg\Slack\Send;
+
+require_once __DIR__ . '/config.php';
+
+function get_whitelist_for_channel( $channel ) {
+       $whitelist = get_whitelist();
+       if ( isset( $whitelist[ $channel ] ) ) {
+               return $whitelist[ $channel ];
+       }
+       return array();
+}
+
+function get_whitelisted_channels_for_user( $user ) {
+       $whitelist = get_whitelist();
+       $whitelisted = array();
+       foreach ( $whitelist as $channel => $users ) {
+               if ( in_array( $user, $users, true ) ) {
+                       $whitelisted[] = $channel;
+               }
+       }
+
+       return $whitelisted;
+}
+
+function is_user_whitelisted( $user, $channel ) {
+       if ( $channel === 'privategroup' ) {
+               // 'privategroup' is special on Slack's end.
+               // Let's assume anyone in a private group can send to private groups.
+               return true;
+       }
+
+       $whitelist = get_whitelist_for_channel( $channel );
+       return in_array( $user, $whitelist, true );
+}
+
+function show_authorization( $user, $channel ) {
+       $channels = get_whitelisted_channels_for_user( $user ) ;
+       if ( $channel === 'privategroup' ) {
+               echo "Any private group members can use @channel in this group.";
+               # return;
+       } elseif ( empty( $channels ) ) {
+               echo "You are not allowed to use @channel.";
+       } elseif ( in_array( $channel, $channels ) ) {
+               $channels = array_filter( $channels, function( $c ) use ( $channel ) { return $c !== $channel; } );
+               if ( $channels ) {
+                       printf( "You are allowed to use @channel in #%s (also %s).", $channel, '#' . implode( ' #', $channels ) );
+               } else {
+                       echo "You are allowed to use @channel in #$channel.";
+               }
+       } else {
+               printf( "You are not allowed to use @channel in #%s, but you are in #%s.", $channel, implode( ' #', $channels ) );
+       }
+
+       printf( " If you are a team lead and need to be whitelisted, contact an admin in <#%s|%s> for assistance.", SLACKHELP_CHANNEL_ID, SLACKHELP_CHANNEL_NAME );
+}
+
+function run( $data ) {
+       $user = $data['user_name'];
+       $channel = $data['channel_name'];
+
+       if ( empty( $data['text'] ) ) {
+               show_authorization( $user, $channel );
+               return;
+       }
+
+       if ( ! is_user_whitelisted( $user, $channel ) ) {
+               return;
+       }
+
+       $send = new Send( \Dotorg\Slack\Send\WEBHOOK );
+       $send->set_username( $user );
+       $send->set_text( sprintf( "<!channel> %s", $data['text'] ) );
+
+       $get_avatar = __NAMESPACE__ . '\\' . 'get_avatar';
+       if ( function_exists( $get_avatar ) ) {
+               $send->set_icon( call_user_func( $get_avatar, $data['user_name'], $data['user_id'], $data['team_id'] ) );
+       }
+       
+       // By sending the channel ID, we can post to private groups.
+       $send->send( $data['channel_id'] );
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/announce/lib.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookscommentsphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/comments.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/comments.php      2015-01-11 05:35:52 UTC (rev 1120)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/comments.php        2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,162 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-namespace Dotorg\SlackTracHooks\Comments;
-
-function process_message( $lines ) {
-       $lines = array_map( 'rtrim', $lines );
-       
-       // Trim off headers.
-       while ( '' !== current( $lines ) ) {
-               array_shift( $lines );
-       }
-       // Remove empty line between headers and body.
-       array_shift( $lines );
-       
-       $title = '';
-       while ( 0 !== strpos( current( $lines ), '------' ) ) {
-               if ( '' !== $title ) {
-                       $last = substr( $title, -1 );
-                       if ( $last !== '-' && $last !== '_' ) {
-                               $title .= ' ';
-                       }
-               }
-               $title .= array_shift( $lines );
-       }
-       $title = substr( $title, strpos( $title, ': ' ) + 2 );
-       
-       // Remove up to top of ticket properties table.
-       while ( 0 !== strpos( current( $lines ), '------' ) ) {
-               array_shift( $lines );
-       }
-       // Remove top border of table.
-       array_shift( $lines );
-       // Remove ticket properties table.
-       while ( 0 !== strpos( current( $lines ), '------' ) ) {
-               array_shift( $lines );
-       }
-       // Remove bottom border of table.
-       array_shift( $lines );
-       
-       // Remove empty line if present. (It is when it's a comment without changes.)
-       if ( current( $lines ) === '' ) {
-               array_shift( $lines );
-       }
-       
-       // Remove Trac email footer.
-       while ( end( $lines ) !== '--' ) {
-               array_pop( $lines );
-       }
-       // Remove -- which starts footer.
-       array_pop( $lines );
-       // Remove empty line before footer.
-       array_pop( $lines );
-       
-       preg_match( '/^(Comment|Changes) \(by (.*)\):$/', array_shift( $lines ), $matches );
-       $has_changes = $matches[1] === 'Changes';
-       $author = $matches[2];
-       
-       // Remove blank line after 'Comment|Changes (by author):'
-       array_shift( $lines );
-       
-       $changes = $comment = array();
-       if ( $has_changes ) {
-               while ( '' !== current( $lines ) ) {
-                       $changes[] = preg_replace( '~^ \* (.*?):  ~', '_*$1:*_ ', array_shift( $lines ) );
-               }
-       }
-       
-       // Remove blank lines (should be two if it had changes).
-       while ( '' === current( $lines ) ) {
-               array_shift( $lines );
-       }
-       
-       // Next line should start with 'Comment' if there is one.
-       if ( $has_changes && 0 === strpos( current( $lines ), 'Comment' ) ) {
-               array_shift( $lines ); // Remove 'Comment'
-               array_shift( $lines ); // Remove blank line
-       }
-       
-       // Everything left is the comment. Remove leading space.
-       $comment = array_map( 'ltrim', $lines );
-       
-       $changes = implode( "\n", $changes );
-       $comment = implode( "\n", $comment );
-
-       return compact( 'author', 'title', 'changes', 'comment' );
-}
-
-function format_comment( $comment, $ticket_url ) {
-       // Link 'Replying to [comment:1 user]:'
-       $comment = preg_replace_callback( '/^Replying to \[comment:(\d+) (.*)\]/m',
-               function ( $matches ) use ( $ticket_url ) {
-                       $comment_url = $ticket_url . '#comment:' . $matches[1];
-                       $text = 'Replying to ' . $matches[2];
-                       return "<$comment_url|$text>";
-               }, $comment );
-
-       // Replace {{{ and }}} with ``` or `
-       $comment = trim( str_replace(
-               array( "\n{{{\n", "\n}}}\n", '{{{', '}}}' ),
-               array( "\n```\n", "\n```\n", '`',   '`' ),
-               "\n$comment\n"
-       ), "\n" );
-
-       return $comment;
-}
-
-function send( $slack_hook, $args ) {
-       // Don't post auto-comments for commits.
-       if ( false !== strpos( $args['comment'], '#!CommitTicketReference' ) ) {
-               return;
-       }
-
-       $trac_class = '\\Dotorg\\SlackTracHooks\\' . $args['trac'] . '_Trac';
-       $trac = new $trac_class;
-
-               
-       $args['comment'] = format_comment( $args['comment'], $args['ticket_url'] );
-       $main_attachment = $args['changes'] ? $args['changes'] : $args['comment'];
-
-       $pretext = sprintf( '*%s updated <%s|#%s %s>*', $args['author'], $args['comment_url'], $args['ticket'], $args['title'] );
-       $fallback = trim( $pretext, '*' ) . "\n" . $main_attachment;
-
-       $payload = array(
-               'channel'     => $trac->get_firehose_channel(),
-               'icon_emoji'  => $trac->get_emoji(),
-               'username'    => $trac->get_ticket_username(),
-               'attachments' => array(
-                       array(
-                               'pretext'   => $pretext,
-                               'fallback'  => $fallback,
-                               'text'      => $main_attachment,
-                               'mrkdwn_in' => array( 'pretext', 'fallback', 'text' ),
-                       ),
-               ),
-       );
-
-       // If we have both changes and a comment, append the comment.
-       // Ensure the comment uses a darker gray color, even when alone.        
-       if ( $args['changes'] && $args['comment'] ) {
-               $payload['attachments'][] = array(
-                       'fallback'  => $args['comment'],
-                       'text'      => $args['comment'],
-                       'mrkdwn_in' => array( 'fallback', 'text' ),
-                       'color'     => '#999',
-               );
-       } elseif ( ! $args['changes'] ) {
-               $payload['attachments'][0]['color'] = '#999';
-       }
-       
-       $payload = json_encode( $payload );
-       
-       $context = stream_context_create( array(
-               'http' => array(
-                       'method'  => 'POST',
-                       'header'  => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
-                       'content' => http_build_query( compact( 'payload' ) ),
-               ),
-       ) );
-       
-       file_get_contents( $slack_hook, false, $context );
-}
-
</del></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachookscommitsphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/commits.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/commits.php       2015-01-11 05:35:52 UTC (rev 1120)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/commits.php 2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,119 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-namespace Dotorg\SlackTracHooks;
-
-class Commits {
-       protected $trac;
-       protected $repo;
-       protected $rev;
-       protected $slack_hook;
-
-       protected $test_mode = false;
-       protected $svnlook = '/usr/bin/svnlook';
-
-       public function __construct( $trac, $repo, $rev, $slack_hook ) {
-               $this->set_trac( $trac );
-               $this->repo = $repo;
-               $this->rev = $rev;
-               $this->slack_hook = $slack_hook;
-       }
-
-       public function use_test_channel( $enabled ) {
-               $this->test_mode = (bool) $enabled;
-       }
-
-       public function set_svnlook_executable( $path ) {
-               $this->svnlook = $path;
-       }
-
-       public function run() {
-               $payload = $this->generate_payload();
-               foreach ( $this->trac->get_commit_channels( $this->svnlook( 'changed' ) ) as $channel ) {
-                       $this->send( $channel, $payload );
-               }
-       }
-
-       protected function set_trac( $trac ) {
-               $class = __NAMESPACE__ . '\\' . $trac . '_Trac';
-               $this->trac = new $class;
-       }
-
-       protected function generate_payload() {
-               $author = $this->svnlook( 'author' );
-               $log = $this->format_log_for_slack( $this->svnlook( 'log' ) );
-
-               $url = $this->trac->get_commit_template( $this->rev );
-               $revision = 'r' . $this->rev;
-
-               $username = $this->trac->get_commit_username();
-               $emoji    = $this->trac->get_emoji();
-               $color    = $this->trac->get_color();
-
-               $pretext = "*$username <$url|$revision>* by $author:";
-               $fallback = "$revision by $author: $log";
-
-               return array(
-                       'channel'     => '#test',
-                       'username'    => $username,
-                       'icon_emoji'  => $emoji,
-                       'attachments' => array( array(
-                               'color'     => $color,
-                               'pretext'   => $pretext,
-                               'text'      => $log,
-                               'fallback'  => $fallback,
-                               'mrkdwn_in' => array( 'text', 'pretext' ),
-                       ) ),
-               );
-       }
-
-       protected function format_log_for_slack( $log ) {
-               foreach ( $this->trac->get_log_replacements() as $find => $replace ) {
-                       $log = preg_replace( $find, '<' . $replace . '|$0>', $log );
-               }
-               return $log;
-       }
-
-       protected function svnlook( $subcommand ) {
-               $args = array(
-                       $subcommand,
-                       '-r' . $this->rev,
-                       $this->repo,
-               );
-               $args = array_map( 'escapeshellarg', $args );
-               $command = escapeshellcmd( $this->svnlook ) . ' ' . implode( ' ', $args );
-
-               if ( $subcommand === 'changed' ) {
-                       $command .= ' | awk \'{print $2}\'';
-               }
-
-               exec( $command, $output, $return_var );
-               if ( $return_var === 0 ) {
-                       return trim( implode( "\n", $output ) );
-               }
-               $this->error( "Error processing svnlook( $subcommand )" );
-       }
-
-       protected function error( $message ) {
-               error_log( $message . ' for ' . $this->repo . ' -r ' . $this->rev );
-               exit( 1 );
-       }
-
-       protected function send( $channel, $payload ) {
-               if ( $this->test_mode ) {
-                       $payload['attachments'][0]['pretext']  = "[$channel] " . $payload['attachments'][0]['pretext'];
-                       $payload['attachments'][0]['fallback'] = "[$channel] " . $payload['attachments'][0]['fallback'];
-               } else {
-                       $payload['channel'] = $channel;
-               }
-
-               $context = stream_context_create( array(
-                       'http' => array(
-                               'method'  => 'POST',
-                               'header'  => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
-                               'content' => http_build_query( array( 'payload' => json_encode( $payload ) ) ),
-                       ),
-               ) );
-
-               file_get_contents( $this->slack_hook, false, $context );
-       }
-}
</del></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachooksconfigphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/config.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/config.php        2015-01-11 05:35:52 UTC (rev 1120)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/config.php  2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,92 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-namespace Dotorg\SlackTracHooks;
-
-class Core_Trac extends Trac {
-       protected $commit_channels = array( '#core', '#core-commits' );
-       protected $commit_username = 'WordPress commit';
-       protected $commit_range = array( 3, 5 );
-       protected $ticket_range = array( 3, 5 );
-
-       protected $ticket_channels  = array( '#core', '#core-newtickets' );
-       protected $ticket_username  = 'WordPress Trac';
-       protected $firehose_channel = '#core-firehose';
-
-       /**
-        * File paths that cause commits to be piped to particular channels.
-        * Start regex matches with # as your delimiter.
-        */
-       protected $commit_path_filters = array(
-               'wp-content/themes'       => '#core-themes',
-               'customize'               => '#core-customize',
-               'editor-expand.js'        => '#feature-focus',
-               'wp-admin/css/edit.css'   => '#feature-focus',
-               'wp-admin/css/editor.css' => '#feature-focus',
-               'press-this.php'          => '#feature-pressthis',
-       );
-
-       /**
-        * Components or focuses that cause new tickets to be piped to particular channels.
-        */
-       protected $ticket_component_filters = array(
-               'Customize'     => '#core-customize',
-               'Bundled Theme' => '#core-themes',
-               'Press This'    => '#feature-pressthis',
-       );
-}
-
-class Meta_Trac extends Trac {
-       protected $commit_channels = array( '#meta', '#meta-commits' );
-       protected $commit_username = 'WordPress.org Meta commit';
-
-       protected $ticket_channels = array( '#meta-newtickets' );
-
-       protected $commit_path_filters = array(
-               'translate.wordpress.org/' => '#meta-i18n',
-               'global.wordpress.org/'    => '#meta-i18n',
-               'translations'             => '#meta-i18n',
-               'developer-reference/'     => '#meta-devhub',
-               'wporg-developer/'         => '#meta-devhub',
-       );
-
-       protected $ticket_component_filters = array(
-               'International Forums'          => '#meta-i18n',
-               'International Sites (Rosetta)' => '#meta-i18n',
-               'translate.wordpress.org'       => '#meta-i18n',
-               'developer.wordpress.org'       => '#meta-devhub',
-       );
-}
-
-class bbPress_Trac extends Trac {
-       protected $commit_channels = array( '#bbpress', '#bbpress-commits' );
-       protected $commit_username = 'bbPress commit';
-       protected $ticket_channels = array( '#bbpress', '#bbpress-newtickets' );
-       protected $color    = '#080';
-       protected $emoji    = ':bbpress:';
-}
-
-class BuddyPress_Trac extends Trac {
-       protected $commit_channels = array( '#buddypress', '#buddypress-commits' );
-       protected $commit_username = 'BuddyPress commit';
-       protected $ticket_channels = array( '#buddypress', '#buddypress-newtickets' );
-       protected $color    = '#d84800';
-       protected $emoji    = ':buddypress:';
-}
-
-class Dotorg_Trac extends Trac {
-       protected $commit_channels = 'dotorg';
-       protected $commit_username = 'Private dotorg commit';
-       protected $ticket_channels = 'dotorg';
-}
-
-class Deploy_Trac extends Trac {
-       protected $commit_channels = 'dotorg';
-       protected $commit_username = 'Deploy commit';
-       protected $ticket_channels = 'dotorg';
-}
-
-class GlotPress_Trac extends Trac {
-       protected $commit_channels = '#glotpress';
-       protected $commit_username = 'GlotPress commit';
-       protected $ticket_channels = '#glotpress';
-}
</del></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachookssendphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/send.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/send.php                          (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/send.php    2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,126 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack;
+
+class Send {
+
+       /**
+        * The constant overrides the property,
+        * which is set with the testing() method.
+        */
+       const testing = false;
+       protected $testing;
+
+       protected $webhook;
+       protected $user;
+       protected $icon;
+       protected $username;
+       protected $text = '';
+       protected $attachments = array();
+
+       function __construct( $webhook ) {
+               $this->webhook = $webhook;
+       }
+
+       function set_user( User $user ) {
+               $this->user = $user;
+       }
+
+       function set_icon( $icon ) {
+               $this->icon = $icon;
+       }
+
+       function get_icon() {
+               if ( $this->icon ) {
+                       return $this->icon;
+               } elseif ( $this->user ) {
+                       return $this->user->get_icon();
+               }
+               return ':wordpress:';
+       }
+
+       function set_username( $username ) {
+               $this->username = $username;
+       }
+
+       function get_username() {
+               if ( $this->username ) {
+                       return $this->username;
+               } elseif ( $this->user ) {
+                       return $this->user->get_name();
+               }
+               return 'Bot';
+       }
+
+       function get_text() {
+               return $this->text;
+       }
+
+       function set_text( $text ) {
+               $this->text = $text;
+       }
+
+       function add_attachment( $attachment ) {
+               $this->attachments[] = $attachment;
+       }
+
+       function get_attachments() {
+               return $this->attachments;
+       }
+
+       function get_payload() {
+               $icon = $this->get_icon();
+               $icon_type = ':' === substr( $icon, 0, 1 ) ? 'icon_emoji' : 'icon_url';
+
+               $payload = array(
+                       $icon_type    => $icon,
+                       'username'    => $this->get_username(),
+                       'attachments' => $this->get_attachments(),
+               );
+
+               if ( $text = $this->get_text() ) {
+                       $payload['text'] = $text;
+               }
+               return $payload;
+       }
+
+       function testing( $enabled = null ) {
+               if ( null === $enabled ) {
+                       // If the constant is true, it overrides a public testing(false) call.
+                       if ( self::testing ) {
+                               return true;
+                       }
+                       // testing(true)
+                       if ( isset( $this->testing ) ) {
+                               return $this->testing;
+                       }
+                       return false;
+               }
+               $this->testing = (bool) $enabled;
+       }
+
+       function send( $channel ) {
+               if ( $this->testing() ) {
+                       $this->set_text( "[$channel] " . $this->get_text() );
+                       $channel = '#test';
+               }
+
+               $payload = $this->get_payload();
+               $payload['channel'] = $channel;
+
+               # error_log( print_r( $payload, true ) );
+               $payload = json_encode( $payload );
+               $content = http_build_query( compact( 'payload' ) );
+
+               $context = stream_context_create( array(
+                       'http' => array(
+                               'method'  => 'POST',
+                               'header'  => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
+                               'content' => $content,
+                       ),
+               ) );
+
+               return file_get_contents( $this->webhook, false, $context );
+       }
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/send.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookstracbotphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/bot.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/bot.php                              (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/bot.php        2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,149 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+
+class Bot {
+       const default_trac = 'core';
+
+       static private $default_tracs = array(
+               '#themereview'  => 'themes',
+               '#bbpress'      => 'bbpress',
+               '#buddypress'   => 'buddypress',
+               '#glotpress'    => 'glotpress',
+               '#meta'         => 'meta',
+               '#core-restapi' => false, // ideally: GH WP-API/WP-API
+       );
+
+       protected $parsed = array();
+
+       // We want to post to Trac no more than once per two hours, and to Slack no more than once every 10 minutes.
+       // After 5 minutes for Slack, show a link only and extend it the redundancy.
+       private $redundant_time = array( 'slack' => 600, 'trac' => 7200 );
+       // After 5 minutes for Slack, show a link only. Extend the redundany check.
+       const slack_repost_link = 300;
+
+       private $avoid_redundancy = false;
+
+       function __construct( $post_data ) {
+               $this->post_data = $post_data;
+       }
+
+       function get_channel() {
+               return '#' . $this->post_data['channel_name'];
+       }
+
+       function parse() {
+               $this->parse_tickets( $this->post_data['text'] );
+               $this->parse_commits( $this->post_data['text'] );
+               return $this->parsed;
+       }
+
+       function parse_tickets( $text ) {
+               $digits = Trac::get_digit_capture();
+               $ticket_tracs = '?<trac>' . Trac::get_regex();
+               preg_match_all( "/#(?<id>$digits)(?:\-($ticket_tracs)\b)?/", $text, $tickets, PREG_SET_ORDER );
+               preg_match_all( "/#($ticket_tracs)(?<id>$digits)\b/", $text, $tickets_alt, PREG_SET_ORDER );
+               preg_match_all( "~https?://($ticket_tracs).trac.wordpress.org/ticket/(?<id>$digits)~", $text, $tickets_url, PREG_SET_ORDER );
+               foreach ( $tickets_url as &$ticket ) {
+                       $ticket['url'] = true;
+               }
+               $tickets = array_merge( $tickets, $tickets_alt, $tickets_url );
+               $this->finish_parsing( 'ticket', $tickets );
+       }
+
+       function parse_commits( $text ) {
+               $digits = '[1-9][0-9]{1,4}'; // two digits minimum, five digits maximum (avoid clashing with colors), cannot start with 0.
+               $commit_tracs = '?<trac>' . Trac::get_regex();
+               preg_match_all( "/\br(?<id>$digits)(?:\-($commit_tracs))?\b/", $text, $revisions, PREG_SET_ORDER );
+               preg_match_all( "/\[($commit_tracs)?(?<id>$digits)\]/", $text, $commits, PREG_SET_ORDER );
+               preg_match_all( "/\[(?<id>$digits)-($commit_tracs)\]/", $text, $commits_alt, PREG_SET_ORDER );
+               // Edge case: Doesn't handle the design changesets. I don't care.
+               preg_match_all( "~https?://($commit_tracs).trac.wordpress.org/changeset/(?<id>$digits)~", $text, $changesets_url, PREG_SET_ORDER );
+
+               foreach ( $changesets_url as &$changeset ) {
+                       $changeset['url'] = true;
+               }
+
+               $commits = array_merge( $commits, $commits_alt, $revisions, $changesets_url );
+               $this->finish_parsing( 'commit', $commits );
+       }
+
+       function finish_parsing( $type, $items ) {
+               foreach ( $items as $item ) {
+                       $trac = $this->parse_trac( $item );
+                       if ( ! $trac ) {
+                               continue;
+                       }
+
+                       if ( $type === 'ticket' && ! $trac->has_tickets() ) {
+                               continue;
+                       } elseif ( $type === 'commit' && ! $trac->has_commits() ) {
+                               continue;
+                       }
+
+                       unset( $item[0], $item[1], $item[2] );
+                       $trac = $trac->get_slug();
+
+                       if ( ! isset( $this->parsed[ $trac ][ $type ] ) ) {
+                               $this->parsed[ $trac ][ $type ] = array( $item );
+                       } elseif ( ! in_array( $item['id'], self::array_column( $this->parsed[ $trac ][ $type ], 'id' ) ) ) {
+                               $this->parsed[ $trac ][ $type ][] = $item;
+                       }
+               }
+       }
+
+       static function array_column( $array, $column ) {
+               $results = array();
+               foreach ( $array as $item ) {
+                       $results[] = $item[ $column ];
+               }
+               return $results;
+       }
+
+       function parse_trac( $item ) {
+               if ( ! empty( $item['trac'] ) ) {
+                       return Trac::get( $item['trac'] );
+               }
+
+               $channel = $this->get_channel();
+               if ( ! empty( self::$default_tracs[ $channel ] ) ) {
+                       return Trac::get( self::$default_tracs[ $channel ] );
+               } elseif ( isset( self::$default_tracs[ $channel ] ) ) {
+                       return false;
+               }
+
+               list( $channel_namespace ) = explode( '-', $channel, 2 );
+               if ( ! empty( self::$default_tracs[ $channel_namespace ] ) ) {
+                       return Trac::get( self::$default_tracs[ $channel_namespace ] );
+               } elseif ( isset( self::$default_tracs[ $channel_namespace ] ) ) {
+                       return false;
+               }
+
+               return Trac::get( self::default_trac );
+       }
+
+       // Redundancy functions
+
+       function avoid_redundancy() {
+               $this->avoid_redundancy = true;
+               wp_cache_init();
+       }
+
+       function is_redundant( $realm, $trac, $type, $id ) {
+               if ( ! $this->avoid_redundancy ) {
+                       return false;
+               }
+               return wp_cache_get( $this->redundancy_key( $realm, $trac, $type, $id ), 'tracslack' );
+       }
+
+       function set_redundancy( $realm, $trac, $type, $id ) {
+               if ( ! $this->avoid_redundancy ) {
+                       return;
+               }
+               wp_cache_set( $this->redundancy_key( $realm, $trac, $type, $id ), time(), 'tracslack', $this->redundant_time[ $realm ] );
+       }
+
+       function redundancy_key( $realm, $trac, $type, $id ) {
+               return sprintf( 'chan:%s:%s:%s:%s:%d', $this->get_channel(), $realm, $trac, $type, $id );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/bot.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookstraccommenthandlerphpfromrev1080sitestrunksvnwordpressorgincludesslacktrachookscommentsphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/comment-handler.php (from rev 1080, sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/comments.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/comment-handler.php                          (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/comment-handler.php    2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,171 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+
+class Comment_Handler {
+
+       function __construct( Dotorg\Slack\Send $send, array $email_message ) {
+               $this->send  = $send;
+               $this->lines = $email_message;
+       }
+
+       function run() {
+               $this->process_message();
+
+               // Don't post auto-comments for commits.
+               if ( false !== strpos( $this->comment, '#!CommitTicketReference' ) ) {
+                       return;
+               }
+
+               $this->generate_payload();
+               $this->send->send( $trac->get_firehose_channel() );
+       }
+
+       function process_message() {
+               $lines = array_map( 'rtrim', $this->lines );
+               
+               // Trim off headers.
+               while ( '' !== current( $lines ) ) {
+                       $line = array_shift( $lines );
+                       if ( 0 === strpos( $line, 'X-Trac-Ticket-URL:' ) ) {
+                               // X-Trac-Ticket-URL: https://core.trac.wordpress.org/ticket/12345#comment:1
+                               list( , $comment_url ) = explode( ': ', $line );
+                               list( $ticket_url, $comment_id ) = explode( '#comment:', $comment_url );
+                               list( $trac_url, $ticket_id ) = explode( '/ticket/', $ticket_url );
+       
+                               $trac = Dotorg\Slack\Trac::get( $trac_url );
+                               if ( ! $trac ) {
+                                       return false;
+                               }
+                       }
+               }
+
+               // Remove empty line between headers and body.
+               array_shift( $lines );
+               
+               $title = '';
+               while ( 0 !== strpos( current( $lines ), '------' ) ) {
+                       if ( '' !== $title ) {
+                               $last = substr( $title, -1 );
+                               if ( $last !== '-' && $last !== '_' ) {
+                                       $title .= ' ';
+                               }
+                       }
+                       $title .= array_shift( $lines );
+               }
+               $title = substr( $title, strpos( $title, ': ' ) + 2 );
+
+               // Remove up to top of ticket properties table.
+               while ( 0 !== strpos( current( $lines ), '------' ) ) {
+                       array_shift( $lines );
+               }
+               // Remove top border of table.
+               array_shift( $lines );
+               // Remove ticket properties table.
+               while ( 0 !== strpos( current( $lines ), '------' ) ) {
+                       array_shift( $lines );
+               }
+               // Remove bottom border of table.
+               array_shift( $lines );
+               
+               // Remove empty line if present. (It is when it's a comment without changes.)
+               if ( current( $lines ) === '' ) {
+                       array_shift( $lines );
+               }
+               
+               // Remove Trac email footer.
+               while ( end( $lines ) !== '--' ) {
+                       array_pop( $lines );
+               }
+               // Remove -- which starts footer.
+               array_pop( $lines );
+               // Remove empty line before footer.
+               array_pop( $lines );
+               
+               preg_match( '/^(Comment|Changes) \(by (.*)\):$/', array_shift( $lines ), $matches );
+               $has_changes = $matches[1] === 'Changes';
+               $author = $matches[2];
+
+               // Remove blank line after 'Comment|Changes (by author):'
+               array_shift( $lines );
+               
+               $changes = $comment = array();
+               if ( $has_changes ) {
+                       while ( '' !== current( $lines ) ) {
+                               $changes[] = preg_replace( '~^ \* (.*?):  ~', '_*$1:*_ ', array_shift( $lines ) );
+                       }
+               }
+               
+               // Remove blank lines (should be two if it had changes).
+               while ( '' === current( $lines ) ) {
+                       array_shift( $lines );
+               }
+               
+               // Next line should start with 'Comment' if there is one.
+               if ( $has_changes && 0 === strpos( current( $lines ), 'Comment' ) ) {
+                       array_shift( $lines ); // Remove 'Comment'
+                       array_shift( $lines ); // Remove blank line
+               }
+
+               // Everything left is the comment. Remove leading space.
+               $comment = array_map( 'ltrim', $lines );
+
+               $this->trac    = $trac;
+               $this->title   = $title;
+               $this->author  = $author;
+               $this->comment = $comment;
+               $this->changes = $changes;
+               $this->ticket_id   = $ticket_id;
+               $this->ticket_url  = $ticket_url;
+               $this->comment_id  = $comment_id;
+               $this->comment_url = $comment_url;
+       }
+
+       function format_comment_for_slack() {
+               // Link 'Replying to [comment:1 user]:'
+               $ticket_url = $this->ticket_url;
+               $comment = preg_replace_callback( '/Replying to \[comment:(\d+) (.*)\]/m',
+                       function ( $matches ) use ( $ticket_url ) {
+                               $comment_url = $ticket_url . '#comment:' . $matches[1];
+                               $text = 'Replying to ' . $matches[2];
+                               return "<$comment_url|$text>";
+                       }, $this->comment );
+
+               $comment = Trac::format_for_slack( $comment );
+               return $comment;
+       }
+
+       function generate_payload() {
+               $this->send->set_icon( $this->trac->get_icon() );
+               $this->send->set_username( $this->trac->get_ticket_username() );
+                       
+               $comment         = $this->format_comment_for_slack();
+               $main_attachment = $this->changes ? $this->changes : $comment;
+               $fallback        = trim( $pretext, '*' ) . "\n" . $main_attachment;
+               $pretext         = sprintf( '*%s updated <%s|#%s %s>*', $this->author, $this->comment_url, $this->ticket_id, $this->title );
+
+               $attachment = array(
+                       'pretext'   => $pretext,
+                       'fallback'  => $fallback,
+                       'text'      => $main_attachment,
+                       'mrkdwn_in' => array( 'pretext', 'fallback', 'text' ),
+               );
+
+               // Ensure the comment uses a darker gray color, even when alone.        
+               if ( ! $this->changes ) {
+                       $attachment['color'] = '#999';
+               }
+
+               $this->send->add_attachment( $attachment );
+
+               // If we have both changes and a comment, append the comment.
+               if ( $this->changes && $comment ) {
+                       $this->send->add_attachment( array(
+                               'fallback'  => $comment,
+                               'text'      => $comment,
+                               'mrkdwn_in' => array( 'fallback', 'text' ),
+                               'color'     => '#999',
+                       ) );
+               }
+       }
+}
</ins></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachookstraccommithandlerphpfromrev1080sitestrunksvnwordpressorgincludesslacktrachookscommitsphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit-handler.php (from rev 1080, sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/commits.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit-handler.php                           (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit-handler.php     2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,86 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+use Dotorg\Slack\Send;
+
+class Commit_Handler {
+       protected $trac;
+       protected $repo;
+       protected $rev;
+       protected $send;
+
+       protected $test_mode = false;
+       protected $svnlook = '/usr/bin/svnlook';
+
+       public function __construct( Send $send, $trac, $repo, $rev ) {
+               $this->send = $send;
+               $this->trac = Trac::get( $trac );
+               $this->repo = $repo;
+               $this->rev  = $rev;
+       }
+
+       public function run() {
+               $this->generate_payload();
+               foreach ( $this->trac->get_commit_channels( $this->svnlook( 'changed' ) ) as $channel ) {
+                       $this->send->send( $channel );
+               }
+       }
+
+       public function testing( $enabled ) {
+               $this->send->testing( (bool) $enabled );
+       }
+
+       public function set_svnlook_executable( $path ) {
+               $this->svnlook = $path;
+       }
+
+       protected function generate_payload() {
+               $author = $this->svnlook( 'author' );
+               $log = Commit::format_commit_for_slack( $this->trac, $this->svnlook( 'log' ) );
+
+               $url = $this->trac->get_commit_template( $this->rev );
+               $revision = 'r' . $this->rev;
+
+               $username = $this->trac->get_commit_username();
+               $icon     = $this->trac->get_icon();
+               $color    = $this->trac->get_color();
+
+               $pretext = "*$username <$url|$revision>* by $author:";
+               $fallback = "$revision by $author: $log";
+
+               $this->send->set_username( $username );
+               $this->send->set_icon( $icon );
+               $this->send->add_attachment( array(
+                       'color'     => $color,
+                       'pretext'   => $pretext,
+                       'text'      => $log,
+                       'fallback'  => $fallback,
+                       'mrkdwn_in' => array( 'text', 'pretext', 'fallback' ),
+               ) );
+       }
+
+       protected function svnlook( $subcommand ) {
+               $args = array(
+                       $subcommand,
+                       '-r' . $this->rev,
+                       $this->repo,
+               );
+               $args = array_map( 'escapeshellarg', $args );
+               $command = escapeshellcmd( $this->svnlook . ' ' . implode( ' ', $args ) );
+
+               if ( $subcommand === 'changed' ) {
+                       $command .= ' | awk \'{print $2}\'';
+               }
+
+               exec( $command, $output, $return_var );
+               if ( $return_var === 0 ) {
+                       return trim( implode( "\n", $output ) );
+               }
+               $this->error( "Error processing svnlook( $subcommand )" );
+       }
+
+       protected function error( $message ) {
+               error_log( $message . ' for ' . $this->repo . ' -r ' . $this->rev );
+               exit( 1 );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachookstraccommitphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit.php                           (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit.php     2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,72 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+
+class Commit extends Resource {
+       protected $data;
+
+       function get_text() {
+               $this->fetch();
+
+               if ( false === $this->data ) {
+                       return $this->get_url();
+               }
+
+               return sprintf( '<%s|r%s>: %s', $this->get_url(), $this->id, self::format_commit_for_slack( $this->trac, $this->message ) );
+       }
+
+       function get_short_attachment() {
+               return $this->get_attachment();
+       }
+
+       function get_attachment() {
+               $this->fetch();
+
+               if ( false === $this->data ) {
+                       return false;
+               }
+
+               $text = $this->get_text();
+
+               return array(
+                       'text'      => $text,
+                       'fallback' => $text,
+                       'mrkdwn_in' => array( 'text', 'fallback' ),
+               );
+       }
+
+       function fetch() {
+               if ( isset( $this->message ) ) {
+                       return $this->message;
+               }
+
+               if ( ! $this->trac->is_public() || ! $this->trac->has_commits() ) {
+                       $this->message = false;
+                       return;
+               }
+
+               $url = $this->trac->get_commit_info_url( $this->id );
+               $contents = @file_get_contents( $url );
+               if ( false === $contents ) {
+                       $this->message = false;
+                       return;
+               }
+
+               // Fragile, but does the trick. First \n\n is the changelog header.
+               // Second \n\n separates the metadata (including file changes)
+               // from the log message.
+               $contents = explode( "\n\n", $contents, 3 );
+               // Trim tabs from the start of each line.
+               $message = preg_replace( '/^\t+/', '', $contents[2] );
+
+               $this->message = $message;
+               $this->fetched = true;
+       }
+
+       static function format_commit_for_slack( Trac $trac, $message ) {
+               foreach ( $trac->get_log_replacements() as $find => $replace ) {
+                       $message = preg_replace( $find, '<' . $replace . '|$0>', $message );
+               }
+               return $message;
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/commit.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookstracconfigphpfromrev1080sitestrunksvnwordpressorgincludesslacktrachooksconfigphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/config.php (from rev 1080, sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/config.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/config.php                           (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/config.php     2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,162 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac\Tracs;
+use Dotorg\Slack\Trac\Trac;
+
+class Core extends Trac {
+       protected $name = 'WordPress';
+       protected $primary_channel  = '#core';
+       protected $commits_channel  = '#core-commits';
+       protected $tickets_channel  = '#core-newtickets';
+       protected $firehose_channel = '#core-firehose';
+
+       protected $primary_channel_ticket_format = 'title';
+
+       /**
+        * File paths that cause commits to be piped to particular channels.
+        * Start regex matches with # as your delimiter.
+        */
+       protected $commit_path_filters = array(
+               'wp-content/themes'       => array( '#core-themes' => true, '#core' => false ),
+               'customize'               => '#core-customize',
+               'editor-expand.js'        => '#feature-focus',
+               'wp-admin/css/edit.css'   => '#feature-focus',
+               'wp-admin/css/editor.css' => '#feature-focus',
+               'press-this.php'          => '#feature-pressthis',
+       );
+
+       /**
+        * Components or focuses that cause new tickets to be piped to particular channels.
+        */
+       protected $ticket_component_filters = array(
+               'Bundled Theme' => array( '#core-themes' => true, '#core' => false ),
+               'Customize'     => '#core-customize',
+               'Press This'    => '#feature-pressthis',
+       );
+}
+
+class Meta extends Trac {
+       protected $name = 'WordPress.org Meta';
+       protected $primary_channel  = '#meta';
+       protected $commits_channel  = '#meta-commits';
+       protected $tickets_channel  = '$meta-newtickets';
+       protected $firehose_channel = '#meta-firehose';
+
+       protected $bypass_primary_channel_for_commit_filter_matches = true;
+       protected $bypass_primary_channel_for_ticket_filter_matches = true;
+
+       protected $commit_path_filters = array(
+               'translate.wordpress.org/' => '#meta-i18n',
+               'global.wordpress.org/'    => '#meta-i18n',
+               'translations'             => '#meta-i18n',
+               'developer-reference/'     => '#meta-devhub',
+               'wporg-developer/'         => '#meta-devhub',
+       );
+
+       protected $ticket_component_filters = array(
+               'International Forums'          => '#meta-i18n',
+               'International Sites (Rosetta)' => '#meta-i18n',
+               'translate.wordpress.org'       => '#meta-i18n',
+               'developer.wordpress.org'       => '#meta-devhub',
+       );
+}
+
+class bbPress extends Trac {
+       protected $primary_channel  = '#bbpress';
+       protected $commits_channel  = '#bbpress-commits';
+       protected $tickets_channel  = '#bbpress-newtickets';
+       protected $firehose_channel = '#bbpress-firehose';
+
+       protected $color = '#080';
+       protected $icon  = ':bbpress:';
+}
+
+class BuddyPress extends Trac {
+       protected $primary_channel  = '#buddypress';
+       protected $commits_channel  = '#buddypress-commits';
+       protected $tickets_channel  = '#buddypress-newtickets';
+       protected $firehose_channel = '#buddypress-firehose';
+
+       protected $color = '#d84800';
+       protected $icon  = ':buddypress:';
+}
+
+class Dotorg extends Trac {
+       protected $name = 'Private Dotorg';
+       protected $public = false;
+       protected $primary_channel = 'dotorg';
+}
+
+class Deploy extends Trac {
+       protected $public = false;
+       protected $tickets = false;
+
+       protected $primary_channel = 'dotorg';
+}
+
+class GlotPress extends Trac {
+       protected $primary_channel = '#glotpress';
+}
+
+class Build extends Trac {
+       protected $name = 'WordPress Build';
+       protected $tickets = false;
+}
+
+class BackPress extends Trac {
+}
+
+class SupportPress extends Trac {
+}
+
+class Design extends Trac {
+       protected $commit_template = 'https://core.trac.wordpress.org/changeset/design/%s';
+       protected $commit_info_template = 'https://core.trac.wordpress.org/log/%s?rev=%s&format=changelog&limit=1&verbose=on';
+}
+
+class Plugins extends Trac {
+}
+
+class Themes extends Trac {
+}
+
+class i18n extends Trac {
+       protected $name = 'WordPress i18n';
+       protected $tickets = false;
+}
+
+class Unit_Tests extends Trac {
+       protected $dormant = true;
+       protected $slug = 'unit-tests';
+       protected $name = 'Unit Tests (Old)';
+}
+
+class MU extends Trac {
+       protected $dormant = true;
+       protected $name = 'WordPress MU';
+}
+
+class OpenAtd extends Trac {
+       protected $dormant = true;
+       protected $name = 'After the Deadline';
+}
+
+class Code extends Trac {
+       protected $dormant = true;
+       protected $name = 'Code Repo';
+}
+
+class GSoC extends Trac {
+       protected $dormant = true;
+}
+
+class Security extends Trac {
+       protected $public = false;
+       protected $commits = false;
+}
+
+class WordCamp extends Trac {
+       protected $name = 'Private WordCamp.org';
+       protected $public = false;
+}
+
</ins></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachookstracnewticketphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/new-ticket.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/new-ticket.php                               (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/new-ticket.php 2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,59 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+
+class New_Ticket extends Ticket {
+       static protected function get_type( $type ) {
+               return strtr( $type, array( 'defect (bug)' => 'bug', 'task (blessed)' => 'task' ) );
+       }
+
+       function get_text() {
+               $text = parent::get_text();
+               if ( false === $this->data ) {
+                       return sprintf( 'New ticket: *%s*', $text );
+               }
+
+               return sprintf( 'New %s opened by %s: *%s*', self::get_type( $this->type ), $this->reporter, $text );
+       }
+
+       function get_attachment() {
+               $attachment = parent::get_attachment();
+               if ( false === $attachment ) {
+                       return $attachment;
+               }
+
+               $attachment['pretext'] = preg_replace( '/: /', ": \n", $attachment['text'], 1 );
+               $attachment['mrkdwn_in'][] = 'pretext';
+               $attachment['text'] = Trac::format_for_slack( $this->description );
+               $attachment['color'] = $this->trac->get_color();
+               return $attachment;
+       }
+
+       static function get_triaging_notes( $ticket ) {
+               $attachments = array();
+
+               if ( $ticket->component === 'General' ) {
+                       $attachments[] = array( 'This ticket is filed in the *General* component. Can you help triage it?', '#ffba00' );
+               }
+
+               if ( in_array( $ticket->severity, array( 'major', 'critical', 'blocker' ) ) ) {
+                       $severity = $ticket->severity === 'blocker' ? $ticket->severity = 'a blocker' : $ticket->severity;
+                       $attachments[] = array( sprintf( "%s marked this ticket as *%s*. Could you take a look?", $ticket->reporter, $severity ), '#dd3d36' );
+               }
+
+               if ( false !== strpos( $ticket->keywords, 'has-patch' ) ) {
+                       $attachments[] = array( sprintf( "%s uploaded a *patch*! Could you review it?", $ticket->reporter ), '#7ad03a' );
+               }
+
+               foreach ( $attachments as &$attachment ) {
+                       $attachment = array(
+                               'text'      => $attachment[0],
+                               'fallback'  => $attachment[0],
+                               'color'     => $attachment[1],
+                               'mrkdwn_in' => array( 'text', 'fallback' ),
+                       );
+               }
+
+               return $attachments;
+       }       
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/new-ticket.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookstracresourcephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/resource.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/resource.php                         (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/resource.php   2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,54 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+use Dotorg\Slack\User;
+
+class Resource implements User {
+
+       protected $data;
+
+       static protected $instances = array();
+
+       function __construct( Trac $trac, $id ) {
+               $this->trac = $trac;
+               $this->id   = $id;
+       }
+
+       static protected function get_resource_type() {
+               $class = get_called_class();
+               while ( get_parent_class( $class ) !== __CLASS__ ) {
+                       $class = get_parent_class( $class );
+               }
+               return strtolower( str_replace( __NAMESPACE__ . '\\', '', $class ) );
+       }
+
+       function get( Trac $trac, $id ) {
+               $key = $trac->get_slug() . ':' . static::get_resource_type() . ':' . $id;
+               if ( isset( static::$instances[ $key ] ) ) {
+                       return static::$instances[ $key ];
+               }
+               return static::$instances[ $key ] = new static( $trac, $id );
+       }
+
+       function get_name() {
+               $method = 'get_' . static::get_resource_type() . '_username';
+               return $this->trac->$method();
+       }
+
+       function get_url() {
+               $method = 'get_' . static::get_resource_type() . '_url';
+               return $this->trac->$method( $this->id );
+       }
+
+       function get_icon() {
+               return $this->trac->get_icon();
+       }
+
+       function __get( $prop ) {
+               return isset( $this->data->$prop ) ? $this->data->$prop : false;
+       }
+
+       function __isset( $prop ) {
+               return isset( $this->data->$prop );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/resource.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookstracticketphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/ticket.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/ticket.php                           (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/ticket.php     2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,145 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+
+class Ticket extends Resource {
+       protected $data;
+
+       function get_text() {
+               $this->fetch();
+
+               if ( false === $this->data ) {
+                       return $this->get_url();
+               }
+
+               return sprintf( "<%s|#%s: %s>", $this->get_url(), $this->id, htmlentities( $this->summary, ENT_NOQUOTES ) );
+       }
+
+       function get_short_attachment() {
+               $this->fetch();
+
+               if ( false === $this->data ) {
+                       return false;
+               }
+
+               $text = $this->get_text();
+
+               return array(
+                       'text'      => $text,
+                       'fallback'  => $text,
+                       'mrkdwn_in' => array( 'text', 'fallback' ),
+               );
+       }
+
+       function get_attachment() {
+               $attachment = $this->get_short_attachment();
+
+               if ( false === $attachment ) {
+                       return false;
+               }
+
+               $attachment['fields'] = self::get_ticket_fields( $this->data );
+               return $attachment;
+       }
+
+       function fetch() {
+               if ( isset( $this->data ) ) {
+                       return $this->data;
+               }
+
+               if ( ! $this->trac->is_public() || ! $this->trac->has_tickets() ) {
+                       $this->data = false;
+                       return;
+               }
+
+               $url = $this->get_url() . '?format=csv';
+               $contents = @file_get_contents( $url );
+               if ( $contents === false ) {
+                       $this->data = false;
+                       return;
+               }
+
+               // The first line are headers. All additional lines are part of
+               // of a single CSV row (there can be \n in content).
+               $contents = explode( "\n", $contents, 2 );
+               $ticket_info = array_combine(
+                       str_getcsv( $contents[0], ',', '"', '"' ),
+                       str_getcsv( $contents[1], ',', '"', '"' )
+               );
+
+               $this->data = (object) $ticket_info;
+               return $this->data;
+       }
+
+       static function get_ticket_fields( $ticket ) {
+               $new = false !== strpos( get_class( $this ), 'New_Ticket' );
+       
+               $ticket_fields = array();
+
+               if ( isset( $ticket->type ) && ! $new ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Type',
+                               'value' => $ticket->type,
+                               'short' => true,
+                       );
+               }
+
+               if ( isset( $ticket->status, $ticket->resolution ) && ( ! $new || $ticket->status === 'open' ) ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Status',
+                               'value' => $ticket->status === 'closed' ? $ticket->resolution : 'open',
+                               'short' => true,
+                       );
+               }
+
+               if ( ! empty( $ticket->component ) ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Component' . ( ! empty( $ticket->focuses ) ? ' (Focuses)' : '' ),
+                               'value' => $ticket->component . ( ! empty( $ticket->focuses ) ? ' (' . $ticket->focuses . ')' : '' ),
+                               'short' => true,
+                       );
+               }
+
+               if ( ! empty( $ticket->version ) ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Version',
+                               'value' => $ticket->version,
+                               'short' => true,
+                       );
+               }
+
+               if ( ! empty( $ticket->milestone ) && ( ! $new || $ticket->milestone !== 'Awaiting Review' ) ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Milestone',
+                               'value' => $ticket->milestone,
+                               'short' => true,
+                       );
+               }
+
+               if ( ! empty( $ticket->severity ) && ! empty( $ticket->priority ) && ! ( $ticket->severity === 'normal' && $ticket->priority === 'normal' ) ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Severity / Priority',
+                               'value' => sprintf( '%s/%s', $ticket->severity, $ticket->priority ),
+                               'short' => true,
+                       );
+               } elseif ( ( ! empty( $ticket->severity ) && $ticket->severity !== 'normal' ) || ( ! empty( $ticket->priority ) && $ticket->priority !== 'normal' ) ) {
+                       $ticket_fields[] = array(
+                               'title' => ! empty( $ticket->severity ) ? 'Severity' : 'Priority',
+                               'value' => ! empty( $ticket->severity ) ? $ticket->severity : $ticket->priority,
+                               'short' => true,
+                       );
+               }
+
+               if ( $ticket->keywords ) {
+                       $ticket_fields[] = array(
+                               'title' => 'Keywords',
+                               'value' => $ticket->keywords,
+                               // Make keywords 'short' if it's in column 2.
+                               // Otherwise, ensure it doesn't need to wrap if it's in column 1 at the bottom.
+                               'short' => (bool) ( count( $ticket_fields ) % 2 === 1 ),
+                       );
+               }
+
+               return $ticket_fields;
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/ticket.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunksvnwordpressorgincludesslacktrachookstractracphpfromrev1080sitestrunksvnwordpressorgincludesslacktrachookstracphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/trac.php (from rev 1080, sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/trac.php                             (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac/trac.php       2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,290 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack\Trac;
+use Dotorg\Slack\User;
+
+class Trac implements User {
+       protected $public = true;
+       protected $commits = true;
+       protected $tickets = true;
+
+       protected $primary_channel  = '#test';
+       protected $tickets_channel  = false;
+       protected $commits_channel  = false;
+       protected $firehose_channel = false;
+       protected $commit_username;
+       protected $ticket_username;
+
+       // 'title', 'fields', 'description'
+       protected $primary_channel_ticket_format = 'description';
+
+       protected $bypass_primary_channel_for_commit_filter_matches = false;
+       protected $bypass_primary_channel_for_ticket_filter_matches = false;
+
+       protected $commit_path_filters = array();
+       protected $ticket_component_filters = array();
+
+       protected $color = '#21759b';
+       protected $icon  = ':wordpress:';
+
+       protected $ticket_template = 'https://%s.trac.wordpress.org/ticket/%s';
+       protected $commit_template = 'https://%s.trac.wordpress.org/changeset/%s';
+       protected $commit_info_template = 'https://%s.trac.wordpress.org/log/?rev=%s&format=changelog&limit=1&verbose=on';
+
+       const min_digits = 2;
+       const max_digits = 5;
+
+       static protected $shorthands = array(
+               'wp'        => 'core',
+               'wordpress' => 'core',
+               'develop'   => 'core',
+               'bb'        => 'bbpress',
+       );
+
+       protected function __construct() {
+               if ( isset( $this->trac, $this->name ) ) {
+                       return;
+               }
+
+               // 'Dotorg\Slack\Trac\Tracs\Core' => 'Core'
+               $class = str_replace( __NAMESPACE__ . '\\Tracs\\', '', get_class( $this ) );
+
+               if ( ! isset( $this->trac ) ) {
+                       $this->trac = strtolower( $class );
+               }
+
+               if ( ! isset( $this->name ) ) {
+                       $this->name = str_replace( '_', ' ', $class );
+               }
+
+               if ( ! isset( $this->ticket_username ) ) {
+                       $this->ticket_username = $this->name . ' Trac';
+               }
+
+               if ( ! isset( $this->commit_username ) ) {
+                       $this->commit_username = $this->name . ' commit';
+               }
+
+               foreach ( $this->commit_path_filters as $path => $channel ) {
+                       if ( is_string( $channel ) ) {
+                               $this->commit_path_filters[ $path ] = array( $channel => true );
+                       }
+                       if ( $this->bypass_primary_channel_for_commit_filter_matches && empty( $this->commit_path_filters[ $path ][ $this->primary_channel ] ) ) {
+                               $this->commit_path_filters[ $path ][ $this->primary_channel ] = false;
+                       }
+               }
+
+               foreach ( $this->ticket_component_filters as $component => $channel ) {
+                       if ( is_string( $channel ) ) {
+                               $this->ticket_component_filters[ $component ] = array( $channel => true );
+                       }
+            if ( $this->bypass_primary_channel_for_ticket_filter_matches && empty( $this->ticket_component_filters[ $path ][ $this->primary_channel ] ) ) {
+                $this->ticket_component_filters[ $path ][ $this->primary_channel ] = false;
+            }
+               }
+       }
+
+       static function get( $trac ) {
+               require_once __DIR__ . '/config.php';
+               if ( $trac instanceof Trac ) {
+                       return $trac;
+               }
+
+               $ns = __NAMESPACE__ . '\\Tracs\\';
+
+               $class = $ns . $trac;   
+               if ( class_exists( $class ) ) {
+                       return new $class;
+               }
+
+               if ( isset( self::$shorthands[ $trac ] ) ) {
+                       $class = $ns . self::$shorthands[ $trac ];
+                       return new $class;
+               }
+               
+               if ( preg_match( '~([a-z]+).trac.wordpress.org~', $url, $match ) ) {
+                       $class = $ns . $match[1];
+                       if ( class_exists( $class ) ) {
+                               return new $class;
+                       }
+               }
+
+               return false;
+       }
+
+       static function get_regex() {
+               return implode( '|', array_merge( self::get_registered_tracs(), array_keys( self::$shorthands ) ) );
+       }
+
+       static function get_registered_tracs() {
+               require_once __DIR__ . '/config.php';
+               $classes = get_declared_classes();
+               $tracs = array();
+
+               foreach ( $classes as $key => $class ) {
+                       if ( 0 !== strpos( $class, __NAMESPACE__ . '\\Tracs\\' ) ) {
+                               continue;
+                       }
+
+                       $tracs[] = strtolower( str_replace( array( __NAMESPACE__ . '\\Tracs\\', '_' ), array( '', '-' ), $class ) );
+               }
+
+               return $tracs;
+       }
+
+       function get_slug() {
+               return $this->trac;
+       }
+
+       function get_commit_username() {
+               return $this->commit_username;
+       }
+
+       function get_ticket_username() {
+               return $this->ticket_username;
+       }
+
+       function get_color() {
+               return $this->color;
+       }
+
+       function get_name() {
+               return $this->name . ' Trac';
+       }
+
+       function get_icon() {
+               return $this->icon;
+       }
+
+       function get_ticket_url( $ticket ) {
+               return $this->get_ticket_template( $ticket );
+       }
+
+       function get_ticket_template( $template = '%s' ) {
+               return sprintf( $this->ticket_template, $this->trac, $template );
+       }
+
+       function get_commit_url( $commit ) {
+               return $this->get_commit_template( $commit );
+       }
+
+       function get_commit_template( $template = '%s' ) {
+               return sprintf( $this->commit_template, $this->trac, $template );
+       }
+
+       function get_commit_info_url( $commit ) {
+               return sprintf( $this->commit_info_template, $this->trac, $commit );
+       }
+
+       function is_public() {
+               return (bool) $this->public;
+       }
+
+       function has_tickets() {
+               return (bool) $this->tickets;
+       }
+
+       function has_commits() {
+               return (bool) $this->commits;
+       }
+
+       static function get_digit_capture() {
+               $min = self::min_digits - 1;
+               $max = self::max_digits - 1;
+               return '[1-9][0-9]{' . $min . ',' . $max . '}';
+       }
+
+       function get_log_replacements() {
+               $commit_template = $this->get_commit_template( '$1' );
+               $digits = self::get_digit_capture();
+
+               return array(
+                       "/#($digits)\b/"   => $this->get_ticket_template( '$1' ),
+                       "/\[($digits)\]/"  => $commit_template,
+                       "/\br($digits)\b/" => $commit_template,
+               );
+       }
+
+       function get_commit_channels( $changed_files = null ) {
+               $channels = array();
+
+               if ( $this->primary_channel ) {
+                       $channels[ $this->primary_channel ] = true;
+               }
+
+               if ( $this->commits_channel ) {
+                       $channels[ $this->commits_channel ] = true;
+               }
+
+               foreach ( $this->commit_path_filters as $needle => $channels_to_add ) {
+                       if ( $needle[0] === '#' ) {
+                               // Append PCRE_MULTILINE so ^ and $ refer to individual lines.
+                               if ( preg_match( $needle . 'm', $changed_files ) ) {
+                                       $channels = array_merge( $channels, (array) $channels_to_add );
+                               }
+                       } elseif ( false !== strpos( $changed_files, $needle ) ) {
+                               $channels = array_merge( $channels, (array) $channels_to_add );
+                       }
+               }
+
+               if ( $this->firehose_channel ) {
+                       $channels[ $this->firehose_channel ] = true;
+               }
+
+               return array_keys( array_filter( $channels ) );
+       }
+
+       function get_ticket_channels( $ticket = null ) {
+               $channels = array();
+
+               if ( $this->primary_channel ) {
+                       $channels[ $this->primary_channel ] = true;
+               }
+
+               if ( $this->tickets_channel ) {
+                       $channels[ $this->tickets_channel ] = true;
+               }
+
+               if ( isset( $ticket->component ) && isset( $this->ticket_component_filters[ $ticket->component ] ) ) {
+                       $channels = array_merge( $channels, (array) $this->ticket_component_filters[ $ticket->component ] );
+               }
+
+               if ( isset( $ticket->focuses ) ) {
+                       foreach ( explode( ', ', $ticket->focuses ) as $focus ) {
+                               if ( isset( $this->ticket_component_filters[ $focus ] ) ) {
+                                       $channels = array_merge( $channels, (array) $this->ticket_component_filters[ $focus ] );
+                               }
+                       }
+               }
+
+               if ( $this->firehose_channel ) {
+                       $channels[ $this->firehose_channel ] = true;
+               }
+
+               return array_keys( array_filter( $channels ) );
+       }
+
+       function get_firehose_channel() {
+               return $this->firehose_channel;
+       }
+
+       function get_ticket_format( $channel ) {
+               if ( $channel === $this->primary_channel ) {
+                       return $this->primary_channel_ticket_format;
+               }               
+               return 'description';
+       }
+
+       function format_for_slack( $text ) {
+               $text = str_replace( "\r\n", "\n", $text );
+               $text = trim( str_replace(
+                       array( "\n{{{\n", "\n}}}\n", '{{{', '}}}' ),        
+                       array( "\n```\n", "\n```\n", '`',   '`' ),
+                       "\n$text\n"
+               ), "\n" );
+
+               // TODO: bold, italic, links
+
+               return $text;
+       }
+}
</ins></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachookstracphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac.php  2015-01-11 05:35:52 UTC (rev 1120)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/trac.php    2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,130 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-namespace Dotorg\SlackTracHooks;
-
-abstract class Trac {
-       protected $commit_channels = '#test';
-       protected $commit_username = 'Commit';
-       protected $ticket_channels = '#test';
-       protected $ticket_username;
-
-       protected $firehose_channel = false;
-
-       protected $color    = '#21759b';
-       protected $emoji    = ':wordpress:';
-
-       protected $ticket_template = 'https://%s.trac.wordpress.org/ticket/%s';
-       protected $commit_template = 'https://%s.trac.wordpress.org/changeset/%s';
-       protected $ticket_range = array( 1, 5 );
-       protected $commit_range = array( 1, 5 );
-
-       function __construct() {
-               // 'Dotorg\SlackTracHooks\Core_Trac' => 'Core_Trac'
-               $class = str_replace( __NAMESPACE__ . '\\', '', get_class( $this ) );
-
-               // 'Core_Trac' => 'core'
-               $this->trac = strtolower( str_replace( '_Trac', '', $class ) );
-
-               if ( ! isset( $this->ticket_username ) ) {
-                       // 'Core_Trac' => 'Core Trac'
-                       $this->ticket_username = str_replace( '_', ' ', $class );
-               }
-       }
-
-       function get_commit_username() {
-               return $this->commit_username;
-       }
-
-       function get_ticket_username() {
-               return $this->ticket_username;
-       }
-
-       function get_color() {
-               return $this->color;
-       }
-
-       function get_emoji() {
-               return $this->emoji;
-       }
-
-       function get_ticket_template( $template = '%s' ) {
-               return sprintf( $this->ticket_template, $this->trac, $template );
-       }
-
-       function get_commit_template( $template = '%s' ) {
-               return sprintf( $this->commit_template, $this->trac, $template );
-       }
-
-       function get_digit_capture( $range ) {
-               $min = $range[0] - 1;
-               $max = $range[1] - 1;
-               return '[0-9]\d{' . $min . ',' . $max . '}';
-       }
-
-       function get_log_replacements() {
-               $commit_template = $this->get_commit_template( '$1' );
-               $ticket_digits = $this->get_digit_capture( $this->ticket_range );
-               $commit_digits = $this->get_digit_capture( $this->commit_range );
-
-               return array(
-                       "/#($ticket_digits)\b/"   => $this->get_ticket_template( '$1' ),
-                       "/\[($commit_digits)\]/"  => $commit_template,
-                       "/\br($commit_digits)\b/" => $commit_template,
-               );
-       }
-
-       function get_commit_channels( $changed_files = null ) {
-               $channels = (array) $this->commit_channels;
-
-               if ( ! empty( $this->firehose_channel ) ) {
-                       $channels[] = $this->firehose_channel;
-               }
-
-               if ( empty( $this->commit_path_filters ) || empty( $changed_files ) ) {
-                       return $channels;
-               }
-
-               foreach ( $this->commit_path_filters as $needle => $channels_to_add ) {
-                       if ( $needle[0] === '#' ) {
-                               // Append PCRE_MULTILINE so ^ and $ refer to individual lines.
-                               if ( preg_match( $needle . 'm', $changed_files ) ) {
-                                       $channels = array_merge( $channels, (array) $channels_to_add );
-                               }
-                       } elseif ( false !== strpos( $changed_files, $needle ) ) {
-                               $channels = array_merge( $channels, (array) $channels_to_add );
-                       }
-               }
-       
-               return $channels;
-       }
-
-       function get_ticket_channels( $ticket = null ) {
-               $channels = (array) $this->ticket_channels;
-
-               if ( ! empty( $this->firehose_channel ) ) {
-                       $channels[] = $this->firehose_channel;
-               }
-
-               if ( empty( $this->ticket_component_filters ) || empty( $ticket ) ) {
-                       return $channels;
-               }
-
-               if ( isset( $ticket->component ) && isset( $this->ticket_component_filters[ $ticket->component ] ) ) {
-                       $channels = array_merge( $channels, (array) $this->ticket_component_filters[ $ticket->component ] );
-               }
-
-               if ( isset( $ticket->focuses ) ) {
-                       foreach ( explode( ', ', $ticket->focuses ) as $focus ) {
-                               if ( isset( $this->ticket_component_filters[ $focus ] ) ) {
-                                       $channels = array_merge( $channels, (array) $this->ticket_component_filters[ $focus ] );
-                               }
-                       }
-               }
-               return $channels;
-       }
-
-       function get_firehose_channel() {
-               return $this->firehose_channel;
-       }
-}
-
</del></span></pre></div>
<a id="sitestrunksvnwordpressorgincludesslacktrachooksuserphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/user.php                          (rev 0)
+++ sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/user.php    2015-01-11 11:00:02 UTC (rev 1121)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,9 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace Dotorg\Slack;
+
+interface User {
+       public function get_icon();
+       public function get_name();
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/svn.wordpress.org/includes/slack-trac-hooks/user.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>

</body>
</html>