Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mightybyte/811549 to your computer and use it in GitHub Desktop.
Save mightybyte/811549 to your computer and use it in GitHub Desktop.
FLASK:
#!/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)
PYRAMID:
#!/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]))
YESOD:
#!/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}
HAPPSTACK:
#!/usr/bin/env runhaskell
2 -- A github post-receive hook handler, runs some shell command on each HTTP POST to PORT. $
3-- github-listener.hs PORT 'SOME SHELL COMMAND' $
4
5import Control.Monad.Trans (liftIO)
6import System.Environment (getArgs)
7import System.Process (system)
8import Happstack.Server
9
10post cmd = do
11 methodM POST
12 liftIO $ do putStrLn $ "Received POST, running: " ++ cmd
13 system cmd
14 ok "ok"
15
16main = do
17 port:cmd:_ ← getArgs
18 simpleHTTP nullConf {port=read port} (post cmd)
SINATRA:
#!/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
cmd = ARGV[1]
print "Received POST, running: "+cmd
puts `#{cmd}`
"ok"
end
Snap:
import Control.Monad.Trans
import Snap.Types
import Snap.Http.Server
import System.Environment (getArgs)
import System.Process (system)
main = do
cmd:_ <- getArgs
let handler = do
liftIO $ do
putStrLn $ "Received POST, running: " ++ cmd
system cmd
return ()
quickHttpServe handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment