File: post.php

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (214 lines) | stat: -rw-r--r-- 5,708 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#! /usr/bin/php4 -f
<?php
/**
 * GForge Plugin CVSTracker HTTPPoster
 *
 * Portions Copyright 2004 (c) Roland Mas <99.roland.mas @nospam@ aist.enst.fr>
 * The rest Copyright 2004 (c) Francisco Gimeno <kikov @nospam@ kikov.org>
 *
 * This file is part of GForge-plugin-cvstracker
 *
 * GForge-plugin-cvstracker is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * GForge-plugin-cvstracker is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge-plugin-cvstracker; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US
 *
 * @version $Id: post.php 5124 2005-12-15 12:24:43Z danper $
 */
/**
 *
 *  This is the script called by cvs. It takes some params, and prepare some
 *  HTTP POSTs to /plugins/cvstracker/newcommit.php.
 *
 */
 
//require ('local.inc'); we dont need this file. also, in some installations this file cannot be accessed by the caller (perms problem)
require ('plugins/cvstracker/config.php');
require ($sys_plugins_path.'/cvstracker/include/Snoopy.class');


if ($cvs_binary_version != "1.12" &&
	$cvs_binary_version != "1.11" )
	$cvs_binary_version = "1.12";
/**
 * It returns the usage and exit program
 *
 * @param   string   $argv
 *
 */
function usage( $argv ) {
	global $cvs_binary_version;
	if ($cvs_binary_version == "1.12" ) {
		echo "Usage: $argv[0] <Repository> <Path> [<File> <VersionFrom> <VersionTo>]xN\n";
	} 
	if ($cvs_binary_version == "1.11" ) {
		echo "Usage: $argv[0] <Repository> [<File>,<VersionFrom>,<VersionTo>xN]\n";
	}
	exit(0);
}

/**
 * It returns a list of involved artifacts.
 * An artifact is identified if [#(NUMBER)] if found.
 *
 * @param   string   $Log Log message to be parsed.
 *
 * @return  boot    Returns true if check passed.
 */
function getInvolvedArtifacts($Log)
{
	preg_match_all('/[[]#[\d]+[]]/', $Log,  $Matches );
	foreach($Matches as $Match)
	{
		$Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
	}
	return $Result;
}

/**
 * It returns a list of involved artifacts.
 * An artifact is identified if [T(NUMBER)] is found.
 *
 * @param   string   $Log Log message to be parsed.
 *
 * @return  boot    Returns true if check passed.
 */
function getInvolvedTasks($Log)
{
	preg_match_all ('/[[]T[\d]+[]]/', $Log,  $Matches );
	foreach($Matches as $Match)
	{
		$Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
	}
	return $Result;
}

/**
 * Parse input and get the Log message.
 *
 * @param   string   $Input Input from stdin.
 *
 * @return  array    Array of lines of Log Message.
 */
function getLog($Input)
{
	$Lines = explode("\n", $Input);
	$ii = count($Lines);
	$Logging=false;
	for ( $i=0; $i < $ii ; $i++ )
	{
		if ($Logging==true)
			$Log.=$Lines[$i]."\n";
		if ($Lines[$i]=='Log Message:')
			$Logging=true;
	}
	return trim($Log);
}

$files = array();

if($cvs_tracker_debug) {
	echo "Arguments count: ".$argc."\n";
	echo "Arguments passed to post.php:\n";
	print_r($argv);
}

if( $cvs_binary_version == "1.11" ) {
	if ($argc != 3 ) {
		usage ( $argv );
	}
	
	$repository      = $argv[1];
	$parameters = explode(' ', $argv[2]);
	$path = $parameters[0];
	
	for($i = 1; $i < count($parameters); $i++) {
		$filesInformation = explode(',', trim($parameters[$i], ','));

		$files[] = array(
			'name' => $path."/".$filesInformation[0],
			'previous' => $filesInformation[1],
			'actual' => $filesInformation[2]
		);
	}
	
} 
if ( $cvs_binary_version == "1.12" ) {
	if ($argc < 6 ) {
		usage ( $argv );
	}
	
	if ( (($argc - 3) % 3 ) != 0 ) {
		echo "There should be 3 params + 3*N, instead of $argc\n";
		usage ( $argv );
	}
	$NumFiles= (($argc-3) / 3 ); // 3 Fixed params + 3 * File
	$repository      = $argv[1];
	$path            = $argv[2];
	
	for ( $i=0; $i < $NumFiles; $i++ ) {
		$files[] = array(
			'name' => $path."/".$argv[3 + 3*$i],
			'previous' => $argv[4 + 3*$i],
			'actual' => $argv[5 + 3*$i]
		);
	}
}

// Our POSTer in Gforge
$snoopy = new Snoopy;

if ($use_ssl) {
	$http = "https://";
} else {
	$http = "http://";
}

$SubmitUrl = $http . $sys_default_domain . '/plugins/cvstracker/newcommit.php';

$UserArray=posix_getpwuid ( posix_geteuid ( ) );
$UserName= $UserArray['name'];

$Input = file_get_contents ("/dev/stdin" );
$Log   = getLog($Input);

$tasks_involved= getInvolvedTasks($Log);
$artifacts_involved= getInvolvedArtifacts($Log);
if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
	(!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
	//nothing to post
	die("No artifacts nor tasks in the commit log\n");
}

$i = 0;
foreach ( $files as $file )
{
	$SubmitVars[$i]["UserName"]        = $UserName;
	$SubmitVars[$i]["Repository"]      = $repository;
	$SubmitVars[$i]["FileName"]        = $file['name'];
	$SubmitVars[$i]["PrevVersion"]     = $file['previous'];
	$SubmitVars[$i]["ActualVersion"]   = $file['actual'];
	$SubmitVars[$i]["Log"]             = $Log;
	$SubmitVars[$i]["TaskNumbers"]     = getInvolvedTasks($Log);
	$SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($Log);
	$SubmitVars[$i]["CvsDate"]         = time();
	$i++;
}
	if($cvs_tracker_debug) {
		echo "Variables submitted to newcommit.php:\n";
		print_r($SubmitVars[$i]);
	}
	$vars['data'] = serialize($SubmitVars);
	$snoopy->submit($SubmitUrl,$vars);
	print $snoopy->results;

?>