1 --- eventum-20060724/misc/scm/process_svn_commits.php 2006-07-25 00:34:44.884132544 +0300
2 +++ eventum-20060724.svn/misc/scm/process_svn_commits.php 2006-07-25 00:34:07.543295681 +0300
4 // | Authors: João Prado Maia <jpm@mysql.com> |
5 // | Adam Ratcliffe <adam.ratcliffe@geosmart.co.nz> |
6 // | Frederik M. Kraus <f.kraus@pangora.com> |
7 +// | Elan Ruusamäe <glen@delfi.ee> |
8 // +----------------------------------------------------------------------+
12 +// See http://eventum.mysql.org/wiki/index.php/Subversion_integration about SVN integration.
14 -$eventum_domain = 'www.geosmartlbs.co.nz';
15 -$eventum_relative_url = '/eventum/';
17 -$svnlook = '/usr/bin/svnlook';
18 -$separatorChar = "/";
19 +include '/etc/eventum/scm.php';
22 // DO NOT CHANGE ANYTHING AFTER THIS LINE
25 -if(!file_exists($svnlook)) {
26 - echo 'svnlook does not exist, edit $svnlook\n';
28 +if (isset($eventum_url)) {
29 + $data = parse_url($eventum_url);
33 + $data['host'] = $eventum_domain;
34 + $data['path'] = $eventum_relative_url;
35 + $data['port'] = $eventum_port;
36 + $data['scheme'] = 'http';
39 +if (!isset($data['port'])) {
40 + $data['port'] = $data['scheme'] == 'https' ? 443 : 80;
43 +if (!isset($svnlook)) {
44 + $svnlook = '/usr/bin/svnlook';
47 +if (!is_executable($svnlook)) {
48 + die('svnlook is not executable, edit $svnlook');
51 -if(count($argv) < 3) {
52 - echo 'missing arguments, got ' . count($argv) . ' expected 3\n';
54 + printf("Missing arguments, got %d, expected 2\n", $argc - 1);
62 -$svn_module = base64_encode(substr(strrchr($repos, $separatorChar), 1));
63 +$scm_module = rawurlencode(basename($repos));
66 exec($svnlook . ' info ' . $repos . ' -r ' . $rev, $results);
68 -$username = base64_encode(array_shift($results));
69 +$username = array_shift($results);
70 $date = array_shift($results);
71 array_shift($results); // ignore file length
74 -foreach ($results as $line) {
75 - $commit_msg .= $line."\n";
77 +$commit_msg = join("\n", $results);
78 // now we have to strip html-tags from the commit message
79 $commit_msg = strip_tags($commit_msg);
82 $pieces = explode(' ', $file_info);
83 $filename = $pieces[1];
84 $modified_files[] = array(
85 - 'filename' => "/" . $filename,
86 - 'old_revision' => $oldRev,
87 - 'new_revision' => $rev
88 + 'filename' => $filename,
89 + 'old_revision' => $oldRev,
90 + 'new_revision' => $rev
94 // parse the commit message and get all issue numbers we can find
95 -$pattern = "/[issue|bug] ?:? ?#?(\d+)/i";
96 +$pattern = "/(?:issue|bug) ?:? ?#?(\d+)/i";
97 preg_match_all($pattern, $commit_msg, $matches);
99 -if (count($matches) == 2 && count($matches[1]) > 0) {
100 - $commit_msg = base64_encode($commit_msg);
101 - foreach ($matches[0] as $p_issue_id) {
102 - echo "Matched ISSUE #".$p_issue_id."\n";
103 - $issue_id = base64_encode($p_issue_id);
104 - // build the GET url to use
105 - $ping_url = $eventum_relative_url .
106 - "scm_ping.php?module=$svn_module&username=$username&commit_msg=$commit_msg";
107 +if (count($matches) > 1) {
108 + // need to encode all of the url arguments
109 + $commit_msg = rawurlencode($commit_msg);
110 + $scm_module = rawurlencode($scm_module);
111 + $username = rawurlencode($username);
113 + // build the GET url to use
114 + $ping_url = $data['path']. "scm_ping.php?module=$scm_module&username=$username&commit_msg=$commit_msg";
115 + foreach ($matches[1] as $issue_id) {
116 + echo 'Matched Issue #', $issue_id, "\n";
117 $ping_url .= "&issue[]=$issue_id";
118 - for ($i = 0; $i < count($modified_files); $i++) {
119 - $ping_url .= "&files[$i]=" . base64_encode($modified_files[$i]['filename']);
120 - $ping_url .= "&old_versions[$i]=" .
121 - base64_encode($modified_files[$i]['old_revision']);
122 - $ping_url .= "&new_versions[$i]=" .
123 - base64_encode($modified_files[$i]['new_revision']);
127 - $fp = fsockopen($eventum_domain, $eventum_port, $errno, $errstr, 30);
128 + for ($i = 0; $i < count($modified_files); $i++) {
129 + $ping_url .= "&files[$i]=" . rawurlencode($modified_files[$i]['filename']);
130 + $ping_url .= "&old_versions[$i]=" . rawurlencode($modified_files[$i]['old_revision']);
131 + $ping_url .= "&new_versions[$i]=" . rawurlencode($modified_files[$i]['new_revision']);
135 - echo "Error: Could not ping the Eventum SCM handler script.\n";
138 - $msg = "GET $ping_url HTTP/1.1\r\n";
139 - $msg .= "Host: $eventum_domain\r\n";
140 - $msg .= "Connection: Close\r\n\r\n";
143 + $address = $data['host'];
144 + if ($data['scheme'] == 'https') {
145 + $address = "ssl://$address";
147 + $fp = fsockopen($address, $data['port'], $errno, $errstr, 30);
149 + die("Error: Could not ping the Eventum SCM handler script.\n");
151 + $msg = "GET $ping_url HTTP/1.1\r\n";
152 + $msg .= "Host: $data[host]\r\n";
153 + $msg .= "Connection: Close\r\n\r\n";
155 + $buf = fgets($fp, 4096);
156 + list($proto, $status, $msg) = explode(' ', trim($buf), 3);
157 + if ($status != '200') {
158 + echo "Error: Could not ping the Eventum SCM handler script: HTTP status code: $status $msg\n";
163 - echo "No Match found\n";