Permalink
Browse files

Merge branch 'master' of git://github.com/parente/handlerbag

  • Loading branch information...
2 parents aa9e2b6 + 0afe04c commit af4570ab6903f900db2a9896605d4db8e428b8fc @parente committed Mar 12, 2011
Showing with 22 additions and 10 deletions.
  1. +1 −0 handlerbag.py
  2. +21 −10 hbag/githubpull.py
View
@@ -219,6 +219,7 @@ def set_handler_status(self, name, enable, opts=None):
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
ioloop = tornado.ioloop.IOLoop.instance()
+ logging.info('started on port: %d', options.port)
try:
ioloop.start()
finally:
View
@@ -12,7 +12,7 @@ class GitHubPullHandler(tornado.web.RequestHandler):
def initialize(self, **options):
self.options = options
- def post(self):
+ def post(self, branch):
# translate the json payload sent by github
payload = json.loads(self.get_argument('payload'))
# get the repository info
@@ -21,42 +21,53 @@ def post(self):
url = repo['url'].replace('https', 'git')+'.git'
# get the name of the project
name = repo['name']
+ branch = branch if branch else 'master'
- path = self.options['projects_path']
+ projectsPath = self.options['projects_path']
+ clonePath = os.path.join(projectsPath, name)
git = self.options['git_cmd']
- if not os.path.exists(os.path.join(path, repo['name'])):
+ if not os.path.exists(clonePath):
# we only clone if it is one of ours
m = re.search(self.options['required_url_regex'], url)
if not m or m.start() != 0:
logging.warning('git clone rejected: %s', url)
return
- r = subprocess.call([git, 'clone', url], cwd=path)
+ r = subprocess.call([git, 'clone', url], cwd=projectsPath)
if r:
- logging.warning('git clone failed: %s')
+ logging.warning('git clone failed: %s', url)
else:
logging.info('git clone complete: %s', url)
+ r = subprocess.call([git, 'checkout', branch], cwd=clonePath)
+ if r:
+ logging.warning('git checkout failed: %s', branch)
+ else:
+ logging.info('git checkout complete: %s', branch)
else:
- d = os.path.join(path, name)
m = re.search(self.options['required_url_regex'], url)
if not m or m.start() != 0:
# we'll pull even if it isn't ours if we've already cloned
info = subprocess.Popen([git, 'remote', '-v'],
stdout=subprocess.PIPE,
- cwd=d).communicate()[0]
+ cwd=clonePath).communicate()[0]
if url not in info:
logging.warning('git pull rejected: %s', url)
return
segs = payload['ref'].split('/')
- branch = segs[-1]
- r = subprocess.call([git, 'pull', 'origin', branch], cwd=d)
+ pullBranch = segs[-1]
+ r = subprocess.call([git, 'pull', 'origin', pullBranch], cwd=clonePath)
if r:
logging.warning('git pull failed: %s', url)
else:
logging.info('git pull complete: %s', url)
+ r = subprocess.call([git, 'checkout', branch], cwd=clonePath)
+ if r:
+ logging.warning('git checkout failed: %s', branch)
+ else:
+ logging.info('git checkout complete: %s', branch)
def get_handler_map(app, webroot, options):
- return [(webroot+'githubpull.*', GitHubPullHandler, options)]
+ return [(webroot+'githubpull/?(.*)$', GitHubPullHandler, options)]
def get_default_options(app):
return {

0 comments on commit af4570a

Please sign in to comment.