This is all nice and that crap, but since you didn't merge it into pear/packages/Bugtracker, it will all be lost once that stuff is taken into action..so please merge this there too. :D

--Jani


On 07/20/2009 12:08 AM, Rasmus Lerdorf wrote:
rasmus          Sun, 19 Jul 2009 21:08:22 +0000

URL: http://svn.php.net/viewvc?view=revision&revision=284386

Changed paths:
        U   SVNROOT/commit-email.php
        U   web/php-bugs/trunk/bug.php
        A   web/php-bugs/trunk/rpc.php

Log:
Bugs mentioned in commit messages now update the bug db and also
pull the status of the bug back into the commit email.
(I'm pretty sure this won't work on the first try)


Modified: SVNROOT/commit-email.php
===================================================================
--- SVNROOT/commit-email.php    2009-07-19 20:53:26 UTC (rev 284385)
+++ SVNROOT/commit-email.php    2009-07-19 21:08:22 UTC (rev 284386)
@@ -9,6 +9,7 @@
  // Constants
  $version = substr('$Revision$', strlen('$Revision: '), -2);
  $smtp_server = '127.0.0.1';
+
  $commit_email_list = array(
      // FastCGI ISAPI
      '|^php/fastcgi-isapi|' =>  array('sh...@php.net', 'w...@php.net', 
'ed...@php.net'),
@@ -218,8 +219,34 @@

  $bugs_body = '';
  if ($bugs) {
+    include '/home/svn/SVNROOT/secret.inc';
+    $bugs_body = (count($bugs_array[1])>1) ? "Bug: " : "Bugs: ";
      foreach ($bugs_array[1] as $k=>$bug_id) {
-        $bugs_body .= '     '.$bug_urls[$k]."/$bug_id\r\n";
+        $bug_sdesc = '';
+        $bug_status = '';
+        if($bug_urls[$k]=='http://bugs.php.net') {
+            $ch = curl_init('http://bugs.php.net/rpc.php');
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+            curl_setopt($ch, CURLOPT_POST, 1);
+            $ncomment = "Automatic comment from SVN on behalf of {$from[0]}\n" 
.
+                        "Log: $commit_log\n" .
+                        "Revision: 
http://svn.php.net/viewvc?view=revision&revision={$REV}\n";;
+            curl_setopt($ch, CURLOPT_POSTFIELDS, "user=" . 
rawurlencode($from[0]) .
+                             "&id={$bug_id}" .
+                             "&ncomment=" . rawurlencode($ncomment) .
+                             "&MAGIC_COOKIE=$SVN_MAGIC_COOKIE");
+            $ret = curl_exec($ch);
+            if($ret !== false ) {
+                $json = json_decode($ret,true);
+                if(isset($json['result']['status'])) {
+                    $bug_status = '('.$json['result']['status']['status'].')';
+                    $bug_sdesc = $json['result']['status']['sdesc'];
+                }
+            }
+            curl_close($ch);
+        }
+        if($k) $bugs_body .= '       ';
+        $bugs_body .= $bug_urls[$k]."/$bug_id{$bug_status}{$bug_sdesc}\r\n";
      }
  }

@@ -229,7 +256,7 @@
              "\r\n" .
              "{$commit_user}\t\t" . date(DATE_RFC2822, $commit_date) . "\r\n" .
              "\r\n" .
-            "URL: http://svn.php.net/viewvc?view=revision&revision={$REV}\r\n"; 
.
+            "Revision: 
http://svn.php.net/viewvc?view=revision&revision={$REV}\r\n"; .
              $bugs_body .
              "\r\n" .
              "Changed paths:\r\n" .

Modified: web/php-bugs/trunk/bug.php
===================================================================
--- web/php-bugs/trunk/bug.php  2009-07-19 20:53:26 UTC (rev 284385)
+++ web/php-bugs/trunk/bug.php  2009-07-19 21:08:22 UTC (rev 284386)
@@ -124,7 +124,7 @@

        if (!$errors) {
                $query = "INSERT INTO bugdb_comments (bug,email,ts,comment) 
VALUES"
-                      . " ('$id','" . $in['commentemail'] . 
"',NOW(),'$ncomment')";
+                      . " ('$id','" . mysql_real_escape_string($in['commentemail']) . 
"',NOW(),'".mysql_real_escape_string($ncomment)."')";
                $success = @mysql_query($query);
        }
        $from = stripslashes($in['commentemail']);
@@ -160,12 +160,12 @@

        if (!$errors&&  !($errors = incoming_details_are_valid($in))) {
                /* update bug record */
-               $query = "UPDATE bugdb SET sdesc='" . $in['sdesc'] . "',status='" . $in['status'] . "', 
bug_type='" . $in['bug_type'] . "', php_version='" . $in['php_version'] . "', php_os='" . $in['php_os'] . "', 
ts2=NOW(), email='$from' WHERE id=$id";
+               $query = "UPDATE bugdb SET sdesc='" . mysql_real_escape_string($in['sdesc']) . "',status='" . 
mysql_real_escape_string($in['status']) . "', bug_type='" . mysql_real_escape_string($in['bug_type']) . "', php_version='" . 
mysql_real_escape_string($in['php_version']) . "', php_os='" . mysql_real_escape_string($in['php_os']) . "', ts2=NOW(), 
email='".mysql_real_escape_string($from)."' WHERE id=$id";
                $success = @mysql_query($query);

                /* add comment */
                if ($success&&  !empty($ncomment)) {
-                       $query = "INSERT INTO bugdb_comments (bug, email, ts, 
comment) VALUES ($id,'$from',NOW(),'$ncomment')";
+                       $query = "INSERT INTO bugdb_comments (bug, email, ts, comment) VALUES 
($id,'".mysql_real_escape_string($from)."',NOW(),'".mysql_real_escape_string($ncomment)."')";
                        $success = @mysql_query($query);
                }
        }
