[Libreoffice-commits] dev-tools.git: gerrit/auto-submit

Miklos Vajna vmiklos at collabora.co.uk
Fri Jun 12 11:41:21 PDT 2015


 gerrit/auto-submit/Makefile          |    2 +
 gerrit/auto-submit/README            |   11 +++++++
 gerrit/auto-submit/gerrit-autosubmit |   51 +++++++++++++++++++++++++++++++++++
 gerrit/auto-submit/git-breview       |   14 +++++++++
 4 files changed, 78 insertions(+)

New commits:
commit 306b215b88d63b8963777ed352514808338844ce
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jun 12 10:25:46 2015 +0200

    gerrit: import two auto-submit scripts I posted to the list earlier
    
    So that they are not hidden in the list archive (Jacobo could not find
    it).
    
    Change-Id: I1dacd95b7e28b89b7cf35cb146cc05dff7078e5e

diff --git a/gerrit/auto-submit/Makefile b/gerrit/auto-submit/Makefile
new file mode 100644
index 0000000..3c0456a
--- /dev/null
+++ b/gerrit/auto-submit/Makefile
@@ -0,0 +1,2 @@
+check:
+	pep8 --ignore=E501 gerrit-autosubmit
diff --git a/gerrit/auto-submit/README b/gerrit/auto-submit/README
new file mode 100644
index 0000000..f6c2bdd
--- /dev/null
+++ b/gerrit/auto-submit/README
@@ -0,0 +1,11 @@
+In case your workflow is:
+
+1) Push patch to gerrit.
+2) Mark as code-review-+2
+3) Wait for build-verification.
+4) Submit if 3) succeeded.
+
+Then 1) and 2) is handled by git-breview.
+
+gerrit-autosubmit is supposed to be running all the time, then can automate
+4).
diff --git a/gerrit/auto-submit/gerrit-autosubmit b/gerrit/auto-submit/gerrit-autosubmit
new file mode 100755
index 0000000..52fc02c
--- /dev/null
+++ b/gerrit/auto-submit/gerrit-autosubmit
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+import json
+import os
+import subprocess
+
+
+def get_config(key):
+    sock = subprocess.Popen(["git", "config", "-f", ".gitreview", key], stdout=subprocess.PIPE)
+    ret = sock.stdout.readline().strip()
+    sock.stdout.close()
+    return ret
+
+server = get_config("gerrit.host")
+project = get_config("gerrit.project")
+branch = get_config("gerrit.defaultbranch")
+
+sock = subprocess.Popen(["ssh", server, "gerrit", "stream-events"], stdout=subprocess.PIPE, bufsize=1)
+
+try:
+    for line in iter(sock.stdout.readline, b''):
+        event = json.loads(line)
+
+        if event['type'] != "comment-added":
+            continue
+        if event['change']['owner']['username'] != os.environ['USER']:
+            continue
+        if event['change']['project'] != project:
+            continue
+        if event['change']['branch'] != branch:
+            continue
+        if 'approvals' not in event.keys():
+            continue
+        if len([approval for approval in event['approvals'] if approval['type'] == "Verified" and approval['value'] == "1"]) != 1:
+            continue
+
+        rev = event['patchSet']['revision']
+        cmd = "ssh " + server + " gerrit review -s " + rev
+        print(cmd)
+        os.system(cmd)
+except KeyboardInterrupt:
+    print("Interrupted!")
+
+sock.communicate()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/gerrit/auto-submit/git-breview b/gerrit/auto-submit/git-breview
new file mode 100755
index 0000000..00d815c
--- /dev/null
+++ b/gerrit/auto-submit/git-breview
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+if git-review; then
+    rev=$(git rev-parse HEAD)
+    host=$(git config -f .gitreview gerrit.host)
+    ssh $host gerrit review --code-review=2 $rev
+fi
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list