|
| 1 | +import paho.mqtt.publish as publish |
| 2 | +import time |
| 3 | + |
| 4 | +AIO_USERNAME = 'YOURUSERNAMEHERE' |
| 5 | +AIO_KEY = 'YOURKEYHERE' |
| 6 | + |
| 7 | +AIO_TOPIC = AIO_USERNAME + '/feeds/redlight' |
| 8 | +AIO_YELLOWTOPIC = AIO_USERNAME + '/feeds/yellowlight' |
| 9 | +AIO_GREENTOPIC = AIO_USERNAME + '/feeds/greenlight' |
| 10 | + |
| 11 | +def webhook_handler(event, context): |
| 12 | + print('Starting webhook handler!') |
| 13 | + action = event.get('action') |
| 14 | + print('Issue action: {0}'.format(action)) |
| 15 | + auth = {'username': AIO_USERNAME, 'password': AIO_KEY} |
| 16 | + |
| 17 | + # for issues opened & closed |
| 18 | + if action == 'closed': |
| 19 | + publish.single(AIO_TOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth) |
| 20 | + elif action in ('opened', 'reopened'): |
| 21 | + publish.single(AIO_TOPIC, payload='ON', hostname='io.adafruit.com', auth=auth) |
| 22 | + # starring & watching |
| 23 | + elif action == 'started': |
| 24 | + publish.single(AIO_YELLOWTOPIC, payload='ON', hostname='io.adafruit.com', auth=auth) |
| 25 | + time.sleep(1) |
| 26 | + publish.single(AIO_YELLOWTOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth) |
| 27 | + # look for pushes |
| 28 | + elif "commits" in event: |
| 29 | + publish.single(AIO_GREENTOPIC, payload='ON', hostname='io.adafruit.com', auth=auth) |
| 30 | + time.sleep(1) |
| 31 | + publish.single(AIO_GREENTOPIC, payload='OFF', hostname='io.adafruit.com', auth=auth) |
| 32 | + |
| 33 | + return 'OK' |
| 34 | + |
| 35 | + |
| 36 | +if __name__ == '__main__': |
| 37 | + webhook_handler({'action': 'started'}, {}) |
0 commit comments