grim/bitshifter
Clone
Summary
Browse
Changes
Graph
initial revision, this has a bunch of hard coded stuff, but works
draft
2017-02-09, Gary Kramlich
adb49ff06e6e
initial revision, this has a bunch of hard coded stuff, but works
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
)