From 9de315f09ca3ce17138d6296de240b119880753b Mon Sep 17 00:00:00 2001 From: Ilya Sergey Date: Mon, 6 Mar 2017 14:15:54 +0000 Subject: [PATCH 1/4] added from-field --- github-wiki-notify.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/github-wiki-notify.php b/github-wiki-notify.php index 3aaa581..e8d3ea3 100755 --- a/github-wiki-notify.php +++ b/github-wiki-notify.php @@ -21,6 +21,7 @@ $path = null; $email = null; $subject = null; +$from = null; foreach ($argv as $arg) { if (preg_match('/--path=(.*)/', $arg, $match)) { @@ -29,13 +30,15 @@ $email = $match[1]; } else if (preg_match('/--subject=(.*)/', $arg, $match)) { $subject = $match[1]; + } else if (preg_match('/--from=(.*)/', $arg, $match)) { + $subject = $match[1]; } } -if (is_null($path) || is_null($email)) +if (is_null($path) || is_null($email) || is_null($from)) { echo("Usage:\n"); - echo(" " . basename(__FILE__) . " --path=/path/to/repo --email=list@example.com\n"); + echo(" " . basename(__FILE__) . " --path=/path/to/repo --email=list@example.com --from=my@email.com\n"); exit(1); } @@ -56,6 +59,6 @@ $subject = '[SCM]: ' . $repo . ' was updated'; } $body = "To see the changes, visit:\n" . $wikiDiffUrl . "\n\nChangelog:\n" . $changeLog . "\n"; - mail($email, $subject, $body, "From: $email"); + mail($email, $subject, $body, "From: $from"); } // else no updates From 88bbc0411f24a790e09f1b4d083d21dde5add9a7 Mon Sep 17 00:00:00 2001 From: Ilya Sergey Date: Mon, 6 Mar 2017 14:16:57 +0000 Subject: [PATCH 2/4] changelog update --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c365d..4b37e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +v1.0.2 / 2017-03-06: + +- Added the "from" key + v1.0.1 / 2012-01-31: - Remove branch tags from log output (not that useful in github's wiki context) From fd26a44fd706a163b3d14420d33d29a9da541665 Mon Sep 17 00:00:00 2001 From: Ilya Sergey Date: Mon, 6 Mar 2017 14:20:27 +0000 Subject: [PATCH 3/4] fixes --- github-wiki-notify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-wiki-notify.php b/github-wiki-notify.php index e8d3ea3..bac1d41 100755 --- a/github-wiki-notify.php +++ b/github-wiki-notify.php @@ -31,7 +31,7 @@ } else if (preg_match('/--subject=(.*)/', $arg, $match)) { $subject = $match[1]; } else if (preg_match('/--from=(.*)/', $arg, $match)) { - $subject = $match[1]; + $from = $match[1]; } } From c7e6d3fa7f783dbef289d63723fcb5b149cfd8ff Mon Sep 17 00:00:00 2001 From: Armin Stebich Date: Sat, 29 Jan 2022 15:23:02 +0100 Subject: [PATCH 4/4] update regex pattern for new GitHub output --- CHANGELOG.md | 7 +++++++ README.md | 2 +- github-wiki-notify.php | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b37e44..615f025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +v1.0.3 / 2022-01-29: + +- GitHub output has changed, therefor regex syntax has to be corrected + + Request repo link from git remote, it is no longer in pullResult + + pullResult answer is now 'Updating FROMSHA..TO__SHA' + + also pullResult answer is localized! + v1.0.2 / 2017-03-06: - Added the "from" key diff --git a/README.md b/README.md index 28fb005..0d2dc99 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Get a checkout of your Github repo: Then create a cron (e.g. `crontab -e`): - */15 * * * * github-wiki-notify.php --path="/some/path/repo.wiki" --email="list@example.com" --subject="Wiki updated!" + */15 * * * * github-wiki-notify.php --path="/some/path/repo.wiki" --email="list@example.com" --subject="Wiki updated!" --from="from@example.org" Problems? Want to contribute? ----------------------------- diff --git a/github-wiki-notify.php b/github-wiki-notify.php index bac1d41..ca4ea8f 100755 --- a/github-wiki-notify.php +++ b/github-wiki-notify.php @@ -47,12 +47,19 @@ exit(2); } +// request repo-URL from git remote +$remote = `git remote -v`; +$repo = 'unknown'; +if (preg_match('/origin\s*(\S*)\s*\(fetch\)\n/', $remote, $match)) +{ + $repo = $match[1]; +} + $pullResult = `git pull 2>&1`; -if (preg_match('/From github\.com:(.*)\n\s*([^\s]+)/', $pullResult, $match)) +if (preg_match('/^\S* ([a-z0-9]{7}\.\.[a-z0-9]{7})\n/', $pullResult, $match)) { - $repo = $match[1]; - $revs = $match[2]; - $wikiDiffUrl = 'https://github.com/' . str_replace('.wiki', '/wiki', $repo) . '/_compare/' . $revs; + $revs = $match[1]; + $wikiDiffUrl = str_replace('.wiki.git', '/wiki', $repo) . '/_compare/' . $revs; $changeLog = `git log --pretty=format:'%h - %s (%cr) <%an>' $revs`; if (is_null($subject)) { @@ -62,3 +69,4 @@ mail($email, $subject, $body, "From: $from"); } // else no updates +