Skip to content

Instantly share code, notes, and snippets.

@grapeot
Created September 24, 2013 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grapeot/6692145 to your computer and use it in GitHub Desktop.
Save grapeot/6692145 to your computer and use it in GitHub Desktop.
A php script to send auto email notifications when a github repo is pushed. More details available at http://grapeot.me/automatic-email-notification-on-github-pushes.html.
<?
$r = 'This is an automatically generated message notifying you that someone pushed new commits to the github repo <project>.' . " Don't forget to do git pull before your editing.\r\n\r\nEdit summary: \r\n";
$payload = $_REQUEST['payload'];
preg_match_all('@"name":"([\w ]*?)","email@', $payload, $matches);
$authors = $matches[1];
preg_match_all('@"message":"([^"]*)"@', $payload, $matches);
$messages = $matches[1];
preg_match_all('@"url":"([^"]*)"@', $payload, $matches);
$links= $matches[1];
for ($i = 0; $i < count($messages) - 1; ++$i)
$r = $r . $authors[$i] . ' committed with message "' . $messages[$i] . '" at ' . $links[$i] . "\r\n";
mail('<receipts>', 'New commits pushed to <project>', $r, 'From: <email>' . "\r\n" . 'Reply-to: <email>' . "\r\n");
echo $r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment