[PHP] Getting info from SVN commit with php
Hi, I would be very grateful if someone could point out some ways how to do the following: I have an SVN server but I need to add some extra to commit message which PHP will get and use(for example use the parameters from commit message to change data on mysql database... (if commit messages first line has character *, then run sql query... update tasks set some_row='OK' where Currently important is: 1) Is it even possible to get commit messages text with php ? Since I can't find the file where commit messages are. I only digged subversion docs for 'how to edit message' Should, be possible(bot nut sure) to use commands: $ svn propedit -r N --revprop svn:log URL $ svn propset -r N --revprop svn:log new log message URL What I'd like to achieve is: I'l' make page where I store all my tasks (for example Need to add login function to test.php). In MySQL, this task has got ID 1 and STATUS 0 which means it isn't done yet. Then when I have that task done I start writing commit message where first line may look like this: 1|1 and rest of the lines will be regular commit message. Then there will be PHP script which checks that commit message and reads that line where I put 1|1 and understands that first number is task ID and second is STATUS and then run sql query like: update tasks set STATUS=1 where ID=1; So, seems impossible? For me, currently yes, since I haven't found any examples how to do it...but I know that nothing is impossible. Raido -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting info from SVN commit with php
On 7/23/08, Raido [EMAIL PROTECTED] wrote: I have an SVN server but I need to add some extra to commit message which PHP will get and use(for example use the parameters from commit message to change data on mysql database... (if commit messages first line has character *, then run sql query... update tasks set some_row='OK' where There's an SVN PECL module: http://pecl.php.net/package/svn Also, you can easily run these kind of commands via system() - I've done that in the past, but now that there's this SVN PECL module I've been wanting to get aligned that way. Always better in my opinion to use APIs and not system() calls. If the svn module doesn't meet your needs you can ask for enhancements, or just use system() for now. here's a couple functions I wrote. $config['svn'] was the path to the svn command (like /usr/bin/svn) i used the xml output option so i could parse it using simplexml. also, i pass it a username, password and repository since i support multiple repositories and each one has a unique username/password set. it worked like a charm. i am sure you can tailor this code to suit your needs. # get the latest revision # function svn_latest($username, $password, $repository) { $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']. info --xml --non-interactive --no-auth-cache --username {$username} --password{$password} svn://localhost/{$repository})); return intval($xml-entry-commit['revision']); } function svn_history($username, $password, $repository, $count = 20, $start = 0, $latest = 0) { # svn's revisions are incremental, so we need to calculate backwards to find the right offsets if($latest == 0) { $latest = svn_latest($username, $password, $repository); } $start = $latest - $start; $end = intval($start - $count) + 1; if($end 0) { $end = 0; } $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']. log --xml --non-interactive --no-auth-cache --username {$username} --password {$password} -r {$start}:{$end} svn://localhost/{$repository})); return $xml; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting info from SVN commit with php
Thank You for that fast reply. PECL was something that I din't know about. But I'll dig in with Your examples and also PECL and try to find most simple but well-working solution. Also sorry for Return Receipt, turned that off. mike wrote: On 7/23/08, Raido [EMAIL PROTECTED] wrote: I have an SVN server but I need to add some extra to commit message which PHP will get and use(for example use the parameters from commit message to change data on mysql database... (if commit messages first line has character *, then run sql query... update tasks set some_row='OK' where There's an SVN PECL module: http://pecl.php.net/package/svn Also, you can easily run these kind of commands via system() - I've done that in the past, but now that there's this SVN PECL module I've been wanting to get aligned that way. Always better in my opinion to use APIs and not system() calls. If the svn module doesn't meet your needs you can ask for enhancements, or just use system() for now. here's a couple functions I wrote. $config['svn'] was the path to the svn command (like /usr/bin/svn) i used the xml output option so i could parse it using simplexml. also, i pass it a username, password and repository since i support multiple repositories and each one has a unique username/password set. it worked like a charm. i am sure you can tailor this code to suit your needs. # get the latest revision # function svn_latest($username, $password, $repository) { $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']. info --xml --non-interactive --no-auth-cache --username {$username} --password{$password} svn://localhost/{$repository})); return intval($xml-entry-commit['revision']); } function svn_history($username, $password, $repository, $count = 20, $start = 0, $latest = 0) { # svn's revisions are incremental, so we need to calculate backwards to find the right offsets if($latest == 0) { $latest = svn_latest($username, $password, $repository); } $start = $latest - $start; $end = intval($start - $count) + 1; if($end 0) { $end = 0; } $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']. log --xml --non-interactive --no-auth-cache --username {$username} --password {$password} -r {$start}:{$end} svn://localhost/{$repository})); return $xml; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting info from SVN commit with php
On Wed, Jul 23, 2008 at 8:22 AM, Raido [EMAIL PROTECTED] wrote: 1) Is it even possible to get commit messages text with php ? Since I can't find the file where commit messages are. Just a quick answer to this: in your directory of your project repo, go into the hooks/ subdirectory. In there, you'll find a post-commit.tmpl file. Remove the .tmpl extension and chmod 755 post-commit (if on *NIX). When a commit is made, post-commit will be executed by SVN. Conversely, if you want the script to execute on a different trigger, just use a different name for the script, including pre-commit, pre-lock, post-lock, post-revprop-change, et cetera. One of my post-commit scripts looks like this (with names changed to protect the innocent): #!/bin/bash REPOS=$1 REV=$2 AUTHOR=`/usr/bin/svnlook author -r $REV $REPOS` CHANGED=`/usr/bin/svnlook changed -r $REV $REPOS` DIFF=`/usr/bin/svnlook diff -r $REV $REPOS` /usr/bin/php -q /home/repos/sites/example-com/hooks/post-commit.php $REPOS $REV $AUTHOR $CHANGED $DIFF And then, the PHP script it calls (post-commit.php) from the shellscript above: #!/usr/bin/php -q ?php $repo = $argv[1]; $rev = $argv[2]; $username = $argv[3]; $changes = $argv[4]; $diff = $argv[5]; $datetime = date(D, j F, Y). at .date(H:i:s T); $to = [EMAIL PROTECTED]; $subject = [SVN] Commit by .$username; $body = \n; $body .= \tChanges have been made to the SVN repository. The revision number is now .$rev.. Details follow.\n; $body .= \n; $body .= Committed at .$datetime.\n; $body .= Committed By: .$username.\n; $body .= Repository: .$repo.\n; $body .= Revision # .$rev.\n; $body .= \n\n; $body .= List of changes: \n; $body .= $changes.\n; $body .= \n\n; $body .= Differences:\n; $body .= $diff.\n; $body .= \n; $headers = From: \SVN: .$username.\ [EMAIL PROTECTED]\r\n; $headers .= X-Mailer: PHP/.phpversion().\r\n; mail($to,$subject,$body,$headers); ? -- /Daniel P. Brown Better prices on dedicated servers: Intel 2.4GHz/60GB/512MB/2TB $49.99/mo. Intel 3.06GHz/80GB/1GB/2TB $59.99/mo. Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php