-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
/** | ||
* Copyright (c) <2009>, all contributors | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* - Neither the name of the project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* This software is provided by the copyright holders and contributors "as is" | ||
* and any express or implied warranties, including, but not limited to, the | ||
* implied warranties of merchantability and fitness for a particular purpose | ||
* are disclaimed. in no event shall the copyright owner or contributors be | ||
* liable for any direct, indirect, incidental, special, exemplary, or | ||
* consequential damages (including, but not limited to, procurement of | ||
* substitute goods or services; loss of use, data, or profits; or business | ||
* interruption) however caused and on any theory of liability, whether in | ||
* contract, strict liability, or tort (including negligence or otherwise) | ||
* arising in any way out of the use of this software, even if advised of the | ||
* possibility of such damage. | ||
* | ||
* @package php-commit-hooks | ||
* @version $Revision$ | ||
* @license http://www.opensource.org/licenses/bsd-license.html New BSD license | ||
*/ | ||
|
||
/** | ||
* Reporter designed for a special k.Bot module to report commits to IRC | ||
* | ||
* @package php-commit-hooks | ||
* @version $Revision$ | ||
* @license http://www.opensource.org/licenses/bsd-license.html New BSD license | ||
*/ | ||
class pchKbotReporter extends pchReporter | ||
{ | ||
/** | ||
* URL the report will be passed to | ||
* | ||
* @var string | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* Shared secret used to verify the senders autheticity | ||
* | ||
* @var string | ||
*/ | ||
protected $secret; | ||
|
||
/** | ||
* Project name used in the report | ||
* | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* IRC-Channel to report to | ||
* | ||
* @var string | ||
*/ | ||
protected $channel; | ||
|
||
/** | ||
* Number of the bot, which receives the command | ||
* | ||
* @var int | ||
*/ | ||
protected $bot = 1; | ||
|
||
/** | ||
* Construct k.Bot reporter from shared secret | ||
* | ||
* @param string $secret | ||
* @param string $name | ||
* @param string $channel | ||
* @param int $bot | ||
* @return void | ||
*/ | ||
public function __construct( $url, $secret, $name, $channel, $bot = 1 ) | ||
{ | ||
$this->url = $url; | ||
$this->secret = $secret; | ||
$this->name = $name; | ||
$this->channel = $channel; | ||
$this->bot = (int) $bot; | ||
} | ||
|
||
/** | ||
* Report occured issues | ||
* | ||
* Report occured issues, passed as an array to the command line. Will exit | ||
* with a non-zero exit code if any "errors" occured, and with a zero exit | ||
* code, of no issues occured. | ||
* | ||
* Will always abort script execution. | ||
* | ||
* @param pchRepository $repository | ||
* @param array $issues | ||
* @return void | ||
*/ | ||
public function report( pchRepository $repository, array $issues ) | ||
{ | ||
// Configure who should receive this notification | ||
$commit['bot'] = $this->bot; | ||
|
||
// Basic repository information | ||
$commit['repository'] = $repository->path; | ||
$commit['revision'] = $repository->version; | ||
$commit['project'] = $this->name; | ||
$commit['channel'] = $this->channel; | ||
|
||
// Get more info from repository using svnlook | ||
$commit['author'] = $repository->author; | ||
$commit['date'] = $repository->date; | ||
$commit['log'] = $repository->log; | ||
$commit['dirs'] = substr( $repository->{'dirs-changed'}, 0, 80 ); | ||
|
||
// Build checksum for primitive authentification of request | ||
$commit['checksum'] = md5( $this->secret . '-' . implode( '_', $commit ) ); | ||
|
||
// Send data over the wire | ||
file_get_contents( $this->url . '?' . http_build_query( $commit ) ); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters