The branch PHP_POST_RECEIVE on karma.git has been updated
via 13ad30c07628e08f20e5000956a8fb5abb7438e7 (commit)
from cffd3b39b05fae71090586fcc9f717f857c20ae0 (commit)
http://git.php.net/?p=karma.git;a=log;h=13ad30c07628e08f20e5000956a8fb5abb7438e7;hp=cffd3b39b05fae71090586fcc9f717f857c20ae0
Summary of changes:
hooks/post-receive.mail | 5 +-
lib/Git/PostReceiveHook.php | 94 +++++++++++++++++++++++++++++++-----------
lib/Git/ReceiveHook.php | 3 +
lib/Mail.php | 54 ++++++++++++++++---------
4 files changed, 109 insertions(+), 47 deletions(-)
-- Log ----------------------------------------
commit 13ad30c07628e08f20e5000956a8fb5abb7438e7
Author: Irker <[email protected]>
Date: Thu Mar 15 13:12:58 2012 +0400
phpdoc
diff --git a/hooks/post-receive.mail b/hooks/post-receive.mail
index aacadef..8814b35 100755
--- a/hooks/post-receive.mail
+++ b/hooks/post-receive.mail
@@ -2,10 +2,9 @@
<?php
namespace Karma;
-// STATUS: not worked
+// STATUS: may be worked
// TODO: add license
-// TODO: refactor
-// TODO: documentation
+// TODO: refactoring and testing
error_reporting(E_ALL | E_STRICT);
diff --git a/lib/Git/PostReceiveHook.php b/lib/Git/PostReceiveHook.php
index 589e96a..86992ca 100644
--- a/lib/Git/PostReceiveHook.php
+++ b/lib/Git/PostReceiveHook.php
@@ -18,11 +18,11 @@ class PostReceiveHook extends ReceiveHook
private $allBranches = [];
/**
- * @param $basePath string
- * @param $pushAuthor string
- * @param $usersFile string
- * @param $mailingList string
- * @param $emailPrefix string
+ * @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
*/
public function __construct($basePath, $pushAuthor, $usersFile,
$mailingList, $emailPrefix)
{
@@ -37,6 +37,11 @@ class PostReceiveHook extends ReceiveHook
$this->allBranches = $this->getAllBranches();
}
+ /**
+ * Find user name by nickname in users data file
+ * @param $user user nickname
+ * @return string user name
+ */
public function getUserName($user)
{
$usersDB = file($this->usersFile);
@@ -52,7 +57,9 @@ class PostReceiveHook extends ReceiveHook
/**
- *
+ * Parse input from STDIN
+ * Mail about changes in heads(branches) and tags
+ * Mail about new commits
*/
public function process()
{
@@ -120,10 +127,10 @@ class PostReceiveHook extends ReceiveHook
*
* --/part1--
*
- * @param $name string
- * @param $changeType int
- * @param $oldrev string
- * @param $newrev string
+ * @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
*/
private function sendBranchMail($name, $changeType, $oldrev, $newrev)
{
@@ -204,8 +211,9 @@ class PostReceiveHook extends ReceiveHook
/**
- * @param $branchName string
- * @param array $revisions
+ * Cache revisions per branche for use it later
+ * @param $branchName string branch fullname
+ * @param array $revisions revisions array
*/
private function cacheRevisions($branchName, array $revisions)
{
@@ -242,10 +250,10 @@ class PostReceiveHook extends ReceiveHook
* %PATHS%
* --/part1--
*
- * @param $name string
- * @param $changeType int
- * @param $oldrev string
- * @param $newrev string
+ * @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
*/
private function sendTagMail($name, $changeType, $oldrev, $newrev)
{
@@ -310,8 +318,16 @@ class PostReceiveHook extends ReceiveHook
}
/**
- * @param $tag string
- * @return string
+ * Get info for tag
+ * It return array with items:
+ * 'annotated' flag,
+ * 'revision' - tag sha,
+ * 'target' - target sha (if tag not annotated it equal 'revision')
+ * only for annotated tag:
+ * 'tagger', 'tagger_email', 'tagger_date' - info about tagger person
+ * 'log' - tag message
+ * @param $tag string tag fullname
+ * @return array array with tag info
*/
private function getTagInfo($tag)
{
@@ -337,8 +353,15 @@ class PostReceiveHook extends ReceiveHook
return $info;
}
-
-
+ /**
+ * 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
+ * @return array revisions list
+ */
private function getBranchRevisions($name, $changeType, $oldrev, $newrev)
{
if ($changeType == self::TYPE_UPDATED) {
@@ -350,6 +373,8 @@ class PostReceiveHook extends ReceiveHook
escapeshellarg($newrev) . ' --not ' . implode(' ',
$this->escapeArrayShellArgs($this->alreadyExistsBranches))
);
+ // for new branches we check if they was separated from other
branches in same push
+ // see README.POST_RECEIVE_MAIL "commit mail" part.
foreach ($this->updatedBranches as $refname) {
if ($this->isRevExistsInBranches($this->refs[$refname]['old'],
[$name])) {
$this->cacheRevisions($name,
$this->getRevisions(escapeshellarg($this->refs[$refname]['old'] . '..' .
$newrev)));
@@ -369,7 +394,7 @@ class PostReceiveHook extends ReceiveHook
* Required already escaped string in $revRange!!!
*
* @param $revRange string A..B or A ^B C --not D etc.
- * @return array
+ * @return array revsions list
*/
private function getRevisions($revRange)
{
@@ -382,7 +407,20 @@ class PostReceiveHook extends ReceiveHook
}
-
+ /**
+ * Get info for commit
+ * It return array with items:
+ * 'parents' -list of parents sha,
+ * 'author', 'author_email', 'author_date' - info about author person
+ * 'committer', 'committer_email', 'committer_date' - info about committer
person
+ * 'subject' - commit subject line
+ * 'log' - full commit message
+ * 'time' - 'committer_date' in timestamp
+ *
+ * Also cache revision info
+ * @param $revision revision
+ * @return array commit info array
+ */
private function getCommitInfo($revision)
{
if (!isset($this->commitsData[$revision])) {
@@ -404,6 +442,11 @@ class PostReceiveHook extends ReceiveHook
return $this->commitsData[$revision];
}
+ /**
+ * Find info about bugs in log message
+ * @param $log log message
+ * @return array array with bug numbers and links in values
+ */
private function getBugs($log)
{
$bugUrlPrefixes = [
@@ -447,7 +490,7 @@ class PostReceiveHook extends ReceiveHook
* %DIFF%
* --/part2--
*
- * @param $revision string
+ * @param $revision string commit revision
*/
private function sendCommitMail($revision)
{
@@ -525,8 +568,9 @@ class PostReceiveHook extends ReceiveHook
/**
- * @param $revision string
- * @param array $branches
+ * Check if revision exists in branches list
+ * @param $revision string revision
+ * @param array $branches branches
* @return bool
*/
private function isRevExistsInBranches($revision, array $branches) {
diff --git a/lib/Git/ReceiveHook.php b/lib/Git/ReceiveHook.php
index 7860043..a182a5d 100644
--- a/lib/Git/ReceiveHook.php
+++ b/lib/Git/ReceiveHook.php
@@ -15,6 +15,9 @@ abstract class ReceiveHook
private $repositoryName = '';
protected $refs = [];
+ /**
+ * @param $basePath Base path for all repositories
+ */
public function __construct($basePath)
{
$rel_path = str_replace($basePath, '', \Git::getRepositoryPath());
diff --git a/lib/Mail.php b/lib/Mail.php
index 21469b9..dca9e6e 100644
--- a/lib/Mail.php
+++ b/lib/Mail.php
@@ -14,8 +14,9 @@ class Mail
const CRLF = "\r\n";
/**
+ * Add attached text file to mail
* @param $name string unique file name
- * @param $data string
+ * @param $data string file content
*/
public function addTextFile($name , $data)
{
@@ -23,8 +24,9 @@ class Mail
}
/**
- * @param $name string
- * @return int
+ * Return length of attached file
+ * @param $name string unique file name
+ * @return int file length
*/
public function getFileLength($name)
{
@@ -32,6 +34,10 @@ class Mail
return isset($this->files[$name]) ? strlen($this->files[$name]) : 0;
}
+ /**
+ * Delete attached file
+ * @param $name unique file name
+ */
public function dropFile($name)
{
$name = trim($name);
@@ -39,8 +45,9 @@ class Mail
}
/**
- * @param string $email
- * @param string $name
+ * Set "From" address
+ * @param string $email email author address
+ * @param string $name author name
*/
public function setFrom($email, $name = '')
{
@@ -48,8 +55,9 @@ class Mail
}
/**
- * @param string $email
- * @param string $name
+ * Add recipient address
+ * @param string $email recipient address
+ * @param string $name recipient name
*/
public function addTo($email, $name = '')
{
@@ -57,7 +65,8 @@ class Mail
}
/**
- * @param $subject string
+ * Set mail subject
+ * @param $subject string subject
*/
public function setSubject($subject)
{
@@ -65,7 +74,8 @@ class Mail
}
/**
- * @param $message string
+ * Set mail body text
+ * @param $message string body text
*/
public function setMessage($message)
{
@@ -74,9 +84,10 @@ class Mail
/**
- * @param $name string
- * @param $value string
- * @return string
+ * Format header string
+ * @param $name string header name
+ * @param $value string header value
+ * @return string header string
*/
private function makeHeader($name, $value)
{
@@ -84,8 +95,9 @@ class Mail
}
/**
- * @param array $address
- * @return string
+ * Format address string
+ * @param array $address array with email adress and name
+ * @return string address string
*/
private function makeAddress(array $address)
{
@@ -93,9 +105,10 @@ class Mail
}
/**
- * @param $value string
- * @param int $maxLenght
- * @return string
+ * Cut end encode string by mb_encode_mimeheader
+ * @param $value string utf8 string
+ * @param int $maxLenght max length
+ * @return string encoded string
*/
private function utf8SafeEncode($value, $maxLenght = null)
{
@@ -104,7 +117,8 @@ class Mail
}
/**
- * @return string
+ * Prepare heade part of mail
+ * @return string header part of mail
*/
private function makeHeaders()
{
@@ -126,7 +140,8 @@ class Mail
}
/**
- * @return string
+ * Prepare body part of mail
+ * @return string mail body
*/
private function makeBody()
{
@@ -153,6 +168,7 @@ class Mail
}
/**
+ * Send current mail
* @return bool
*/
public function send()
Thank you for your contribution.
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php