<?php
$recipients = array(
'svncommitter' => 'email@example.com',
);
include 'XMPPHP/XMPP.php';
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'svnlog@example.com', 's3cr3t', 'xmpphp','example.com');
try {
$conn->connect();
$conn->processUntil('session_start');
$conn->presence();
$message = commit_message();
foreach ($recipients as $recipient => $jid) {
if ($recipient != $author) {
$conn->message($jid, $message);
}
}
$conn->disconnect();
} catch(XMPPHP_Exception $e) {
exit;
}
function commit_message() {
$svnroot = 'file:///'.str_replace(DIRECTORY_SEPARATOR,'/',$_SERVER['argv'][1]);
$rev = $_SERVER['argv'][2];
$cmd = 'svn log --xml -v --revision '.$rev.' '.$svnroot;
if (exec ($cmd,$output)) {
$result = implode('',$output);
$dom = simplexml_load_string($result);
$commit = $dom->logentry;
$author = (string)$commit->author;
$paths = $commit->paths->path;
$messages = array();
$messages[] = '';
$messages[] = $author.' закоммитил ревизию '.$rev;
$msg = trim((string)$commit->msg);
$messages[] = 'Комментарий: '.((strlen($msg)) ? $msg : 'ПУСТОЙ!!!!!');
$actions = array(
'A' => 'добавлен',
'D' => 'удалён',
'M' => 'изменён',
);
if ($paths) {
$messages[] = 'Затронутые файлы:';
foreach ($paths as $elem) {
$attrs = $elem->attributes();
$action = (string)$attrs['action'];
$messages[] = $actions[$action].' '.(string)$elem;
}
}
}
return implode(PHP_EOL,$messages);
}
?>