Commit:    d038684673c4f99e7d52c6c7ebfa1082351baefb
Author:    Anatol Belski <[email protected]>         Sat, 28 Sep 2013 00:33:35 +0200
Parents:   87c84793a9ed07795905f1e2b973476889653515
Branches:  master

Link:       
http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=d038684673c4f99e7d52c6c7ebfa1082351baefb

Log:
improvements to aggregated mailing

Changed paths:
  M  client/include/PeclExt.php
  M  client/include/PeclMail.php
  M  client/script/pecl.php

diff --git a/client/include/PeclExt.php b/client/include/PeclExt.php
index 2ac5155..140fbca 100644
--- a/client/include/PeclExt.php
+++ b/client/include/PeclExt.php
@@ -52,7 +52,6 @@ class PeclExt
        public function init($force_name = NULL, $force_version = NULL)
        {
                $this->unpack();
-               $this->check();
 
                $this->name = $force_name;
                $this->version = $force_version;
@@ -65,6 +64,10 @@ class PeclExt
                        $this->version = 
(string)$this->getPackageXmlProperty("version", "release");
                }
 
+               /* Looks a bit strange, but usually we would get a name from 
package.xml, if not - we're
+                  required to ->check() before trying to access config.w32 and 
that's a hack anyway. */
+               $this->check();
+
                if (!$this->name) {
                        /* This is the fallback if there's no package.xml  */
                        if (!$this->name) {
@@ -699,15 +702,15 @@ if (!function_exists('rmtools\combinations')) {
        public function mailMaintainers($success, $is_snap, array $logs, 
PeclMail $mailer, $force_email = NULL)
        {
                $seg = $is_snap ? 'snaps' : 'releases';
-               $url = 'http://windows.php.net/downloads/pecl/' . $seg . '/' . 
$this->name . '/' . $this->version;
+               $url = 'http://windows.php.net/downloads/pecl/' . $seg . '/' . 
$this->name . '/' . $this->version . '/';
 
                if ($mailer->isAggregated()) {
                        /* NOTE we're not able to send all the build logs in an 
aggregated mail right now.
                           But that's fine, they are uploaded anyway. */
                        if ($success) {
-                               $msg = $this->getPackageName() . " 
succeeded\n\n";
+                               $msg = $this->getPackageName() . " succeeded\n";
                        } else {
-                               $msg = $this->getPackageName() . " failed\n\n";
+                               $msg = $this->getPackageName() . " failed\n";
                        }
                } else {
                        if ($success) {
diff --git a/client/include/PeclMail.php b/client/include/PeclMail.php
index a5491e0..94a6245 100644
--- a/client/include/PeclMail.php
+++ b/client/include/PeclMail.php
@@ -29,13 +29,6 @@ class PeclMail {
                }
        }
 
-       public function __destruct()
-       {
-               if (!$this->aggregated_sent) {
-                       $this->saveState();
-               }
-       }
-
        public function saveState()
        {
                $tmp = serialize($this->buffer);
@@ -59,15 +52,21 @@ class PeclMail {
                        return xmail($from, $to, $subject, $text, $attachment);
                }
 
+               /* aggregate all the stuff below */
                $this->buffer['to'][] = $to;
                $this->buffer['from'][] = $from;
-               /* subject can't be aggregated anyway */
+               /* subject can't be aggregated anyway , or?*/
                $this->buffer['subject'] = $subject;
-               $this->buffer['text'] = $this->buffer['text'] ."\n\n" . $text;
+               $this->buffer['text'] = $this->buffer['text'] ."\n" . $text;
                $this->buffer['attachment'] = array_merge($attachment, 
$this->buffer['attachment']);
+
+               $this->saveState();
+
+               /* fake we've sent it */
+               return true;
        }
 
-       public function mailAggregated($from, $to, $subject, $open, $close)
+       public function mailAggregated($from, $to, $subject, $open, $close, 
$with_attachment)
        {
                if (!$to) {
                        $to = implode(',', array_unique($this->buffer['to']));
@@ -77,6 +76,8 @@ class PeclMail {
                }
                $text = "$open\n\n" . $this->buffer['text'] . "\n\n$close";
 
+               $att = $with_attachment ? $this->buffer['attachment'] : array();
+
                $this->aggregated_sent = true;
                
                return xmail($from, $to, $subject, $text, 
$this->buffer['attachment']);
diff --git a/client/script/pecl.php b/client/script/pecl.php
index 3b98a97..99db173 100644
--- a/client/script/pecl.php
+++ b/client/script/pecl.php
@@ -72,11 +72,14 @@ $branch_name = $branch->config->getName();
 
 /* Init things if --first was given */
 if ($is_first_run) {
+       echo PHP_EOL;
        echo "First invocation for <$pkg_path> started." . PHP_EOL . PHP_EOL;
 
        try {
                /* Not sure it's needed anymore, but let it persist */
                $mailer = new rm\PeclMail($pkg_path, $aggregate_mail);
+               $mailer->saveState();
+               unset($mailer);
        } catch (Exception $e) {
                echo 'Error: ' . $e->getMessage() . PHP_EOL;
                $was_errors = true;
@@ -141,15 +144,26 @@ foreach ($builds as $build_name) {
                if ($mail_maintainers) {
                        $maintainer_mailto = $force_email ? $force_email: 
MAIL_TO_FALLBACK;
 
-                       echo "Mailing info to <$maintainer_mailto>" . PHP_EOL;
-
-                       xmail(
-                               MAIL_FROM,
-                               /* no chance to have the maintainers mailto at 
this stage */
-                               $maintainer_mailto,
-                               '[PECL-DEV] Windows build: ' . 
basename($pkg_path),
-                               "PECL build failed before it could start for 
the reasons below:\n\n" . $e->getMessage()
-                       );
+                       if (!$aggregate_mail) {
+                               echo "Mailing info to <$maintainer_mailto>" . 
PHP_EOL;
+                       }
+                       if ($mailer) {
+                               $mailer->xmail(
+                                       MAIL_FROM,
+                                       /* no chance to have the maintainers 
mailto at this stage */
+                                       $maintainer_mailto,
+                                       '[PECL-DEV] Windows build: ' . 
basename($pkg_path),
+                                       $ext->getPackageName() . " not 
started\nReason: " . $e->getMessage()
+                               );
+                       } else {
+                               xmail(
+                                       MAIL_FROM,
+                                       /* no chance to have the maintainers 
mailto at this stage */
+                                       $maintainer_mailto,
+                                       '[PECL-DEV] Windows build: ' . 
basename($pkg_path),
+                                       $ext->getPackageName() . " not 
started\nReason: " . $e->getMessage()
+                               );
+                       }
                }
 
                $build->clean();
@@ -186,13 +200,16 @@ foreach ($builds as $build_name) {
                                }
                        }
 
-                       echo "Mailing info to <$maintainer_mailto>" . PHP_EOL;
+                       
+                       if (!$aggregate_mail) {
+                               echo "Mailing info to <$maintainer_mailto>" . 
PHP_EOL;
+                       }
 
-                       rm\xmail(
+                       $mailer->xmail(
                                MAIL_FROM,
                                $maintainer_mailto,
                                '[PECL-DEV] Windows build: ' . 
basename($pkg_path),
-                               "PECL build failed before it could start for 
the reasons below:\n\n" . $e->getMessage()
+                               $ext->getPackageName() . " not started\nReason: 
" . $e->getMessage()
                        );
                }
 
@@ -326,7 +343,13 @@ foreach ($builds as $build_name) {
                                }
                        }
 
-                       echo "Mailing logs to <$maintainer_mailto>" . PHP_EOL;
+                       if (!$aggregate_mail) {
+                               echo "Mailing logs to <$maintainer_mailto>" . 
PHP_EOL;
+                       } else {
+                               /* Save a couple of things so we can use them 
for aggregated mail */
+                               $last_ext_name = $ext->getName();
+                               $last_ext_version = $ext->getVersion();
+                       }
 
                        $res = $ext->mailMaintainers(0 == $build_error, 
$is_snap, array($logs_zip), $mailer, $maintainer_mailto);
                        if (!$res) {
@@ -355,6 +378,7 @@ Coventry:
 
        unset($ext);
        unset($build);
+       unset($mailer);
        if (isset($db)) {
                unset($db);
        }
@@ -369,20 +393,56 @@ echo "Run finished." . PHP_EOL . PHP_EOL;
 /* Cleanup things if --last was given */
 if ($is_last_run) {
        echo "Last invocation for <$pkg_path> finished." . PHP_EOL . PHP_EOL;
-       try {
-               $mailer = new rm\PeclMail($pkg_path, $aggregate_mail);
 
-               $mailer->mailAggredated(
-                       NULL,
-                       NULL,
-                       '[PECL-DEV] Windows build: ' . basename($pkg_path),
-                       'Hi,',
-                       'Have a nice day'
-               );
-               $mailer->cleanup();
-       } catch (Exception $e) {
-               echo 'Error: ' . $e->getMessage() . PHP_EOL;
-               $was_errors = true;
+       if ($aggregate_mail) {
+               try {
+                       $mailer = new rm\PeclMail($pkg_path, $aggregate_mail);
+
+                       echo "Sending aggregated report mail to 
<$maintainer_mailto>" . PHP_EOL;
+               
+                       $seg = $is_snap ? 'snaps' : 'releases';
+                       $url = 'http://windows.php.net/downloads/pecl/' . $seg 
. '/';
+                       if (isset($last_ext_name) && isset($last_ext_name)) {
+                               $url .= $last_ext_name . '/' . 
$last_ext_version . '/';
+                       }
+
+
+                       $from = NULL;
+                       $to = NULL;
+                       if (isset($last_ext_name) && isset($last_ext_name)) {
+                               $subject = '[PECL-DEV] Windows build: ' . 
$last_ext_name . '-' . $last_ext_version;
+                       } else {
+                               $subject = '[PECL-DEV] Windows build: ' . 
basename($pkg_path);
+                       }
+
+                       $open = "\nFilename: " . basename($pkg_path) . "\n";
+                       if (isset($last_ext_name)) {
+                               $open .= "Extension name: $last_ext_name\n";
+                       }
+                       if (isset($last_ext_name)) {
+                               $open .= "Extension version: 
$last_ext_version\n";
+                       }
+                       $open .= "Build type: " . ($is_snap ? 'snapshot' : 
'release') . "\n\n";
+                       $open .= "For each build combination and status please 
refer to the list below."; 
+
+                       if ($upload) {
+                               $close = "Upload status: ";
+                               if ($upload_success) {
+                                       $close .= "succceeded\n";
+                                       $close .= "URL: $url\n\n";
+                               } else {
+                                       $close .= "failed\n\n";
+                               }
+                       }
+                       $close .= "This mail is being sent to you because you 
are the lead developer in package.xml\n\n";
+                       $close .= "Have a nice day";
+
+                       $mailer-> mailAggregated($from, $to, $subject, $open, 
$close, false);
+                       $mailer->cleanup();
+               } catch (Exception $e) {
+                       echo 'Error: ' . $e->getMessage() . PHP_EOL;
+                       $was_errors = true;
+               }
        }
 }
-- 
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to