4 * GForge Plugin SVNTracker HTTPPoster
6 * Portions Copyright 2004 (c) Roland Mas <99.roland.mas @nospam@ aist.enst.fr>
7 * The rest Copyright 2004 (c) Francisco Gimeno <kikov @nospam@ kikov.org>
9 * This file is part of GForge-plugin-svntracker
11 * GForge-plugin-svntracker is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * GForge-plugin-svntracker is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY; without even the implied
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * This is the script called by svn. It takes some params, and prepare some
28 * HTTP POSTs to /plugins/svntracker/newcommit.php.
32 require_once dirname(__FILE__)."/../../env.inc.php";
33 require_once $gfcommon.'include/pre.php';
34 require $gfplugins.'svntracker/common/Snoopy.class.php';
37 * It returns the usage and exit program
42 function usage( $argv ) {
43 echo "Usage: $argv[0] <Repository> <Revision> \n";
48 * It returns a list of involved artifacts.
49 * An artifact is identified if [#(NUMBER)] if found.
51 * @param string $Log Log message to be parsed.
53 * @return boot Returns true if check passed.
55 function getInvolvedArtifacts($Log)
57 preg_match_all('/[[]#[\d]+[]]/', $Log, $Matches );
58 foreach($Matches as $Match)
60 $Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
66 * It returns a list of involved artifacts.
67 * An artifact is identified if [T(NUMBER)] is found.
69 * @param string $Log Log message to be parsed.
71 * @return boot Returns true if check passed.
73 function getInvolvedTasks($Log)
75 preg_match_all ('/[[]T[\d]+[]]/', $Log, $Matches );
76 foreach($Matches as $Match)
78 $Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
84 * Parse input and get the Log message.
86 * @param string $Input Input from stdin.
88 * @return array Array of lines of Log Message.
90 function getLog($Input)
92 $Lines = explode("\n", $Input);
95 for ( $i=0; $i < $ii ; $i++ )
98 $Log.=$Lines[$i]."\n";
99 if ($Lines[$i]=='Log Message:')
107 if (count($argv) != 3) {
109 Usage: $0 <repository> <revision>
110 This program should be automatically called by SVN
116 $repository = $argv[1];
117 $revision = $argv[2];
119 $UserName = trim(`svnlook author -r $revision $repository`); //username of author
120 $date = trim(`svnlook date -r $revision $repository`); //date
121 $log = trim(`svnlook log -r $revision $repository`); // the log
122 $changed = trim(`svnlook changed -r $revision $repository | sed 's/[A-Z]* //'`); // the filenames
124 if ($svn_tracker_debug) {
125 fwrite($file,"Vars filled:\n");
126 fwrite($file,"username : " . $UserName . " \n");
127 fwrite($file,"date : " . $date . " \n");
128 fwrite($file,"log : " . $log . " \n");
129 fwrite($file,"changed : " . $changed . " \n");
132 $changed = explode("\n", $changed);
134 foreach ($changed as $onefile) {
135 //we must see when it was last changed, and that's previous revision
137 $actrev = $revision - 1;
142 while ( (!$exit) && ($actrev != 0 ) ) {
143 $changed2 = trim(`svnlook changed -r $actrev $repository | sed 's/[A-Z]* //'`);
144 $changed2 = explode("\n", $changed2);
145 if ( in_array($onefile,$changed2) ) {
149 $actrev = $actrev - 1 ;
156 'name' => $repository . "/" . $onefile,
158 'actual' => $revision
163 // Our POSTer in Gforge
164 $snoopy = new Snoopy;
166 $SubmitUrl = util_make_url('/plugins/svntracker/newcommit.php');
168 $tasks_involved= getInvolvedTasks($log);
169 $artifacts_involved= getInvolvedArtifacts($log);
170 if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
171 (!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
173 die("No artifacts nor tasks in the commit log\n");
177 foreach ( $files as $onefile )
179 $SubmitVars[$i]["UserName"] = $UserName;
180 $SubmitVars[$i]["Repository"] = $repository;
181 $SubmitVars[$i]["FileName"] = $onefile['name'];
182 $SubmitVars[$i]["PrevVersion"] = $onefile['previous'];
183 $SubmitVars[$i]["ActualVersion"] = $onefile['actual'];
184 $SubmitVars[$i]["Log"] = $log;
185 $SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($log);
186 $SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($log);
187 $SubmitVars[$i]["SvnDate"] = time();
191 $vars['data'] = serialize($SubmitVars);
192 $snoopy->submit($SubmitUrl,$vars);