Browse Source

Initial commit

master
Mark Vainomaa 3 years ago
commit
8e890341d9
No known key found for this signature in database GPG Key ID: 1B3F9523B542D315
  1. 3
      debug-attach.sh
  2. 25
      init-tmate.sh
  3. 14
      testserver.py
  4. 4
      vars.sh
  5. 21
      webhook-handler.py

3
debug-attach.sh

@ -0,0 +1,3 @@
#!/bin/bash
tmate -S /run/user/1000/aur-buildbot/tmate-sockets/tmate-0.sock attach-session

25
init-tmate.sh

@ -0,0 +1,25 @@
#!/bin/bash
source vars.sh
mkdir -p "${XDG_BUILDBOT_TMATE}"
CONFIG_FILE_LOC="$(mktemp --suffix="-aur-buildbot.conf")"
# Check if tmate sessions are empty
# TODO: implement concurrent builds
if [ -z "$(find "${XDG_BUILDBOT_TMATE}" -maxdepth 0 -empty -exec echo "1" ';')" ]; then
echo "Concurrent builds are not supported yet!"
exit 0
fi
# Write configuration file
cat > "${CONFIG_FILE_LOC}" <<EOF
set-option -g tmate-webhook-url "https://warp.mikroskeem.eu/aur_buildbot"
set-option -g tmate-webhook-userdata "some private data"
EOF
# Start up tmate
tmate -S "${XDG_BUILDBOT_TMATE}/tmate-0.sock" -f "${CONFIG_FILE_LOC}" new-session -d '/usr/bin/python3 webhook-handler.py /bin/bash -i'
# Remove configuration file
rm "${CONFIG_FILE_LOC}"

14
testserver.py

@ -0,0 +1,14 @@
#!/usr/bin/env python
import tornado.ioloop
import tornado.web
import pprint
class DumpingHandler(tornado.web.RequestHandler):
def post(self):
pprint.pprint(self.request)
pprint.pprint(self.request.body.decode())
if __name__ == "__main__":
tornado.web.Application([("/.*", DumpingHandler)]).listen(8080)
tornado.ioloop.IOLoop.instance().start()

4
vars.sh

@ -0,0 +1,4 @@
#!/bin/bash
export XDG_BUILDBOT="${XDG_RUNTIME_DIR}/aur-buildbot"
export XDG_BUILDBOT_TMATE="${XDG_RUNTIME_DIR}/aur-buildbot/tmate-sockets"

21
webhook-handler.py

@ -0,0 +1,21 @@
#!/usr/bin/env python
import json
import os
import sys
import time
import tornado.ioloop
import tornado.web
class WebHookHandler(tornado.web.RequestHandler):
def post(self):
data = json.loads(self.request.body.decode())
if data["type"] == "session_register":
print(data["params"]["stoken_ro"])
target = sys.argv[1:]
os.spawnlp(os.P_NOWAIT, target[0], target)
if __name__ == "__main__":
tornado.web.Application([("/aur_buildbot", WebHookHandler)]).listen(8080)
tornado.ioloop.IOLoop.instance().start()
time.sleep(5)
Loading…
Cancel
Save