4 * GForge Plugin CVSTracker 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-cvstracker
11 * GForge-plugin-cvstracker 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-cvstracker 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
22 * along with GForge-plugin-cvstracker; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
29 * This is the script called by cvs. It takes some params, and prepare some
30 * HTTP POSTs to /plugins/cvstracker/newcommit.php.
34 //require ('local.inc'); we donĀ“t need this file. also, in some installations this file cannot be accessed by the caller (perms problem)
35 require ('plugins/cvstracker/config.php');
36 require ($sys_plugins_path.'/cvstracker/common/Snoopy.class.php');
39 if ($cvs_binary_version != "1.12" &&
40 $cvs_binary_version != "1.11" )
41 $cvs_binary_version = "1.12";
43 * It returns the usage and exit program
48 function usage( $argv ) {
49 global $cvs_binary_version;
50 if ($cvs_binary_version == "1.12" ) {
51 echo "Usage: $argv[0] <Repository> <Path> [<File> <VersionFrom> <VersionTo>]xN\n";
53 if ($cvs_binary_version == "1.11" ) {
54 echo "Usage: $argv[0] <Repository> [<File>,<VersionFrom>,<VersionTo>xN]\n";
60 * It returns a list of involved artifacts.
61 * An artifact is identified if [#(NUMBER)] if found.
63 * @param string $Log Log message to be parsed.
65 * @return boot Returns true if check passed.
67 function getInvolvedArtifacts($Log)
69 preg_match_all('/[[]#[\d]+[]]/', $Log, $Matches );
70 foreach($Matches as $Match)
72 $Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
78 * It returns a list of involved artifacts.
79 * An artifact is identified if [T(NUMBER)] is found.
81 * @param string $Log Log message to be parsed.
83 * @return boot Returns true if check passed.
85 function getInvolvedTasks($Log)
87 preg_match_all ('/[[]T[\d]+[]]/', $Log, $Matches );
88 foreach($Matches as $Match)
90 $Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
96 * Parse input and get the Log message.
98 * @param string $Input Input from stdin.
100 * @return array Array of lines of Log Message.
102 function getLog($Input)
104 $Lines = explode("\n", $Input);
107 for ( $i=0; $i < $ii ; $i++ )
110 $Log.=$Lines[$i]."\n";
111 if ($Lines[$i]=='Log Message:')
119 if($cvs_tracker_debug) {
120 echo "Arguments count: ".$argc."\n";
121 echo "Arguments passed to post.php:\n";
125 if( $cvs_binary_version == "1.11" ) {
130 $repository = $argv[1];
131 $parameters = explode(' ', $argv[2]);
132 $path = $parameters[0];
134 for($i = 1; $i < count($parameters); $i++) {
135 $filesInformation = explode(',', trim($parameters[$i], ','));
138 'name' => $path."/".$filesInformation[0],
139 'previous' => $filesInformation[1],
140 'actual' => $filesInformation[2]
145 if ( $cvs_binary_version == "1.12" ) {
150 if ( (($argc - 3) % 3 ) != 0 ) {
151 echo "There should be 3 params + 3*N, instead of $argc\n";
154 $NumFiles= (($argc-3) / 3 ); // 3 Fixed params + 3 * File
155 $repository = $argv[1];
158 for ( $i=0; $i < $NumFiles; $i++ ) {
160 'name' => $path."/".$argv[3 + 3*$i],
161 'previous' => $argv[4 + 3*$i],
162 'actual' => $argv[5 + 3*$i]
167 // Our POSTer in Gforge
168 $snoopy = new Snoopy;
176 $SubmitUrl = $http . $sys_default_domain . '/plugins/cvstracker/newcommit.php';
178 $UserArray=posix_getpwuid ( posix_geteuid ( ) );
179 $UserName= $UserArray['name'];
181 $Input = file_get_contents ("/dev/stdin" );
182 $Log = getLog($Input);
184 $tasks_involved= getInvolvedTasks($Log);
185 $artifacts_involved= getInvolvedArtifacts($Log);
186 if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
187 (!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
189 die("No artifacts nor tasks in the commit log\n");
193 foreach ( $files as $file )
195 $SubmitVars[$i]["UserName"] = $UserName;
196 $SubmitVars[$i]["Repository"] = $repository;
197 $SubmitVars[$i]["FileName"] = $file['name'];
198 $SubmitVars[$i]["PrevVersion"] = $file['previous'];
199 $SubmitVars[$i]["ActualVersion"] = $file['actual'];
200 $SubmitVars[$i]["Log"] = $Log;
201 $SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($Log);
202 $SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($Log);
203 $SubmitVars[$i]["CvsDate"] = time();
207 if($cvs_tracker_debug) {
208 echo "Variables submitted to newcommit.php:\n";
209 print_r($SubmitVars);
211 $vars['data'] = serialize($SubmitVars);
212 $snoopy->submit($SubmitUrl,$vars);
213 print $snoopy->results;