/usr/share/fusionforge/plugins/scmhook/library/scmgit/hooks/committracker/post.php is in fusionforge-plugin-scmhook 6.0.3+20151023-1ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #! /usr/bin/php
<?php
/**
* Fusionforge Plugin SVNTracker 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>
* Copyright 2011, Franck Villaume - Capgemini
* Copyright 2013, Franck Villaume - TrivialDev
* Copyright 2014, Benoit Debaenst - TrivialDev
*
* This file is part of FusionForge. FusionForge 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 Licence, or (at your option)
* any later version.
*
* FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
*
* This is the script called by svn. It takes some params, and prepare some
* HTTP POSTs to scmhook/www/newcommitgit.php.
*
*/
require_once dirname(__FILE__).'/../../../../../../common/include/env.inc.php';
require_once $gfcommon.'include/pre.php';
/**
* usage - It returns the usage and exit program
*
* @param string $prog
*
*/
function usage( $prog ) {
echo "Usage: $prog <oldrev> <newrev> <refname> <repo_path> \n";
echo "You must control parameters! \n";
exit(1);
}
/**
* getInvolvedArtifacts - It returns a list of involved artifacts.
* An artifact is identified if [#(NUMBER)] if found.
*
* @param string $Log Log message to be parsed.
*
* @return string $Result Returns artifact.
*/
function getInvolvedArtifacts($Log)
{
preg_match_all('/[[]#[\d]+[]]/', $Log, $Matches );
foreach($Matches as $Match)
{
$Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
}
return $Result;
}
/**
* getInvolvedTasks - It returns a list of involved tasks.
* A task is identified if [T(NUMBER)] is found.
*
* @param string $Log Log message to be parsed.
*
* @return string $Result Returns task.
*/
function getInvolvedTasks($Log)
{
preg_match_all ('/[[]T[\d]+[]]/', $Log, $Matches );
foreach($Matches as $Match)
{
$Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
}
return $Result;
}
/**
* getLog - 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 (count($argv) != 5) {
usage("post.php");
}
$oldrev = $argv[1];
$newrev = $argv[2];
$refname = $argv[3];
$repo_path = substr_replace($argv[4],'',-6);
$git_tracker_debug = 0;
chdir($repo_path);
$UserName = trim(`git log -n 1 --format=%an $newrev`);
$email = trim(`git log -n 1 --format=%ae $newrev`);
$date = trim(`git log -n 1 --format=%ai $newrev`);
$log = trim(`git log -n 1 --format=%s $newrev`);
$changed = trim(`git log -n 1 --format=%b --name-only -p $newrev`);
if (isset($git_tracker_debug) && $git_tracker_debug == 1) {
$tempfile = tempnam('/tmp', 'debug.post');
$file=fopen($tempfile, 'a+');
fwrite($file,"Vars filled:\n");
fwrite($file,"arg : " . print_r($argv,true) . " \n");
fwrite($file,"rev : " . $newrev . " \n");
fwrite($file,"username : " . $UserName . " \n");
fwrite($file,"email : " . $email . " \n");
fwrite($file,"date : " . $date . " \n");
fwrite($file,"log : " . $log . " \n");
fwrite($file,"changed : " . $changed . " \n");
fclose($file);
}
$changed = explode("\n", $changed);
foreach ($changed as $onefile) {
//we must see when it was last changed, and that's previous revision
$exit=0;
$actrev = $newrev - 1;
if ($newrev==0) {
$exit = 1;
$prev = 1;
}
while ( (!$exit) && ($actrev != 0 ) ) {
$changed2 = trim(`git log -n 1 --format=%b --name-only -p $newrev`);
$changed2 = explode("\n", $changed2);
if ( in_array($onefile,$changed2) ) {
$prev = $actrev;
$exit = 1;
}
$actrev = $actrev - 1 ;
}
if ($actrev == 0) {
$prev = 1;
}
$files[] = array(
'name' => $onefile,
'previous' => $oldrev,
'actual' => $newrev
);
}
// Our POSTer in Fusionforge
$SubmitUrl = util_make_url('/plugins/scmhook/committracker/newcommitgit.php');
$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)) {
// No artifacts nor tasks in the commit log
exit(0);
}
$i = 0;
foreach ( $files as $onefile )
{
$SubmitVars[$i]["UserName"] = $UserName;
$SubmitVars[$i]["Email"] = $email;
$SubmitVars[$i]["Repository"] = $repo_path;
$SubmitVars[$i]["FileName"] = $onefile['name'];
$SubmitVars[$i]["PrevVersion"] = $onefile['previous'];
$SubmitVars[$i]["ActualVersion"] = $onefile['actual'];
$SubmitVars[$i]["Log"] = $log;
$SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($log);
$SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($log);
$SubmitVars[$i]["GitDate"] = time();
$i++;
}
$vars['data'] = urlencode(serialize($SubmitVars));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $SubmitUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
$result = curl_exec($ch);
//$info = curl_getinfo($ch);
curl_close($ch);
|