How to display git commits on DokuWiki page

Lets display git commits using DokuWiki on your own project workspace or personal wiki.

Create 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 owner and group from root to www-data.

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

Add write access for 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 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 generated page.

{{page>external:git_blog_log&inline&nofooter&noeditbutton}}
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu