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
28 * This is the script called by cvs. It takes some params, and prepare some
29 * HTTP POSTs to /plugins/cvstracker/newcommit.php.
33 require dirname(__FILE__).'/../../env.inc.php';
34 require_once $gfcommon.'include/pre.php';
35 require_once ($gfcommon.'common/include/utils.php');
36 require_once ($gfplugins.'cvstracker/common/Snoopy.class.php');
38 $cvs_binary_version = get_cvs_binary_version () ;
40 if ($cvs_binary_version != "1.12" &&
41 $cvs_binary_version != "1.11" )
42 $cvs_binary_version = "1.12";
44 * It returns the usage and exit program
49 function usage( $argv ) {
50 global $cvs_binary_version;
51 if ($cvs_binary_version == "1.12" ) {
52 echo "Usage: $argv[0] <Repository> <Path> [<File> <VersionFrom> <VersionTo>]xN\n";
54 if ($cvs_binary_version == "1.11" ) {
55 echo "Usage: $argv[0] <Repository> [<File>,<VersionFrom>,<VersionTo>xN]\n";
61 * It returns a list of involved artifacts.
62 * An artifact is identified if [#(NUMBER)] if found.
64 * @param string $Log Log message to be parsed.
66 * @return boot Returns true if check passed.
68 function getInvolvedArtifacts($Log)
70 preg_match_all('/[[]#[\d]+[]]/', $Log, $Matches );
71 foreach($Matches as $Match)
73 $Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
79 * It returns a list of involved artifacts.
80 * An artifact is identified if [T(NUMBER)] is found.
82 * @param string $Log Log message to be parsed.
84 * @return boot Returns true if check passed.
86 function getInvolvedTasks($Log)
88 preg_match_all ('/[[]T[\d]+[]]/', $Log, $Matches );
89 foreach($Matches as $Match)
91 $Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
97 * Parse input and get the Log message.
99 * @param string $Input Input from stdin.
101 * @return array Array of lines of Log Message.
103 function getLog($Input)
105 $Lines = explode("\n", $Input);
109 for ( $i=0; $i < $ii ; $i++ )
112 $Log.=$Lines[$i]."\n";
113 if ($Lines[$i]=='Log Message:')
121 if( $cvs_binary_version == "1.11" ) {
126 $repository = $argv[1];
127 $parameters = explode(' ', $argv[2]);
128 $path = $parameters[0];
130 for($i = 1; $i < count($parameters); $i++) {
131 $filesInformation = explode(',', trim($parameters[$i], ','));
134 'name' => $path."/".$filesInformation[0],
135 'previous' => $filesInformation[1],
136 'actual' => $filesInformation[2]
141 if ( $cvs_binary_version == "1.12" ) {
146 if ( (($argc - 3) % 3 ) != 0 ) {
147 echo "There should be 3 params + 3*N, instead of $argc\n";
150 $NumFiles= (($argc-3) / 3 ); // 3 Fixed params + 3 * File
151 $repository = $argv[1];
154 for ( $i=0; $i < $NumFiles; $i++ ) {
156 'name' => $path."/".$argv[3 + 3*$i],
157 'previous' => $argv[4 + 3*$i],
158 'actual' => $argv[5 + 3*$i]
163 // Our POSTer in Gforge
164 $snoopy = new Snoopy;
172 $SubmitUrl = util_make_url('/plugins/cvstracker/newcommit.php');
174 $UserArray=posix_getpwuid ( posix_geteuid ( ) );
175 $UserName= $UserArray['name'];
177 $Input = file_get_contents ("/dev/stdin" );
178 $Log = getLog($Input);
180 $tasks_involved= getInvolvedTasks($Log);
181 $artifacts_involved= getInvolvedArtifacts($Log);
182 if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
183 (!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
185 die("No artifacts nor tasks in the commit log\n");
189 foreach ( $files as $file )
191 $SubmitVars[$i]["UserName"] = $UserName;
192 $SubmitVars[$i]["Repository"] = $repository;
193 $SubmitVars[$i]["FileName"] = $file['name'];
194 $SubmitVars[$i]["PrevVersion"] = $file['previous'];
195 $SubmitVars[$i]["ActualVersion"] = $file['actual'];
196 $SubmitVars[$i]["Log"] = $Log;
197 $SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($Log);
198 $SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($Log);
199 $SubmitVars[$i]["CvsDate"] = time();
203 $vars['data'] = serialize($SubmitVars);
204 $snoopy->submit($SubmitUrl,$vars);