obmc-gerrit: Require a topic be specified

Topics make it much easier to understand related groups of commits in
the Gerrit UI.

    $ obmc-gerrit push -h
    usage: obmc-gerrit push [-h] remote refspec topic

    positional arguments:
      remote
      refspec
      topic

    optional arguments:
      -h, --help  show this help message and exit

    $ obmc-gerrit push gerrit HEAD:refs/for/master obmc-gerrit-topic
    Enumerating objects: 11, done.
    Counting objects: 100% (11/11), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (6/6), 881 bytes | 881.00 KiB/s, done.
    Total 6 (delta 4), reused 0 (delta 0)
    remote: Resolving deltas: 100% (4/4)
    remote: Processing changes: refs: 1, updated: 1, done
    remote: warning: e764977: no files changed, message updated
    remote:
    remote: SUCCESS
    remote:
    remote: Updated Changes:
    remote:   https://gerrit.openbmc-project.xyz/c/openbmc/openbmc-tools/+/33636 obmc-gerrit: Require a topic be specified
    remote:
    To ssh://gerrit.openbmc-project.xyz:29418/openbmc/openbmc-tools
     * [new branch]                HEAD -> refs/for/master%r=andrew@aj.id.au,r=geissonator@yahoo.com,topic=obmc-gerrit-topic

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I927e14b11ae2765b9831e262462f43a773e67b6c
diff --git a/amboar/obmc-scripts/maintainers/obmc-gerrit b/amboar/obmc-scripts/maintainers/obmc-gerrit
index e7e8f6a..6cb24cb 100755
--- a/amboar/obmc-scripts/maintainers/obmc-gerrit
+++ b/amboar/obmc-scripts/maintainers/obmc-gerrit
@@ -37,14 +37,16 @@
             reviewers.extend(i.email.address for i in rlist)
     return reviewers
 
-def gerrit_refspec_args(reviewers: Optional[List[str]]=None) -> str:
-    args = ""
+def gerrit_refspec_args(reviewers: Optional[List[str]]=None, topic: str=None) -> str:
+    argl = []
     if reviewers:
-        args += ",".join("r={}".format(addr) for addr in reviewers)
-    return args
+        argl.extend("r={}".format(addr) for addr in reviewers)
+    if topic:
+        argl.append("topic={}".format(topic));
+    return ",".join(argl)
 
-def decorate_refspec(refspec: str) -> str:
-    gargs = gerrit_refspec_args(get_reviewers())
+def decorate_refspec(refspec: str, topic: str) -> str:
+    gargs = gerrit_refspec_args(get_reviewers(), topic)
     if not gargs:
         return refspec
     if '%' in refspec:
@@ -52,7 +54,7 @@
     return "{}%{}".format(refspec, gargs)
 
 def do_push(args: argparse.Namespace) -> None:
-    git.push(args.remote, decorate_refspec(args.refspec),
+    git.push(args.remote, decorate_refspec(args.refspec, args.topic),
              _in=sys.stdin, _out=sys.stdout, _err=sys.stderr)
 
 parser = argparse.ArgumentParser()
@@ -61,6 +63,7 @@
 push = subbies.add_parser("push", help="Push changes to Gerrit with reviewers")
 push.add_argument("remote")
 push.add_argument("refspec")
+push.add_argument("topic")
 push.set_defaults(func=do_push)
 
 args = parser.parse_args()