[ Index ] |
PHP Cross Reference of Eventum |
[Summary view] [Print] [Text view]
1 #!/usr/bin/php 2 <?php 3 /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */ 4 // +----------------------------------------------------------------------+ 5 // | Eventum - Issue Tracking System | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB | 8 // | | 9 // | This program is free software; you can redistribute it and/or modify | 10 // | it under the terms of the GNU General Public License as published by | 11 // | the Free Software Foundation; either version 2 of the License, or | 12 // | (at your option) any later version. | 13 // | | 14 // | This program is distributed in the hope that it will be useful, | 15 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 // | GNU General Public License for more details. | 18 // | | 19 // | You should have received a copy of the GNU General Public License | 20 // | along with this program; if not, write to: | 21 // | | 22 // | Free Software Foundation, Inc. | 23 // | 59 Temple Place - Suite 330 | 24 // | Boston, MA 02111-1307, USA. | 25 // +----------------------------------------------------------------------+ 26 // | Authors: João Prado Maia <jpm@mysql.com> | 27 // | Adam Ratcliffe <adam.ratcliffe@geosmart.co.nz> | 28 // | Frederik M. Kraus <f.kraus@pangora.com> | 29 // | Elan Ruusamäe <glen@delfi.ee> | 30 // +----------------------------------------------------------------------+ 31 // 32 // @(#) $Id: process_svn_commits.php 3309 2007-04-17 10:17:38Z glen $ 33 34 // See http://eventum.mysql.org/wiki/index.php/Subversion_integration about SVN integration. 35 36 // URL to your Eventum installation. 37 // https is supported transparently by PHP 5 if you have openssl module enabled. 38 $eventum_url = 'http://rabbit.impleo.net/'; 39 40 // 41 // DO NOT CHANGE ANYTHING AFTER THIS LINE 42 // 43 if (isset($eventum_url)) { 44 $data = parse_url($eventum_url); 45 } else { 46 // legacy 47 $data = array(); 48 $data['host'] = $eventum_domain; 49 $data['path'] = $eventum_relative_url; 50 $data['port'] = $eventum_port; 51 $data['scheme'] = 'http'; 52 } 53 54 if (!isset($data['port'])) { 55 $data['port'] = $data['scheme'] == 'https' ? 443 : 80; 56 } 57 58 if (!isset($svnlook)) { 59 $svnlook = '/usr/bin/svnlook'; 60 } 61 62 if (!is_executable($svnlook)) { 63 die('svnlook is not executable, edit $svnlook'); 64 } 65 66 if ($argc < 3) { 67 printf("Missing arguments, got %d, expected 2\n", $argc - 1); 68 exit(1); 69 } 70 71 $repos = $argv[1]; 72 $rev = $argv[2]; 73 $oldRev = $rev - 1; 74 75 $scm_module = rawurlencode(basename($repos)); 76 77 $results = array(); 78 exec($svnlook . ' info ' . $repos . ' -r ' . $rev, $results); 79 80 $username = array_shift($results); 81 $date = array_shift($results); 82 array_shift($results); // ignore file length 83 84 $commit_msg = join("\n", $results); 85 // now we have to strip html-tags from the commit message 86 $commit_msg = strip_tags($commit_msg); 87 88 $files = array(); 89 exec($svnlook . ' changed ' . $repos . ' -r ' . $rev, $files); 90 foreach ($files as $file_info) { 91 $pieces = explode(' ', $file_info); 92 $filename = $pieces[1]; 93 $modified_files[] = array( 94 'filename' => $filename, 95 'old_revision' => $oldRev, 96 'new_revision' => $rev 97 ); 98 } 99 100 // parse the commit message and get all issue numbers we can find 101 $pattern = "/(?:issue|bug) ?:? ?#?(\d+)/i"; 102 preg_match_all($pattern, $commit_msg, $matches); 103 104 if (count($matches[1]) > 0) { 105 // need to encode all of the url arguments 106 $commit_msg = rawurlencode($commit_msg); 107 $scm_module = rawurlencode($scm_module); 108 $username = rawurlencode($username); 109 110 // build the GET url to use 111 $ping_url = $data['path']. "scm_ping.php?module=$scm_module&username=$username&commit_msg=$commit_msg"; 112 foreach ($matches[1] as $issue_id) { 113 echo 'Matched Issue #', $issue_id, "\n"; 114 $ping_url .= "&issue[]=$issue_id"; 115 } 116 117 for ($i = 0; $i < count($modified_files); $i++) { 118 $ping_url .= "&files[$i]=" . rawurlencode($modified_files[$i]['filename']); 119 $ping_url .= "&old_versions[$i]=" . rawurlencode($modified_files[$i]['old_revision']); 120 $ping_url .= "&new_versions[$i]=" . rawurlencode($modified_files[$i]['new_revision']); 121 } 122 123 $address = $data['host']; 124 if ($data['scheme'] == 'https') { 125 $address = "ssl://$address"; 126 } 127 $fp = fsockopen($address, $data['port'], $errno, $errstr, 30); 128 if (!$fp) { 129 die("Error: Could not ping the Eventum SCM handler script.\n"); 130 } else { 131 $msg = "GET $ping_url HTTP/1.1\r\n"; 132 $msg .= "Host: $data[host]\r\n"; 133 $msg .= "Connection: Close\r\n\r\n"; 134 fwrite($fp, $msg); 135 $buf = fgets($fp, 4096); 136 list($proto, $status, $msg) = explode(' ', trim($buf), 3); 137 if ($status != '200') { 138 echo "Error: Could not ping the Eventum SCM handler script: HTTP status code: $status $msg\n"; 139 } 140 fclose($fp); 141 } 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 19 21:21:33 2007 | Cross-referenced by PHPXref 0.7 |