4 * Fusionforge Plugin SVNTracker 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>
8 * Copyright 2011, Franck Villaume - Capgemini
9 * Copyright 2013, Franck Villaume - TrivialDev
10 * Copyright 2014, Benoit Debaenst - TrivialDev
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 * This is the script called by svn. It takes some params, and prepare some
30 * HTTP POSTs to scmhook/www/newcommitgit.php.
34 require_once dirname(__FILE__).'/../../../../../../common/include/env.inc.php';
35 require_once $gfcommon.'include/pre.php';
36 require $gfplugins.'scmhook/library/scmgit/hooks/committracker/Snoopy.class.php';
39 * It returns the usage and exit program
44 function usage( $argv ) {
45 echo "Usage: $argv[0] <Repository> <Revision> \n";
50 * It returns a list of involved artifacts.
51 * An artifact is identified if [#(NUMBER)] if found.
53 * @param string $Log Log message to be parsed.
55 * @return boot Returns true if check passed.
57 function getInvolvedArtifacts($Log)
59 preg_match_all('/[[]#[\d]+[]]/', $Log, $Matches );
60 foreach($Matches as $Match)
62 $Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
68 * It returns a list of involved artifacts.
69 * An artifact is identified if [T(NUMBER)] is found.
71 * @param string $Log Log message to be parsed.
73 * @return boot Returns true if check passed.
75 function getInvolvedTasks($Log)
77 preg_match_all ('/[[]T[\d]+[]]/', $Log, $Matches );
78 foreach($Matches as $Match)
80 $Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
86 * Parse input and get the Log message.
88 * @param string $Input Input from stdin.
90 * @return array Array of lines of Log Message.
92 function getLog($Input)
94 $Lines = explode("\n", $Input);
97 for ( $i=0; $i < $ii ; $i++ )
100 $Log.=$Lines[$i]."\n";
101 if ($Lines[$i]=='Log Message:')
109 if (count($argv) != 5) {
111 Usage: $0 <repository> <revision>
112 This program should be automatically called by SVN
121 $repo_path = substr_replace($argv[4],'',-6);
123 $git_tracker_debug = 0;
127 $UserName = trim(`git log -n 1 --format=%an $newrev`);
128 $date = trim(`git log -n 1 --format=%ai $newrev`); //date
129 $log = trim(`git log -n 1 --format=%s $newrev`); // the log
130 $changed = trim(`git log -n 1 --format=%b --name-only -p $newrev`); // the filenames
132 if (isset($git_tracker_debug) && $git_tracker_debug == 1) {
133 $file=fopen("/tmp/debug.post","a+");
134 fwrite($file,"Vars filled:\n");
135 fwrite($file,"arg : " . print_r($argv,true) . " \n");
136 fwrite($file,"rev : " . $newrev . " \n");
137 fwrite($file,"username : " . $UserName . " \n");
138 fwrite($file,"date : " . $date . " \n");
139 fwrite($file,"log : " . $log . " \n");
140 fwrite($file,"changed : " . $changed . " \n");
144 $changed = explode("\n", $changed);
145 foreach ($changed as $onefile) {
146 //we must see when it was last changed, and that's previous revision
148 $actrev = $newrev - 1;
153 while ( (!$exit) && ($actrev != 0 ) ) {
154 $changed2 = trim(`git log -n 1 --format=%b --name-only -p $newrev`);
155 $changed2 = explode("\n", $changed2);
156 if ( in_array($onefile,$changed2) ) {
160 $actrev = $actrev - 1 ;
168 'previous' => $oldrev,
174 // Our POSTer in Fusionforge
175 $snoopy = new Snoopy;
177 $SubmitUrl = util_make_url('/plugins/scmhook/committracker/newcommitgit.php');
179 $tasks_involved = getInvolvedTasks($log);
180 $artifacts_involved = getInvolvedArtifacts($log);
181 if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
182 (!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
184 die("No artifacts nor tasks in the commit log\n");
188 foreach ( $files as $onefile )
190 $SubmitVars[$i]["UserName"] = $UserName;
191 $SubmitVars[$i]["Repository"] = $repo_path;
192 $SubmitVars[$i]["FileName"] = $onefile['name'];
193 $SubmitVars[$i]["PrevVersion"] = $onefile['previous'];
194 $SubmitVars[$i]["ActualVersion"] = $onefile['actual'];
195 $SubmitVars[$i]["Log"] = $log;
196 $SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($log);
197 $SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($log);
198 $SubmitVars[$i]["GitDate"] = time();
202 $vars['data'] = urlencode(serialize($SubmitVars));
203 $snoopy->submit($SubmitUrl, $vars);