Re: [SVN-MIGRATION] cvs: SVNROOT / commit-email.php
[email protected] ("Alexey Zakhlestin")
| Newsgroups | svn.migration |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Nov 11, 2008 at 12:19 AM, Gwynne Raskind <[email protected]> wrote: > gwynne Mon Nov 10 21:19:10 2008 UTC > > Added files: > /SVNROOT commit-email.php > Log: > commit e-mail script I see, that you use svnlook using commandline.. Did you consider using pecl-svn extension? http://pecl.php.net/package/svn Also, I wrote commit-script in php several years ago, which was producing nice output. It won't be possible to use it directly, I think (objectives are different), but still it can give some ideas.. I didn't use it for awhile, so there is a chance, that it is not more compatible with current pecl-svn api, but that should be easily fixable http://freshmeat.net/projects/php_svncommit/ > http://cvs.php.net/viewvc.cgi/SVNROOT/commit-email.php?view=markup&rev=1.1 > Index: SVNROOT/commit-email.php > +++ SVNROOT/commit-email.php > <?php > > // ----------------------------------------------------------------------------------------------------------------------------- > // Settings > error_reporting(E_ALL | E_STRICT); > date_default_timezone_set('UTC'); > > // ----------------------------------------------------------------------------------------------------------------------------- > // Constants > $version = substr('$Revision: 1.1 $', strlen('$Revision: '), -2); > $email_to = array('[email protected]'); > $smtp_server = '127.0.0.1'; > > // ----------------------------------------------------------------------------------------------------------------------------- > // Version check > if (version_compare('5.2.0', PHP_VERSION, '>')) { > die("Requires at least PHP 5.2.\n"); > } > > // ----------------------------------------------------------------------------------------------------------------------------- > // Arguments > if ($argc != 3) { > die("Pass exactly two arguments: REPOS and REV.\n"); > } > $REPOS = $argv[1]; > $REV = $argv[2]; > > // ----------------------------------------------------------------------------------------------------------------------------- > // Utility > function run_svnlook($command) > { > exec('exec svnlook ' . escapeshellarg($command) . ' -r ' . escapeshellarg($GLOBALS['REV']) . ' ' . escapeshellarg($GLOBALS['REPOS']), $output, $status); > if ($status != 0) { > die("svnlook failed with exit code {$status}\nOutput:\n" . implode("\n", $output) . "\n"); > } > return $output; > } > > // ----------------------------------------------------------------------------------------------------------------------------- > // Get info from commit > $commit_info = run_svnlook('info'); > $commit_user = $commit_info[0]; > $commit_date = strtotime(substr($commit_info[1], 0, strlen("0000-00-00 00:00:00 +0000"))); > $commit_log = implode("\n", array_slice($commit_info, 3)); > > // ----------------------------------------------------------------------------------------------------------------------------- > // Determine "from" address > // Various repositories can play with this to read from their equivelant of the old cvsusers folder, or whatever else they like > $from = '[email protected]'; > > // ----------------------------------------------------------------------------------------------------------------------------- > // Build list of changes > $changed_paths = run_svnlook('changed'); > > // ----------------------------------------------------------------------------------------------------------------------------- > // Get diffs > $diffs = run_svnlook('diff'); > $diffs = implode("\n", $diffs); > > // ----------------------------------------------------------------------------------------------------------------------------- > // Parent changed path > $dirs_changed = run_svnlook('dirs-changed'); > $parent_path = $dirs_changed[0]; > foreach ($dirs_changed as $dir_changed) { > if (strlen($dir_changed) < strlen($parent_path)) { > $parent_path = $dir_changed; > } > } > > // ----------------------------------------------------------------------------------------------------------------------------- > // Build e-mail > $msg_headers = "From: {$from}\n" . > "To: " . implode(', ', $email_to) . "\n" . > "Message-ID: <svn{$commit_user}{$commit_date}@svn.php.net>\n" . > "Date: " . date(DATE_RFC822, $commit_date) . "\n" . > "Subject: svn: {$parent_path}\n"; > > $msg_body = "{$commit_user}\t\t" . date(DATE_RFC2822, $commit_date) . "\n" . > "\n" . > "Changed paths:\n" . > "\t" . implode("\n\t", $changed_paths) . "\n" . > "\n" . > "Log:\n" . > wordwrap($commit_log, 80, "\n") . "\n" . > "\n"; > > if (strlen($diffs) >= 8000) { > $boundary = $commit_user. $commit_date; > $msg_headers .= "MIME-Version: 1.0\n" . > "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n"; > $msg_body = "This is a MIME encoded message.\n\n--{$boundary}\n" . > "Content-Type: text/plain\n" . > "\n" . > "{$msg_body}\n" . > "--{$boundary}\n" . > "Content-Type: text/plain\n" . > "Content-Disposition: attachment; filename=\"{$boundary}.txt\"\n" . > "\n" . > "{$diffs}\n" . > "--{$boundary}--\n"; > } else { > $msg_body .= $diffs; > } > > $complete_email = $msg_headers . "\n" . $msg_body; > $complete_email = str_replace(array("\r", "\n", "\r\n."), array("", "\r\n", ".."), $complete_email); > > // ----------------------------------------------------------------------------------------------------------------------------- > // Send e-mail > if (isset($_ENV['DEBUG']) && $_ENV['DEBUG'] == 'DEBUG') { > $socket = fopen("php://stdout", "w"); > } else { > $socket = fsockopen($smtp_server, getservbyname('smtp', 'tcp'), $errno); > } > if ($socket === FALSE) { > die("Couldn't connect to SMTP server {$smtp_server}. Errno: {$errno}.\n"); > } > > fwrite($socket, > "HELO svnserver\r\n" . > "MAIL FROM:<[email protected]>\r\n"); > foreach ($email_to as $send_addr) { > fwrite($socket, "RCPT TO:<{$email_to}>\r\n"); > } > fwrite($socket, > "DATA\r\n" . > $complete_email . "\r\n" . > ".\r\n" . > "QUIT\r\n"); > fclose($socket); > > // ----------------------------------------------------------------------------------------------------------------------------- > // Done! > exit(0); > > ?> > > > > -- > SVN Migration Project Mailing List (http://svn.php.net) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Alexey Zakhlestin http://blog.milkfarmsoft.com/