irc-bot.mdwn 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. There is an IRC commit bot (the software is KGB), which reports commits made
  2. into Git repositories (currently the [[!rel4git wiki]] repo, i.e. this website)
  3. to IRC channels (currently `#rel4tion`). The bot's nickname is `rel4bot`.
  4. # Intro
  5. KGB has a server component which listens to requests and sends messages to IRC
  6. channels accordingly. There is also a client command, meant to be run from a
  7. Git hook, which contacts the server to send requests.
  8. I'd prefer to try doing this in Haskell, because it's a chance to learn more in
  9. Haskell and customize the bot, but after examining my options I decided to
  10. leave this for later (I have enough open projects). KGB comes as a package in
  11. Debian-based distros, so it's quick and easy to set up.
  12. I'll hopefully do some hacking with Haskell IRC-related packages in the future.
  13. # Server
  14. The KGB server daemon has a config file under `/etc/`. New IRC channels need to
  15. be added to it (or to other config files it `include`s). For example, this is
  16. for `#rel4tion`:
  17. [[!format yaml """
  18. repositories:
  19. wiki:
  20. password: verysecret
  21. channels:
  22. - name: '#rel4tion'
  23. network: freenode
  24. repos:
  25. - wiki
  26. """]]
  27. # Client
  28. In the gitolite conf file, specify `notify-irc` as a post-receive hook. For
  29. example:
  30. repo wiki
  31. RW+ = fr33domlover
  32. RW = ikiwiki
  33. R = daemon
  34. config gitweb.description = "Research, design, development, documents"
  35. option hook.post-receive = ping-ikiwiki notify-irc
  36. The hook script looks like this (the GNOME sysadmin team wiki pages helped):
  37. [[!format sh """
  38. #!/bin/sh
  39. # send notification to IRC channel
  40. REPOSITORY_ID=$(basename "$PWD")
  41. REPOSITORY_ID=${REPOSITORY_ID%.git}
  42. kgb-client --conf /var/lib/gitolite3/kgb-client-${REPOSITORY_ID}.conf --repository git > /dev/null 2>&1
  43. """]]
  44. Create a client config file and place it under the gitolite user's home
  45. directory. The name should as specified in the script above. For example,
  46. `kgb-config-wiki.conf` looks like this:
  47. [[!format yaml """
  48. ---
  49. repo-id: wiki
  50. servers:
  51. - uri: http://localhost:5391/
  52. timeout: 5
  53. password: verysecret
  54. status-dir: /var/cache/kgb/client-status
  55. web-link: http://git.rel4tion.org/?p=${module}.git;a=commitdiff;h=${commit}
  56. """]]