@@ -215,11 +215,11 @@

        if (!$errors&&  !($errors = incoming_details_are_valid($in))) {
                $query = 'UPDATE bugdb SET ';
-               $query.= ($bug['email'] != $in['email']&&  !empty($in['email'])) ? 
"email='" . $in['email'] . "', " : '';
-               $query.= "sdesc='$in[sdesc]', status='$in[status]', 
bug_type='$in[bug_type]', assign='$in[assign]', php_version='$in[php_version]', 
php_os='$in[php_os]', ts2=NOW() WHERE id=$id";
+               $query.= ($bug['email'] != $in['email']&&  !empty($in['email'])) ? 
"email='" . mysql_real_escape_string($in['email']) . "', " : '';
+               $query.= "sdesc='".mysql_real_escape_string($in[sdesc])."', 
status='".mysql_real_escape_string($in[status])."', bug_type='".mysql_real_escape_string($in[bug_type])."', 
assign='".mysql_real_escape_string($in[assign])."', php_version='".mysql_real_escape_string($in[php_version])."', 
php_os='".mysql_real_escape_string($in[php_os])."', ts2=NOW() WHERE id=$id";
                $success = @mysql_query($query);
                if ($success&&  !empty($ncomment)) {
-                       $query = "INSERT INTO bugdb_comments (bug, email, ts, 
comment) VALUES ($id,'$u...@php.net',NOW(),'$ncomment')";
+                       $query = "INSERT INTO bugdb_comments (bug, email, ts, comment) VALUES 
($id,'$u...@php.net',NOW(),'".mysql_real_escape_string($ncomment)."')";
                        $success = @mysql_query($query);
                }


Added: web/php-bugs/trunk/rpc.php
===================================================================
--- web/php-bugs/trunk/rpc.php                          (rev 0)
+++ web/php-bugs/trunk/rpc.php  2009-07-19 21:08:22 UTC (rev 284386)
@@ -0,0 +1,59 @@
+<?php /* vim: set noet ts=4 sw=4: : */
+$id = (int)$_REQUEST['id'];
+
+if (!$id) {
+  echo json_encode(array('result'=>array('error'=>'Missing bug id')));
+  exit;
+}
+
+require './include/auth.inc';
+
+if (isset($_POST['MAGIC_COOKIE'])) {
+  list($user,$pw) = explode(":", base64_decode($_POST['MAGIC_COOKIE']));
+} else {
+  echo json_encode(array('result'=>array('error'=>'Missing credentials')));
+  exit;
+}
+
+if (!verify_password($user,$pw)) {
+  echo json_encode(array('result'=>array('error'=>'Invalid user or 
password')));
+  exit;
+}
+
+...@mysql_connect("localhost","nobody","") or die("Unable to connect to SQL 
server.");
+...@mysql_select_db("phpbugdb");
+
+# fetch info about the bug into $bug
+$query = "SELECT 
id,bug_type,email,sdesc,ldesc,php_version,php_os,status,ts1,ts2,assign,"
+       . "UNIX_TIMESTAMP(ts1) AS submitted, UNIX_TIMESTAMP(ts2) AS modified,"
+       . "COUNT(bug=id) AS votes,"
+       . "SUM(reproduced) AS reproduced,SUM(tried) AS tried,"
+       . "SUM(sameos) AS sameos, SUM(samever) AS samever,"
+       . "AVG(score)+3 AS average,STD(score) AS deviation"
+       . " FROM bugdb LEFT JOIN bugdb_votes ON id=bug WHERE id=$id"
+       . " GROUP BY bug";
+
+$res = mysql_query($query);
+
+if ($res) {
+    $bug = mysql_fetch_assoc($res);
+}
+
+if (!$res || !$bug) {
+  echo json_encode(array('result'=>array('error'=>'No such bug')));
+  exit;
+}
+
+if(!empty($_POST['ncomment'])) {
+    $ncomment = trim($_POST['ncomment']);
+    $query = "INSERT INTO bugdb_comments (bug,email,ts,comment) VALUES 
('$id','$u...@php.net',NOW(),'".mysql_real_escape_string($ncomment)."')";
+    $success = @mysql_query($query);
+    if($success) {
+        echo json_encode(array('result'=>array('status'=>$bug)));
+    } else {
+        echo json_encode(array('result'=>array('error'=>mysql_error())));
+        exit;
+    }
+}
+
+echo json_encode(array('result'=>array('error'=>'Nothing to do')));




--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to