Bitbucket hoot for Dokuwiki
When we started to actualise our company documentations then I made a quick DokuWiki. It's awesome and I like it. I would like to display the latest commits on the "start" page of projects. So here is my Bitbucket hook:
<?php
/*
* Filename: git-hook.php
* Author: Balazs Nadasdi <yitsushi@gmail.com>
*/
define('DEST', 'data/pages/code/git-hook/');
$payload = json_decode($_POST['payload']);
if (!empty($payload->commits)) {
$projectSlug = $payload->repository->slug;
$projectOwner = $payload->repository->owner;
define('PROJECTFILE', $projectOwner . "-" . $projectSlug);
foreach ($payload->commits as $commit) {
$branch = $commit->branch;
$rawAuthor = $commit->raw_author;
$date = $commit->timestamp;
$message = $commit->message;
$node = $commit->node;
$rawNode = $commit->raw_node;
if ($branch === 'master' || isset($commit->branches) && in_array('master', $commit->branches)) {
$original = file_get_contents(DEST . PROJECTFILE . "-commits.txt");
$content = "=== [" . $date . "] " . $rawAuthor . " ===\n";
$content .= "\n";
$content .= " " . preg_replace("/\n/", "\n ", $message) . "\n";
$content .= "\n";
$content .= "**Commit:** [[https://bitbucket.org/" . $projectOwner . "/" . $projectSlug . "/commits/" . $rawNode . "|" . $node . "]]\n\n";
$content .= $original;
file_put_contents(DEST . PROJECTFILE . "-commits.txt", $content);
}
}
}
Add a POST hook to "http://my.wiki.page/git-hook.php". Now it saves the changes under DEST
. With the simple include plugin we can include our changes with {{page>..:git-hook:OWNER-PROJECTSLUG}}
.
Written by Balazs Nadasdi
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#