Skip to content

Commit

Permalink
- Implemented: k.Bot reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
kore committed May 17, 2010
1 parent 7631112 commit 92ca135
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/classes/reporter/dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @version $Revision$
* @license http://www.opensource.org/licenses/bsd-license.html New BSD license
*/
class pchReporterDsipatcher extends pchReporter
class pchReporterDispatcher extends pchReporter
{
/**
* List of reporters to dispatch to.
Expand Down
134 changes: 134 additions & 0 deletions src/classes/reporter/kbot.php
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 ) );
}
}

2 changes: 2 additions & 0 deletions src/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
require __DIR__ . '/classes/string_stream.php';

require __DIR__ . '/classes/reporter.php';
require __DIR__ . '/classes/reporter/dispatcher.php';
require __DIR__ . '/classes/reporter/text.php';
require __DIR__ . '/classes/reporter/cli.php';
require __DIR__ . '/classes/reporter/mail.php';
require __DIR__ . '/classes/reporter/kbot.php';

require __DIR__ . '/classes/check.php';
require __DIR__ . '/classes/check/code_sniffer.php';
Expand Down

0 comments on commit 92ca135

Please sign in to comment.