Skip to content

Instantly share code, notes, and snippets.

@stick
Created July 31, 2012 18:40
Show Gist options
  • Save stick/3219343 to your computer and use it in GitHub Desktop.
Save stick/3219343 to your computer and use it in GitHub Desktop.
modification of hook-reciever.py
#!/usr/bin/env python
'''
Takes a GitHub service hook POST and automatically updates the associated repo.
'''
__license__ = '''
Copyright 2009 Jake Wharton
hookpuller is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
hookpuller is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with hookpuller. If not, see
<http://www.gnu.org/licenses/>.
'''
import json
import subprocess
import sys
import urllib
#Associate branch names with repo locations on disk
repos = {
#'repository name': {
# 'branch name': 'path on disk',
# ...
#}
#...
'puppet-configs': {
'master': '/etc/puppet/',
}
}
#Read and load JSON from POST
data = json.loads(urllib.unquote(sys.stdin.read())[8:]) #8 = len('payload=')
#Get repo and branch that was committed to
repo = data['repository']['name']
branch = data['ref'][11:] #11 = len('refs/heads/')
if repo in repos and branch in repos[repo]:
#Execute pull in branch's associated directory
subprocess.call(['git', 'pull', 'origin', branch], cwd=repos[repo][branch])
subprocess.call(['/etc/puppet/repo-mx'], cwd=repos[repo][branch])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment