[ 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 // +----------------------------------------------------------------------+ 28 // 29 // @(#) $Id: process_cvs_commits.php 3502 2007-12-05 10:34:30Z glen $ 30 31 32 // URL to your Eventum installation. 33 // https is supported transparently by PHP 5 if you have openssl module enabled. 34 $eventum_url = 'http://rabbit.impleo.net/'; 35 36 37 // 38 // DO NOT CHANGE ANYTHING AFTER THIS LINE 39 // 40 41 if (isset($eventum_url)) { 42 $data = parse_url($eventum_url); 43 } else { 44 // legacy 45 $data = array(); 46 $data['host'] = $eventum_domain; 47 $data['path'] = $eventum_relative_url; 48 $data['port'] = $eventum_port; 49 $data['scheme'] = 'http'; 50 } 51 52 if (!isset($data['port'])) { 53 $data['port'] = $data['scheme'] == 'https' ? 443 : 80; 54 } 55 56 $input = getInput(); 57 58 // remove the first element which is the name of this script 59 array_shift($argv); 60 61 // save who is committing these changes 62 $username = array_shift($argv); 63 // save what the name of the module is 64 $cvs_arguments = array_shift($argv); 65 $pieces = explode(' ', $cvs_arguments); 66 $cvs_module = array_shift($pieces); 67 68 // now parse the list of modified files 69 $modified_files = array(); 70 foreach ($pieces as $file_info) { 71 @list($filename, $old_revision, $new_revision) = explode(',', $file_info); 72 $modified_files[] = array( 73 'filename' => $filename, 74 'old_revision' => $old_revision, 75 'new_revision' => $new_revision 76 ); 77 } 78 79 // get the full commit message 80 $commit_msg = substr($input, strpos($input, 'Log Message:') + strlen('Log Message:') + 1); 81 82 // parse the commit message and get the first issue number we can find 83 $pattern = "/(?:issue|bug) ?:? ?#?(\d+)/i"; 84 preg_match_all($pattern, $commit_msg, $matches); 85 86 if (count($matches[1]) > 0) { 87 // need to encode all of the url arguments 88 $commit_msg = rawurlencode($commit_msg); 89 $cvs_module = rawurlencode($cvs_module); 90 $username = rawurlencode($username); 91 92 // build the GET url to use 93 $ping_url = $data['path']. "scm_ping.php?module=$cvs_module&username=$username&commit_msg=$commit_msg"; 94 foreach ($matches[1] as $issue_id) { 95 $ping_url .= "&issue[]=$issue_id"; 96 } 97 98 for ($i = 0; $i < count($modified_files); $i++) { 99 $ping_url .= "&files[$i]=" . rawurlencode($modified_files[$i]['filename']); 100 $ping_url .= "&old_versions[$i]=" . rawurlencode($modified_files[$i]['old_revision']); 101 $ping_url .= "&new_versions[$i]=" . rawurlencode($modified_files[$i]['new_revision']); 102 } 103 104 $address = $data['host']; 105 if ($data['scheme'] == 'https') { 106 $address = "ssl://$address"; 107 } 108 $fp = fsockopen($address, $data['port'], $errno, $errstr, 30); 109 if (!$fp) { 110 die("Error: Could not ping the Eventum SCM handler script.\n"); 111 } else { 112 $msg = "GET $ping_url HTTP/1.1\r\n"; 113 $msg .= "Host: {$data['host']}\r\n"; 114 $msg .= "Connection: Close\r\n\r\n"; 115 fwrite($fp, $msg); 116 $buf = fgets($fp, 4096); 117 if (!$buf) { 118 echo "Error: Couldn't read response from $ping_url\n"; 119 } else { 120 list($proto, $status, $msg) = explode(' ', trim($buf), 3); 121 if ($status != '200') { 122 echo "Error: Could not ping the Eventum SCM handler script: HTTP status code: $status $msg\n"; 123 } 124 } 125 fclose($fp); 126 } 127 } 128 129 function getInput() 130 { 131 $terminator = "\n"; 132 133 $stdin = fopen("php://stdin", "r"); 134 $input = ''; 135 while (!feof($stdin)) { 136 $buffer = fgets($stdin, 256); 137 $input .= $buffer; 138 } 139 fclose($stdin); 140 return $input; 141 }
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 |