prscript: update logic of sync with master test

Code now get master sha on github and check if it is in current
branch with a git command. It also sync first that the current
local branch is in sync with github corresponding branch.

Signed-off-by: Eric Leblond <eric@regit.org>
pull/1989/head
Eric Leblond 10 years ago committed by Victor Julien
parent 38f67d88ea
commit 50b33ad508

@ -30,6 +30,7 @@ import argparse
import sys import sys
import os import os
import copy import copy
from subprocess import Popen, PIPE
GOT_NOTIFY = True GOT_NOTIFY = True
try: try:
@ -118,15 +119,32 @@ def TestRepoSync(branch):
page = urllib2.urlopen(request) page = urllib2.urlopen(request)
json_result = json.loads(page.read()) json_result = json.loads(page.read())
sha_orig = json_result[0]["sha"] sha_orig = json_result[0]["sha"]
request = urllib2.Request(GITHUB_BASE_URI + username + "/" + args.repository + "/commits?sha=" + branch + "&per_page=100") check_command = ["git", "branch", "--contains", sha_orig ]
page = urllib2.urlopen(request) p1 = Popen(check_command, stdout=PIPE)
p2 = Popen(["grep", branch], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
if len(output) == 0:
return -1
return 0
def TestGithubSync(branch):
request = urllib2.Request(GITHUB_BASE_URI + username + "/" + args.repository + "/commits?sha=" + branch + "&per_page=1")
try:
page = urllib2.urlopen(request)
except urllib2.HTTPError, e:
if e.code == 404:
return -2
else:
raise(e)
json_result = json.loads(page.read()) json_result = json.loads(page.read())
found = -1 sha_github = json_result[0]["sha"]
for commit in json_result: check_command = ["git", "rev-parse", branch]
if commit["sha"] == sha_orig: p1 = Popen(check_command, stdout=PIPE)
found = 1 sha_local = p1.communicate()[0].rstrip()
break if sha_local != sha_github:
return found return -1
return 0
def OpenBuildbotSession(): def OpenBuildbotSession():
auth_params = { 'username':username,'passwd':password, 'name':'login'} auth_params = { 'username':username,'passwd':password, 'name':'login'}
@ -220,12 +238,23 @@ def WaitForBuildResult(builder, buildid, extension="", builder_name = None):
return res return res
# check that github branch and inliniac master branch are sync # check that github branch and inliniac master branch are sync
if not args.local and TestRepoSync(args.branch) == -1: if not args.local:
if args.norebase: ret = TestGithubSync(args.branch)
print "Branch " + args.branch + " is not in sync with inliniac's master branch. Continuing due to --norebase option." if ret != 0:
else: if ret == -2:
print "Branch " + args.branch + " is not in sync with inliniac's master branch. Rebase needed." print "Branch " + args.branch + " is not pushed to Github."
sys.exit(-1) sys.exit(-1)
if args.norebase:
print "Branch " + args.branch + " is not in sync with corresponding Github branch. Continuing due to --norebase option."
else:
print "Branch " + args.branch + " is not in sync with corresponding Github branch. Push may be needed."
sys.exit(-1)
if TestRepoSync(args.branch) != 0:
if args.norebase:
print "Branch " + args.branch + " is not in sync with inliniac's master branch. Continuing due to --norebase option."
else:
print "Branch " + args.branch + " is not in sync with inliniac's master branch. Rebase needed."
sys.exit(-1)
def CreateContainer(): def CreateContainer():
cli = Client() cli = Client()

Loading…
Cancel
Save