jenkins-bot has submitted this change and it was merged.

Change subject: Fix and clean up pre git-review hook script
......................................................................


Fix and clean up pre git-review hook script

Once again somehow we were not getting the right project name for gerrit
and gerrit API would return incomplete results.

Also, ignore open patches that fail jenkins tests.

Change-Id: I48eced216caf3b2dde1f2ce333cfb6d93518c81d
---
M dev-scripts/pre-review
1 file changed, 26 insertions(+), 16 deletions(-)

Approvals:
  Kaldari: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/dev-scripts/pre-review b/dev-scripts/pre-review
index 3b40083..d34afc8 100755
--- a/dev-scripts/pre-review
+++ b/dev-scripts/pre-review
@@ -1,16 +1,21 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 import sys
 import urllib2
 import subprocess
 import json
 
+MAX_OPEN_PATCHES = 5
+
 def get_project():
-    command = "git remote -v | head -n1 | sed -e 's/.*\(ssh:.*\)\.git.*/\\1/'"
+    # example output of git remote -v | head -n 1:
+    # origin   
ssh://[email protected]:29418/mediawiki/extensions/MobileFrontend 
(fetch)
+    # desired output after sed regex:
+    # mediawiki/extensions/MobileFrontend
+    command = "git remote -v | head -n 1 | sed -e 's/.*:\/\/[^\/]*\/\([^ ]*\) 
.*/\\1/'"
     process = subprocess.Popen(command, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE, shell=True)
 
-    #Launch the shell command:
     output, error = process.communicate()
-    return "/".join(output.strip().split('/')[-3:])
+    return output.strip()
 
 def get_last_commit():
     command = "git log -1"
@@ -24,28 +29,33 @@
     url = "https://gerrit.wikimedia.org/r/changes/?q=status:open+project:"; \
         + project + "&n=25&O=1"
     req = urllib2.Request(url)
-    req.add_header('Accept',
-                   'application/json,application/json,application/jsonrequest')
-    req.add_header('Content-Type', "application/json; charset=UTF-8")
+    req.add_header('Accept', 'application/json')
     resp, data = urllib2.urlopen(req)
-    data = json.loads(data)
-    return data
+    return json.loads(data)
+
 
 changes = query_gerrit(get_project())
 open_patches = 0
-revised_patch = False
 commit = get_last_commit()
-for change in changes:
-    reviews = change["labels"]["Code-Review"]
 
+for change in changes:
     # This patch is updating an existing one so let's allow it.
     if change["change_id"] in commit:
-        revised_patch = True
-    wip = 'WIP' in change['subject']
-    if 'disliked' not in reviews and 'rejected' not in reviews and 'approved' 
not in reviews and not wip:
+        sys.exit()
+
+    reviews = change["labels"]["Code-Review"]
+    jenkins = change["labels"]["Verified"]
+
+    if (
+        'disliked' not in reviews and
+        'rejected' not in reviews and
+        'approved' not in reviews and
+        'rejected' not in jenkins and
+        'WIP' not in change['subject']
+    ):
         open_patches += 1
 
-if open_patches > 5 and not revised_patch:
+if open_patches > MAX_OPEN_PATCHES:
     print 'Do some code review first! There are %s open unreviewed patches!' % 
open_patches
     print 'You can still send this review but note this will generate bad 
karma by running `git review master --no-custom-script`.'
     sys.exit(1)

-- 
To view, visit https://gerrit.wikimedia.org/r/147696
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I48eced216caf3b2dde1f2ce333cfb6d93518c81d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to