Commit: 4a6cbdd7b551664f76c536fd67c009ba25c98d2d
Author: Alexander Moskaliov(ir...@php.net) Sun, 18 Mar 2012 19:43:31
+0400
Committer: Alexander Moskaliov(ir...@php.net) Sun, 18 Mar 2012 19:43:31
+0400
Parents: 7c4de5d5a9e10eb0322d87e69f07e32ad843de60
Link:
http://git.php.net/?p=karma.git;a=commitdiff;h=4a6cbdd7b551664f76c536fd67c009ba25c98d2d
Log:
add "in-reply-to" test support and fix phpdoc
Changed paths:
M lib/Git/PostReceiveHook.php
M lib/Git/ReceiveHook.php
M lib/Mail.php
4a6cbdd7b551664f76c536fd67c009ba25c98d2d
diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php
index 5955bc2..743b6ac 100644
--- a/lib/Git/PostReceiveHook.php
+++ b/lib/Git/PostReceiveHook.php
@@ -17,12 +17,14 @@ class PostReceiveHook extends ReceiveHook
private $allBranches = [];
+ private $branchesMailIds = [];
+
/**
- * @param $basePath string base path for all repositories
- * @param $pushAuthor string user who make push
- * @param $usersFile string path to file with users data
- * @param $mailingList string mail recipient
- * @param $emailPrefix string prefix for mail subject
+ * @param string $basePath base path for all repositories
+ * @param string $pushAuthor user who make push
+ * @param string $usersFile path to file with users data
+ * @param string $mailingList mail recipient
+ * @param string $emailPrefix prefix for mail subject
*/
public function __construct($basePath, $pushAuthor, $usersFile,
$mailingList, $emailPrefix)
{
@@ -39,7 +41,7 @@ class PostReceiveHook extends ReceiveHook
/**
* Find user name by nickname in users data file
- * @param $user user nickname
+ * @param string $user user nickname
* @return string user name
*/
public function getUserName($user)
@@ -83,7 +85,7 @@ class PostReceiveHook extends ReceiveHook
if ($ref['reftype'] == self::REF_TAG) {
$this->sendTagMail($ref['refname'], $ref['changetype'],
$ref['old'], $ref['new']);
} elseif ($ref['reftype'] == self::REF_BRANCH){
- $this->sendBranchMail($ref['refname'], $ref['changetype'],
$ref['old'], $ref['new']);
+ $this->branchesMailIds[$ref['refname']] =
$this->sendBranchMail($ref['refname'], $ref['changetype'], $ref['old'],
$ref['new']);
}
}
@@ -91,12 +93,11 @@ class PostReceiveHook extends ReceiveHook
foreach ($this->revisions as $revision => $branches) {
// check if it commit was already in other branches
if (!$this->isRevExistsInBranches($revision,
array_diff($this->allBranches, $branches))) {
- $this->sendCommitMail($revision);
+ $this->sendCommitMail($revision, $branches);
}
}
}
-
/**
* Send mail about branch.
* Subject: [git] [branch] %PROJECT%: %STATUS% branch %BRANCH_NAME%
@@ -119,10 +120,11 @@ class PostReceiveHook extends ReceiveHook
*
* --/part1--
*
- * @param $name string branch fullname (refs/heads/example)
- * @param $changeType int delete, create or update
- * @param $oldrev string old revision
- * @param $newrev string new revision
+ * @param string $name branch fullname (refs/heads/example)
+ * @param int $changeType delete, create or update
+ * @param string $oldrev old revision
+ * @param string $newrev new revision
+ * @return string mail uniq id
*/
private function sendBranchMail($name, $changeType, $oldrev, $newrev)
{
@@ -202,12 +204,13 @@ class PostReceiveHook extends ReceiveHook
$mail->send();
+ return $mail->getId();
}
/**
* Cache revisions per branche for use it later
- * @param $branchName string branch fullname
+ * @param string $branchName branch fullname
* @param array $revisions revisions array
*/
private function cacheRevisions($branchName, array $revisions)
@@ -245,10 +248,10 @@ class PostReceiveHook extends ReceiveHook
* %PATHS%
* --/part1--
*
- * @param $name string tag fullname (refs/tags/example)
- * @param $changeType int delete, create or update
- * @param $oldrev string old revision
- * @param $newrev string new revision
+ * @param string $name tag fullname (refs/tags/example)
+ * @param int $changeType delete, create or update
+ * @param string $oldrev old revision
+ * @param string $newrev new revision
*/
private function sendTagMail($name, $changeType, $oldrev, $newrev)
{
@@ -321,7 +324,7 @@ class PostReceiveHook extends ReceiveHook
* only for annotated tag:
* 'tagger', 'tagger_email', 'tagger_date' - info about tagger person
* 'log' - tag message
- * @param $tag string tag fullname
+ * @param string $tag tag fullname
* @return array array with tag info
*/
private function getTagInfo($tag)
@@ -351,10 +354,10 @@ class PostReceiveHook extends ReceiveHook
/**
* Find revisions for branch change
* Also cache revisions list for revisions mails
- * @param $name string branch fullname (refs/heads/example)
- * @param $changeType int delete, create or update
- * @param $oldrev string old revision
- * @param $newrev string new revision
+ * @param string $name branch fullname (refs/heads/example)
+ * @param int $changeType delete, create or update
+ * @param string $oldrev old revision
+ * @param string $newrev new revision
* @return array revisions list
*/
private function getBranchRevisions($name, $changeType, $oldrev, $newrev)
@@ -388,7 +391,7 @@ class PostReceiveHook extends ReceiveHook
*
* Required already escaped string in $revRange!!!
*
- * @param $revRange string A..B or A ^B C --not D etc.
+ * @param string $revRange A..B or A ^B C --not D etc.
* @return array revsions list
*/
private function getRevisions($revRange)
@@ -412,7 +415,7 @@ class PostReceiveHook extends ReceiveHook
* 'log' - full commit message
*
* Also cache revision info
- * @param $revision revision
+ * @param string $revision revision
* @return array commit info array
*/
private function getCommitInfo($revision)
@@ -429,7 +432,7 @@ class PostReceiveHook extends ReceiveHook
'committer_email' => $raw[6], // %ce
'committer_date' => $raw[7], // %cD
'subject' => $raw[8], // %s
- 'log' => $raw[9]
+ 'log' => $raw[9] // %B
];
}
return $this->commitsData[$revision];
@@ -437,7 +440,7 @@ class PostReceiveHook extends ReceiveHook
/**
* Find info about bugs in log message
- * @param $log log message
+ * @param string $log log message
* @return array array with bug numbers and links in values
*/
private function getBugs($log)
@@ -483,9 +486,10 @@ class PostReceiveHook extends ReceiveHook
* %DIFF%
* --/part2--
*
- * @param $revision string commit revision
+ * @param string $revision commit revision
+ * @param array $branches branches in current push with this commit
*/
- private function sendCommitMail($revision)
+ private function sendCommitMail($revision, $branches)
{
$info = $this->getCommitInfo($revision);
@@ -556,13 +560,19 @@ class PostReceiveHook extends ReceiveHook
$mail->setFrom($this->pushAuthor . '@php.net', $this->pushAuthorName);
$mail->addTo($this->mailingList);
+ foreach ($branches as $branch) {
+ if (isset($this->branchesMailIds[$branch])) {
+ $mail->addReplyTo($this->branchesMailIds[$branch]);
+ }
+ }
+
$mail->send();
}
/**
* Check if revision exists in branches list
- * @param $revision string revision
+ * @param string $revision revision
* @param array $branches branches
* @return bool
*/
diff --git a/lib/Git/ReceiveHook.php b/lib/Git/ReceiveHook.php
index a182a5d..72a51b5 100644
--- a/lib/Git/ReceiveHook.php
+++ b/lib/Git/ReceiveHook.php
@@ -16,7 +16,7 @@ abstract class ReceiveHook
protected $refs = [];
/**
- * @param $basePath Base path for all repositories
+ * @param string $basePath Base path for all repositories
*/
public function __construct($basePath)
{
@@ -28,10 +28,10 @@ abstract class ReceiveHook
/**
* Escape array items by escapeshellarg function
- * @param $args
+ * @param array $args
* @return array array with escaped items
*/
- protected function escapeArrayShellArgs($args)
+ protected function escapeArrayShellArgs(array $args)
{
return array_map('escapeshellarg', $args);
}
@@ -57,7 +57,7 @@ abstract class ReceiveHook
*
* Required already escaped string in $revRange!!!
*
- * @param $revRange
+ * @param string $revRange
* @return array
*/
protected function getChangedPaths($revRange)
diff --git a/lib/Mail.php b/lib/Mail.php
index dca9e6e..15b90e8 100644
--- a/lib/Mail.php
+++ b/lib/Mail.php
@@ -10,13 +10,39 @@ class Mail
private $files = [];
private $multipart = false;
private $boundary = '';
+ private $uniqId = '';
+ private $replyTo = [];
const CRLF = "\r\n";
+
+ public function __construct()
+ {
+ $this->uniqId = '<php-mail-' . md5(microtime()) . mt_rand() .
'@git.php.net>';
+ }
+
+ /**
+ * Return unique id of mail
+ * @return string unique Id of message in format:
'<php-mail-...@git.php.net';
+ */
+ public function getId()
+ {
+ return $this->uniqId;
+ }
+
+ /**
+ * Add parent mail for this mail
+ * @param string $uniqId unique Id of message in format:
'<php-mail-...@git.php.net';
+ */
+ public function addReplyTo($uniqId)
+ {
+ $this->replyTo[] = $uniqId;
+ }
+
/**
* Add attached text file to mail
- * @param $name string unique file name
- * @param $data string file content
+ * @param string $name unique file name
+ * @param string $data file content
*/
public function addTextFile($name , $data)
{
@@ -25,7 +51,7 @@ class Mail
/**
* Return length of attached file
- * @param $name string unique file name
+ * @param string $name unique file name
* @return int file length
*/
public function getFileLength($name)
@@ -36,7 +62,7 @@ class Mail
/**
* Delete attached file
- * @param $name unique file name
+ * @param string $name unique file name
*/
public function dropFile($name)
{
@@ -66,7 +92,7 @@ class Mail
/**
* Set mail subject
- * @param $subject string subject
+ * @param string $subject subject
*/
public function setSubject($subject)
{
@@ -75,7 +101,7 @@ class Mail
/**
* Set mail body text
- * @param $message string body text
+ * @param string $message body text
*/
public function setMessage($message)
{
@@ -85,8 +111,8 @@ class Mail
/**
* Format header string
- * @param $name string header name
- * @param $value string header value
+ * @param string $name header name
+ * @param string $value header value
* @return string header string
*/
private function makeHeader($name, $value)
@@ -106,14 +132,14 @@ class Mail
/**
* Cut end encode string by mb_encode_mimeheader
- * @param $value string utf8 string
+ * @param string $value utf8 string
* @param int $maxLenght max length
* @return string encoded string
*/
private function utf8SafeEncode($value, $maxLenght = null)
{
if ($maxLenght) $value = mb_substr($value, 0, $maxLenght);
- return mb_encode_mimeheader($value, 'UTF-8', 'Q');;
+ return mb_encode_mimeheader($value, 'UTF-8', 'Q');
}
/**
@@ -124,12 +150,16 @@ class Mail
{
$headers = [];
$headers[] = $this->makeHeader('From',
$this->makeAddress($this->from));
- $uniq = 'php-mail-' . md5(microtime()) . mt_rand();
- $headers[] = $this->makeHeader('Message-ID', '<' . $uniq .
'@git.php.net>');
+ $headers[] = $this->makeHeader('Message-ID', $this->uniqId);
+ if (count($this->replyTo)) {
+ $replyTo = implode(' ', $this->replyTo);
+ $headers[] = $this->makeHeader('References', $replyTo);
+ $headers[] = $this->makeHeader('In-Reply-To', $replyTo);
+ }
$headers[] = $this->makeHeader('MIME-Version', '1.0');
$headers[] = $this->makeHeader('Date', date(DATE_RFC2822, time()));
if ($this->multipart) {
- $this->boundary = sha1($uniq);
+ $this->boundary = sha1($this->uniqId);
$headers[] = $this->makeHeader('Content-Type', 'multipart/mixed;
boundary="' . $this->boundary . '"');
} else {
$headers[] = $this->makeHeader('Content-Type', 'text/plain;
charset="utf-8"');
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php