HowTo keep Redmine in sync with Github without dedicated plugin (Apache CGI + Github Webhook) » History » Revision 2
Revision 1 (crypto gopher, 2018-09-17 14:49) → Revision 2/10 (crypto gopher, 2018-09-17 14:56)
h1. HowTo keep Redmine in sync with Github without dedicated plugin (Apache CGI + Github Webhook)
This is a solution in case you don't want to install additional plugins just to keep repository synchronised. It requires you to have Apache webserver with access to repository you are trying to sync. Apache has to support running CGI scripts.
h2. Prepare CGI script
Any script you run on your server will do. Below is an example of Bash script that pulls git repository and notifies Redmine to fetch changesets:
<pre>
#!/bin/sh
/usr/bin/git -C /var/lib/redmine/tv/repo/token_voting pull -n -q
result1=$?
/usr/bin/curl --max-time 60 -s 'https://tv.michalczyk.pro/sys/fetch_changesets?id=token-voting&key=2GkhmLmtTjKoXYf6PS9y' >/dev/null
result2=$?
if [[ $result1 && $result2 ]]; then
echo "Status: 200 OK"
else
echo "Status: 500 Internal Server Error"
fi
echo "Content-Type: text/plain; charset=utf-8"
echo
if [[ $result1 ]]; then
echo "git pull: ok"
else
echo "git pull: failed"
fi
if [[ $result2 ]]; then
echo "fetch changesets: ok"
else
echo "fetch changesets: failed"
fi
</pre>
Let's say you save this script under: _/var/www/localhost/cgi-bin/update-repo.cgi_
h2. Configure Apache to run script whenever particular URL is requested
Inside @VirtualHost@ of your choice just add:
<pre>
...
# Github webhook for repository pull/update
ScriptAlias /update-repo.cgi /var/www/localhost/cgi-bin/update-repo.cgi
<Directory /var/www/localhost/cgi-bin/>
Options ExecCGI
AllowOverride None
Require all granted
</Directory>
...
</pre>
In case you use the same @VirtualHost@ to proxy requests to your Redmine @rails server@, you should exclude your special URL from being proxied with:
<pre>
ProxyPass /update-repo.cgi !
</pre>
h2.