Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marks/811353 to your computer and use it in GitHub Desktop.
Save marks/811353 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# A github post-receive hook handler, runs some shell command on each HTTP POST to PORT.
# github-listener.py PORT 'SOME SHELL COMMAND'
import sys
from subprocess import *
from flask import Flask
def system(cmd):
print ''.join(Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True).communicate())
app = Flask(__name__)
@app.route("/", methods=['POST'])
def post():
cmd = sys.argv[2]
print "Received POST, running: "+cmd
system(cmd)
return 'ok'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=int(sys.argv[1]), debug=True)
#!/usr/bin/env python
# A github post-receive hook handler, runs some shell command on each HTTP POST to PORT.
# github-listener.py PORT 'SOME SHELL COMMAND'
import sys
from subprocess import *
from paste.httpserver import serve
from pyramid.config import Configurator
from pyramid.response import Response
def system(cmd):
print ''.join(Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True).communicate())
def post(request):
cmd = sys.argv[2]
print "Received POST, running: "+cmd
system(cmd)
return Response('ok')
if __name__ == '__main__':
config = Configurator()
config.add_view(post)
app = config.make_wsgi_app()
serve(app, host='0.0.0.0',port=int(sys.argv[1]))
#!/usr/bin/env runhaskell
{-# LANGUAGE TypeFamilies, QuasiQuotes #-}
-- A github post-receive hook handler, runs some shell command on each HTTP POST to PORT.
-- github-listener.hs PORT 'SOME SHELL COMMAND'
import System.Environment (getArgs)
import System.Process (system)
import Yesod
data App = App {cmd∷String}
mkYesod "App" [$parseRoutes|
/ Home POST
|]
instance Yesod App where approot _ = ""
postHome = do
app ← getYesod
liftIO $ do
putStrLn $ "Received POST, running: " ++ cmd app
system $ cmd app
defaultLayout [$hamlet|ok|]
main = do
port:cmd:_ ← getArgs
basicHandler (read port) App{cmd=cmd}
#!/usr/bin/env ruby
# A github post-receive hook handler, runs some shell command on each HTTP POST to PORT.
# github-listener.rb PORT 'SOME SHELL COMMAND'
%w{rubygems sinatra}.each{|x| require x}
set :port, ARGV[0]
post '/' do
print "Received POST, running: #{ARGV[1]}"
puts `#{ARGV[1]}`
"ok"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment