This repository has no description
1.8 kB
69 lines
1{ config, lib, pkgs, ... }: let
2
3 format-github-message = pkgs.writeDashBin "format-github-message" ''
4 set -efu
5 export PATH=${lib.makeBinPath [
6 pkgs.jq
7 ]}
8 INPUT=$(jq -c .)
9 if $(printf '%s' "$INPUT" | jq 'has("issue") or has("pull_request")'); then
10 ${write_to_irc} "$(printf '%s' "$INPUT" | jq -r '
11 "\(.action): " +
12 "[\(.issue.title // .pull_request.title)] " +
13 "\(.comment.html_url // .issue.html_url // .pull_request.html_url) "
14 ')"
15 fi
16 '';
17
18 write_to_irc = pkgs.writeDash "write_to_irc" ''
19 ${pkgs.curl}/bin/curl -fsSv http://localhost:44001 \
20 -H content-type:application/json \
21 -d "$(${pkgs.jq}/bin/jq -n \
22 --arg text "$1" '{
23 command:"PRIVMSG",
24 params:["#fysi",$text]
25 }'
26 )"
27 '';
28
29in {
30 krebs.iptables.tables.filter.INPUT.rules = [
31 { predicate = "-p tcp --dport 44002"; target = "ACCEPT"; }
32 ];
33 krebs.reaktor2.fysiweb-github = {
34 hostname = "irc.libera.chat";
35 port = "6697";
36 useTLS = true;
37 nick = "fysiweb-github";
38 API.listen = "inet://127.0.0.1:44001";
39 plugins = [
40 {
41 plugin = "register";
42 config = {
43 channels = [
44 "#fysi"
45 ];
46 };
47 }
48 ];
49 };
50 krebs.htgen.fysiweb-github = {
51 port = 44002;
52 user = {
53 name = "reaktor2-fysiweb-github";
54 };
55 script = ''. ${pkgs.writeDash "github-irc" ''
56 set -xefu
57 case "$Method $Request_URI" in
58 "POST /")
59 payload=$(head -c "$req_content_length")
60 printf '%s' "$payload" | ${format-github-message}/bin/format-github-message
61 printf 'HTTP/1.1 200 OK\r\n'
62 printf 'Connection: close\r\n'
63 printf '\r\n'
64 exit
65 ;;
66 esac
67 ''}'';
68 };
69}