Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Branch support in githubpull handler

  • Loading branch information...
commit 44ffcbb58ef99fe4795e2aead42bb63bdb96e082 1 parent c776675
@parente authored
Showing with 21 additions and 10 deletions.
  1. +21 −10 hbag/githubpull.py
View
31 hbag/githubpull.py
@@ -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 {
Please sign in to comment.
Something went wrong with that request. Please try again.