HowTo keep Redmine in sync with Github without dedicated plugin (Apache CGI + Github Webhook) » History » Version 2
crypto gopher, 2018-09-17 14:56
1 | 1 | crypto gopher | h1. HowTo keep Redmine in sync with Github without dedicated plugin (Apache CGI + Github Webhook) |
---|---|---|---|
2 | |||
3 | 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. |
||
4 | |||
5 | h2. Prepare CGI script |
||
6 | |||
7 | 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: |
||
8 | <pre> |
||
9 | #!/bin/sh |
||
10 | /usr/bin/git -C /var/lib/redmine/tv/repo/token_voting pull -n -q |
||
11 | result1=$? |
||
12 | |||
13 | /usr/bin/curl --max-time 60 -s 'https://tv.michalczyk.pro/sys/fetch_changesets?id=token-voting&key=2GkhmLmtTjKoXYf6PS9y' >/dev/null |
||
14 | result2=$? |
||
15 | |||
16 | if [[ $result1 && $result2 ]]; then |
||
17 | echo "Status: 200 OK" |
||
18 | else |
||
19 | echo "Status: 500 Internal Server Error" |
||
20 | fi |
||
21 | |||
22 | echo "Content-Type: text/plain; charset=utf-8" |
||
23 | echo |
||
24 | |||
25 | if [[ $result1 ]]; then |
||
26 | echo "git pull: ok" |
||
27 | else |
||
28 | echo "git pull: failed" |
||
29 | fi |
||
30 | |||
31 | if [[ $result2 ]]; then |
||
32 | echo "fetch changesets: ok" |
||
33 | else |
||
34 | echo "fetch changesets: failed" |
||
35 | fi |
||
36 | </pre> |
||
37 | |||
38 | Let's say you save this script under: _/var/www/localhost/cgi-bin/update-repo.cgi_ |
||
39 | |||
40 | 2 | crypto gopher | h2. Configure Apache to run script whenever particular URL is requested |
41 | |||
42 | Inside @VirtualHost@ of your choice just add: |
||
43 | <pre> |
||
44 | ... |
||
45 | # Github webhook for repository pull/update |
||
46 | ScriptAlias /update-repo.cgi /var/www/localhost/cgi-bin/update-repo.cgi |
||
47 | <Directory /var/www/localhost/cgi-bin/> |
||
48 | Options ExecCGI |
||
49 | AllowOverride None |
||
50 | Require all granted |
||
51 | </Directory> |
||
52 | ... |
||
53 | </pre> |
||
54 | |||
55 | 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: |
||
56 | <pre> |
||
57 | ProxyPass /update-repo.cgi ! |
||
58 | </pre> |
||
59 | |||
60 | 1 | crypto gopher | h2. |