]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
prscript: check if branch is synced with master
authorEric Leblond <eric@regit.org>
Fri, 6 Sep 2013 12:21:58 +0000 (14:21 +0200)
committerEric Leblond <eric@regit.org>
Fri, 6 Sep 2013 13:40:36 +0000 (15:40 +0200)
The script now check if the tested branch is in sync with current
inliniac's master.

qa/prscript.py

index b0c1d2cdaa9ad7d29ab3abb552b04c3aaf74cbd4..7eb35cad0511b7237ec7911ee62c675e326457c8 100755 (executable)
@@ -27,15 +27,36 @@ BASE_URI="https://buildbot.suricata-ids.org/"
 BUILDERS_URI=BASE_URI+"builders/"
 JSON_BUILDERS_URI=BASE_URI+"json/builders/"
 
+GITHUB_BASE_URI = "https://api.github.com/repos/"
+GITHUB_MASTER_URI = "https://api.github.com/repos/inliniac/suricata/commits?sha=master"
+
 parser = argparse.ArgumentParser(prog='prscript', description='Script checking validity of branch before PR')
 parser.add_argument('-u', '--username', dest='username', help='github and buildbot user')
 parser.add_argument('-p', '--password', dest='password', help='buildbot password')
 parser.add_argument('-c', '--check', action='store_const', const=True, help='only check last build', default=False)
+parser.add_argument('-r', '--repository', dest='repository', default='suricata', help='suricata repository on github')
 parser.add_argument('branch', metavar='branch', help='github branch to build')
 args = parser.parse_args()
 username = args.username
 password = args.password
 
+def TestRepoSync(branch):
+    request = urllib2.Request(GITHUB_MASTER_URI)
+    page = urllib2.urlopen(request)
+    json_result = json.loads(page.read())
+    sha_orig = json_result[0]["sha"]
+    request = urllib2.Request(GITHUB_BASE_URI + username + "/" + args.repository + "/commits?sha=" + branch)
+    page = urllib2.urlopen(request)
+    json_result = json.loads(page.read())
+    found = -1
+    for commit in json_result:
+        if commit["sha"] == sha_orig:
+            found = 1
+            break
+    return found
+
+
+
 def SubmitBuild(branch):
     raw_params = {'username':username,'passwd':password,'branch':branch,'comments':'Testing ' + branch, 'name':'force_build'}
     params = urllib.urlencode(raw_params)
@@ -73,8 +94,10 @@ def GetBuildStatus(builder, buildid):
         return 0
     return -1
 
-# check that github branch and current branch are sync
-
+# check that github branch and inliniac master branch are sync
+if TestRepoSync(args.branch) == -1:
+    print "Branch " + args.branch + " is not in sync with inliniac's master branch. Rebase needed."
+    sys.exit(-1)
 
 # submit buildbot form to build current branch on the devel builder
 if not args.check: