Categories
WebOps

How to display git commits on DokuWiki page

Let’s display git commits using DokuWiki on your own project workspace or personal wiki.

Create a system user that can access git repositories and wiki pages.

$ sudo useradd -s /usr/sbin/nologin -G "git,www-data" -r wiki-git-bridge

Create external namespace for DokuWiki installed in /opt/wiki/ directory.

$ sudo mkdir /opt/wiki/data/pages/external

Change the owner and group from root to www-data.

$ sudo chown www-data:www-data /opt/wiki/data/pages/external

Add write access for the assigned group.

$ sudo chmod g+w /opt/wiki/data/pages/external

Create /opt/sbin/wiki_blog_log.sh shell script to generate commits for /opt/repositories/blog.git git repository and store it using /opt/wiki/data/pages/external/git_blog_log.txt wiki page file.

#!/bin/bash
# display recent repository changes using dokuwiki syntax

# number of recent changes
n_changes=5

# git repository
git_repository="/opt/repositories/blog.git/"

# output directory and filename
output_dir="/opt/wiki/data/pages/external"
output_file="git_blog_log.txt"
output="${output_dir}/${output_file}"

# header title
header_title="Recent changes"

echo "==== ${header_title} ====" | tee $output >/dev/null
git --git-dir="${git_repository}" log --max-count="${n_changes}" --date=short --pretty=format:"  * **%h** **%ad** \\\\  //%s//" | tee -a $output >/dev/null

Verify that the created shell script is running without any problems.

$ sudo -u wiki-git-bridge  /opt/sbin/wiki_blog_log.sh

Create cron job to schedule script execution.

$ cat << EOF | sudo tee /etc/cron.d/wiki_blog_log
MAILTO=root
# Generate recent repository changes page
15 */3 * * * wiki-git-bridge [ -x /opt/sbin/wiki_blog_log.sh ] && /opt/sbin/wiki_blog_log.sh
EOF

tmux

Use include plugin to embed the generated page.

{{page>external:git_blog_log&inline&nofooter&noeditbutton}}