Skip to content

Commit

Permalink
More tidying up. Wrote the README file, expanded upon some other read…
Browse files Browse the repository at this point in the history
…me files, got rid of some deprecated and confusing functions.
  • Loading branch information
Sam Rose committed Jan 8, 2011
1 parent 9f89dc2 commit 26f2283
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 26 deletions.
35 changes: 35 additions & 0 deletions README
@@ -0,0 +1,35 @@
# Git Pull Request Email Bot

## What is this?

The Git Pull Request Email Bot is a simple project that sends emails to a
specified address every time a repository of your choice gets a pull request.

It works by adding the run.php file to a Cron job and running it fairly often
(though it doesn't really matter how long you leave it, it remembers what
pull request it emailed you about last and won't email duplicates).

It was written originally written for the [[ThinkUp|http://thinkupapp.com]]
project to post pull requests to the mailing list and promote code review.

## How does it work?

There are only a few files that you as a user need to worry about:

config.inc.php - This is where all of the configuration information is stored.
You will need to change this file to make it suit your purpose.

run.php - This is the file you will need to attach to a Cron job. This file is
where the magic happens: pull requests are crawled, the crawler filters out the
ones it has already emailed you about and sends emails about for the new ones.

Template files - All of the template files are stored in the templates/
directory. These handle the presentation of the emails through a placeholder
system. Details of this can be found in templates/template_readme.txt.

## Can I contribute?

Uhm... yeah, sure, I don't see why not. I haven't really prepared the project
for contributions just yet but if you want to browse the code and you see
something you think you could improve then go for it! Fork it, branch it,
pull it :)
17 changes: 2 additions & 15 deletions classes/class.Config.php
Expand Up @@ -2,6 +2,8 @@
/** /**
* Static class to return the config array. * Static class to return the config array.
* *
* Draws its information from config.inc.php
*
* @author Sam Rose * @author Sam Rose
*/ */
class Config { class Config {
Expand Down Expand Up @@ -31,20 +33,5 @@ public static function getInstance($new = false) {
//Return the $config class variable //Return the $config class variable
return self::$config; return self::$config;
} }

/**
* Returns the table name for a table of your choice concatenated with the
* prefix.
*
* Options for the $table argument:
*
* 'requests' - the pull requests table
* 'users' - the users table
*
* @return String $table
*/
public static function getTableName($table) {
return PullRequestDatabase::getTableName($table);
}
} }
?> ?>
13 changes: 7 additions & 6 deletions classes/class.Email.php
Expand Up @@ -7,20 +7,21 @@
* @author Sam Rose * @author Sam Rose
*/ */
class Email { class Email {
/**
*
*
* @param String $content
*/
public static function send($content) { public static function send($content) {
$config = Config::getInstance(); $config = Config::getInstance();


// properly handle an array of email addresses
if (is_array($config['email_to'])) { if (is_array($config['email_to'])) {
foreach($config['email_to'] as $to) { foreach($config['email_to'] as $to) {
self::send_mail($to, $content); self::send_mail($to, $content);
} }
} else { } else {
if (self::send_mail($config['email_to'], $content)) { self::send_mail($config['email_to'], $content);
echo "woot";
}
else {
echo "not woot";
}
} }
} }


Expand Down
14 changes: 9 additions & 5 deletions classes/class.PullRequestFetcher.php
@@ -1,16 +1,20 @@
<?php <?php
require_once 'class.WebPage.php';
require_once 'class.Config.php';
/** /**
* Class to fetch pull request data from a repository. * Class to fetch pull request data from a repository.
* *
* @author Sam Rose * @author Sam Rose
*/ */

require_once 'class.WebPage.php';
require_once 'class.Config.php';

class PullRequestFetcher { class PullRequestFetcher {


private $last_pull_file_name = 'last_pull.txt'; /**
* The location of the file that contains the number of the last pull
* request emailed about.
*
* @var String $last_pull_file_name
*/
private $last_pull_file_name = 'data/last_pull.txt';


/** /**
* An associative array of pull requests. * An associative array of pull requests.
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/impromptu_tests.php
@@ -1,4 +1,9 @@
<?php <?php
/*
* This file is entirely for just small bits of code that I want to test on
* the fly.
*/

require_once '../classes/class.PullRequestFetcher.php'; require_once '../classes/class.PullRequestFetcher.php';


$fetcher = new PullRequestFetcher(); $fetcher = new PullRequestFetcher();
Expand Down
2 changes: 2 additions & 0 deletions tests/tests_readme.txt
@@ -0,0 +1,2 @@
I have no testing framework set up as of yet but I do intend to get some Unit
tests up and running relatively soon, don't worry! :)

0 comments on commit 26f2283

Please sign in to comment.