grim/bitshifter

adb49ff06e6e
Parents
Children 87ac5b752969
initial revision, this has a bunch of hard coded stuff, but works
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Thu Feb 09 15:18:22 2017 -0600
@@ -0,0 +1,3 @@
+syntax: regexp
+venv\/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Dockerfile Thu Feb 09 15:18:22 2017 -0600
@@ -0,0 +1,20 @@
+FROM alpine:latest
+
+RUN apk add --update \
+ mercurial git \
+ python py-pip \
+ openssh-client \
+ && \
+ rm -f /var/cache/apk/*
+
+RUN mkdir -p /usr/src/app
+WORKDIR /usr/src/app
+
+EXPOSE 11101
+
+COPY requirements.txt /usr/src/app/
+RUN pip install --no-cache-dir -r requirements.txt
+
+COPY . /usr/src/app
+
+CMD python bitshifter.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bitshifter.py Thu Feb 09 15:18:22 2017 -0600
@@ -0,0 +1,58 @@
+import logging
+import subprocess
+
+from flask import Flask, request, make_response
+
+
+logging.getLogger().setLevel(logging.NOTSET)
+
+
+app = Flask(__name__)
+
+
+@app.route('/hooked', methods=['POST'])
+def hooked():
+ data = request.get_json()
+
+ if 'repository' in data:
+ repo = data.get('repository')
+
+ if repo.get('scm') == 'hg' and repo.get('full_name') == 'pidgin/main':
+ try:
+ cmd1 = 'hg pull --cwd pidgin bitbucket'
+ print 'running: {}'.format(cmd1)
+ out1 = subprocess.check_output(cmd1.split())
+ print out1
+ except Exception as exp:
+ logging.exception(exp)
+ return make_response((exp, 500))
+
+ try:
+ cmd2 = 'hg push --cwd pidgin --new-branch pidgin.im'
+ print 'running: {}'.format(cmd2)
+ out2 = subprocess.check_output(cmd2.split())
+ print out2
+
+ output = out1 + out2
+
+ return make_response((output, 200,))
+ except subprocess.CalledProcessError as exp:
+ if exp.returncode == 1:
+ print exp.output
+
+ output = out1 + exp.output
+
+ return make_response((output, 200,))
+
+ logging.exception(exp)
+ return make_response((exp, 500))
+ except Exception as exp:
+ logging.exception(exp)
+ return make_response((exp, 500))
+
+
+ return make_response(('bad request', 400))
+
+
+if __name__ == '__main__':
+ app.run(host='0.0.0.0', port=11101, debug=False)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docker-compose.yml Thu Feb 09 15:18:22 2017 -0600
@@ -0,0 +1,4 @@
+bitshifter:
+ build: .
+ ports:
+ - "11101:11101"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/requirements.txt Thu Feb 09 15:18:22 2017 -0600
@@ -0,0 +1,1 @@
+Flask==0.10.1