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
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * This is the script called by svn. It takes some params, and prepare some
29 * HTTP POSTs to svntracker/newcommit.php.
33 require_once dirname(__FILE__).'/../../../../../../common/include/env.inc.php';
34 require_once $gfcommon.'include/pre.php';
35 require $gfplugins.'scmhook/library/scmgit/hooks/committracker/Snoopy.class.php';
38 * It returns the usage and exit program
43 function usage( $argv ) {
44 echo "Usage: $argv[0] <Repository> <Revision> \n";
49 * It returns a list of involved artifacts.
50 * An artifact is identified if [#(NUMBER)] if found.
52 * @param string $Log Log message to be parsed.
54 * @return boot Returns true if check passed.
56 function getInvolvedArtifacts($Log)
58 preg_match_all('/[[]#[\d]+[]]/', $Log, $Matches );
59 foreach($Matches as $Match)
61 $Result = preg_replace ('/[[]#([\d]+)[]]/', '\1', $Match);
67 * It returns a list of involved artifacts.
68 * An artifact is identified if [T(NUMBER)] is found.
70 * @param string $Log Log message to be parsed.
72 * @return boot Returns true if check passed.
74 function getInvolvedTasks($Log)
76 preg_match_all ('/[[]T[\d]+[]]/', $Log, $Matches );
77 foreach($Matches as $Match)
79 $Result = preg_replace ('/[[]T([\d]+)[]]/', '\1', $Match);
85 * Parse input and get the Log message.
87 * @param string $Input Input from stdin.
89 * @return array Array of lines of Log Message.
91 function getLog($Input)
93 $Lines = explode("\n", $Input);
96 for ( $i=0; $i < $ii ; $i++ )
99 $Log.=$Lines[$i]."\n";
100 if ($Lines[$i]=='Log Message:')
108 if (count($argv) != 3) {
110 Usage: $0 <repository> <revision>
111 This program should be automatically called by SVN
117 $repository = $argv[1];
118 $revision = $argv[2];
119 $git_tracker_debug = 0;
121 $UserName = trim(`svnlook author -r $revision $repository`); //username of author
122 $date = trim(`svnlook date -r $revision $repository`); //date
123 $log = trim(`svnlook log -r $revision $repository`); // the log
124 $changed = trim(`svnlook changed -r $revision $repository | sed 's/[A-Z]* //'`); // the filenames
126 if (isset($git_tracker_debug) && $git_tracker_debug == 1) {
127 fwrite($file,"Vars filled:\n");
128 fwrite($file,"username : " . $UserName . " \n");
129 fwrite($file,"date : " . $date . " \n");
130 fwrite($file,"log : " . $log . " \n");
131 fwrite($file,"changed : " . $changed . " \n");
134 $changed = explode("\n", $changed);
136 foreach ($changed as $onefile) {
137 //we must see when it was last changed, and that's previous revision
139 $actrev = $revision - 1;
144 while ( (!$exit) && ($actrev != 0 ) ) {
145 $changed2 = trim(`svnlook changed -r $actrev $repository | sed 's/[A-Z]* //'`);
146 $changed2 = explode("\n", $changed2);
147 if ( in_array($onefile,$changed2) ) {
151 $actrev = $actrev - 1 ;
158 'name' => $repository . "/" . $onefile,
160 'actual' => $revision
165 // Our POSTer in Fusionforge
166 $snoopy = new Snoopy;
168 $SubmitUrl = util_make_url('/plugins/scmhook/committracker/newcommit.php');
170 $tasks_involved= getInvolvedTasks($log);
171 $artifacts_involved= getInvolvedArtifacts($log);
172 if ((!is_array($tasks_involved) || count($tasks_involved) < 1) &&
173 (!is_array($artifacts_involved) || count($artifacts_involved) < 1)) {
175 die("No artifacts nor tasks in the commit log\n");
179 foreach ( $files as $onefile )
181 $SubmitVars[$i]["UserName"] = $UserName;
182 $SubmitVars[$i]["Repository"] = $repository;
183 $SubmitVars[$i]["FileName"] = $onefile['name'];
184 $SubmitVars[$i]["PrevVersion"] = $onefile['previous'];
185 $SubmitVars[$i]["ActualVersion"] = $onefile['actual'];
186 $SubmitVars[$i]["Log"] = $log;
187 $SubmitVars[$i]["TaskNumbers"] = getInvolvedTasks($log);
188 $SubmitVars[$i]["ArtifactNumbers"] = getInvolvedArtifacts($log);
189 $SubmitVars[$i]["SvnDate"] = time();
193 $vars['data'] = urlencode(serialize($SubmitVars));
194 $snoopy->submit($SubmitUrl, $vars);