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 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 cvs. It takes some params, and prepare some
28 * HTTP POSTs to /plugins/cvstracker/newcommit.php.
32 require dirname(__FILE__).'/../../env.inc.php';
33 require_once $gfcommon.'include/pre.php';
34 require_once ($gfcommon.'common/include/utils.php');
35 require_once ($gfplugins.'cvstracker/common/Snoopy.class.php');
37 $cvs_binary_version = get_cvs_binary_version () ;
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);
108 for ( $i=0; $i < $ii ; $i++ )
111 $Log.=$Lines[$i]."\n";
112 if ($Lines[$i]=='Log Message:')
120 if( $cvs_binary_version == "1.11" ) {
125 $repository = $argv[1];
126 $parameters = explode(' ', $argv[2]);
127 $path = $parameters[0];
129 for($i = 1; $i < count($parameters); $i++) {
130 $filesInformation = explode(',', trim($parameters[$i], ','));
133 'name' => $path."/".$filesInformation[0],
134 'previous' => $filesInformation[1],
135 'actual' => $filesInformation[2]
140 if ( $cvs_binary_version == "1.12" ) {
145 if ( (($argc - 3) % 3 ) != 0 ) {
146 echo "There should be 3 params + 3*N, instead of $argc\n";
149 $NumFiles= (($argc-3) / 3 ); // 3 Fixed params + 3 * File
150 $repository = $argv[1];
153 for ( $i=0; $i < $NumFiles; $i++ ) {
155 'name' => $path."/".$argv[3 + 3*$i],
156 'previous' => $argv[4 + 3*$i],
157 'actual' => $argv[5 + 3*$i]
162 // Our POSTer in Fusionforge
163 $snoopy = new Snoopy;
165 $SubmitUrl = util_make_url('/plugins/cvstracker/newcommit.php');
167 $UserArray=posix_getpwuid ( posix_geteuid ( ) );
168 $UserName= $UserArray['name'];
170 $Input = file_get_contents ("/dev/stdin" );
171 $Log = getLog($Input);
173 $tasks_involved= getInvolvedTasks($Log);
174 $artifacts_involved= getInvolvedArtifacts($Log);
175 if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
176 (!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
178 die("No artifacts nor tasks in the commit log\n");
182 foreach ( $files as $file )
184 $SubmitVars[$i]["UserName"] = $UserName;
185 $SubmitVars[$i]["Repository"] = $repository;
186 $SubmitVars[$i]["FileName"] = $file['name'];
187 $SubmitVars[$i]["PrevVersion"] = $file['previous'];
188 $SubmitVars[$i]["ActualVersion"] = $file['actual'];
189 $SubmitVars[$i]["Log"] = $Log;
190 $SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($Log);
191 $SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($Log);
192 $SubmitVars[$i]["CvsDate"] = time();
196 $vars['data'] = serialize($SubmitVars);
197 $snoopy->submit($SubmitUrl,$vars);