-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgithub-wiki-notify.php
More file actions
executable file
·61 lines (55 loc) · 1.54 KB
/
github-wiki-notify.php
File metadata and controls
executable file
·61 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env php
<?php
/**
* Poll updates to a Github wiki and send notifications about updates.
*
* Usage is simple, just cron it:
*
* github-wiki-notify.php --path=/path/to/repo --email=list@example.com --subject="Wiki updated!"
*
* @author Anthony Bush
* @version 1.0.1
* @copyright Anthony Bush, 20 December, 2011
* @license <http://www.opensource.org/licenses/bsd-license.php>
* @package default
**/
/**
* Define DocBlock
**/
$path = null;
$email = null;
$subject = null;
foreach ($argv as $arg)
{
if (preg_match('/--path=(.*)/', $arg, $match)) {
$path = $match[1];
} else if (preg_match('/--email=(.*)/', $arg, $match)) {
$email = $match[1];
} else if (preg_match('/--subject=(.*)/', $arg, $match)) {
$subject = $match[1];
}
}
if (is_null($path) || is_null($email))
{
echo("Usage:\n");
echo(" " . basename(__FILE__) . " --path=/path/to/repo --email=list@example.com\n");
exit(1);
}
if (!chdir($path)) {
echo("Path does not exist: " . $path . "\n");
exit(2);
}
$pullResult = `git pull 2>&1`;
if (preg_match('/From github\.com:(.*)\n\s*([^\s]+)/', $pullResult, $match))
{
$repo = $match[1];
$revs = $match[2];
$wikiDiffUrl = 'https://github.com/' . str_replace('.wiki', '/wiki', $repo) . '/_compare/' . $revs;
$changeLog = `git log --pretty=format:'%h - %s (%cr) <%an>' $revs`;
if (is_null($subject)) {
$subject = '[SCM]: ' . $repo . ' was updated';
}
$body = "To see the changes, visit:\n" . $wikiDiffUrl . "\n\nChangelog:\n" . $changeLog . "\n";
mail($email, $subject, $body, "From: $email");
}
// else no updates