obmc-gerrit: Return empty list on missing MAINTAINERS
Prevents dumping a traceback when no MAINTAINERS is present:
$ obmc-gerrit push gerrit HEAD:refs/for/master
Traceback (most recent call last):
File "/home/andrew/.local/bin/obmc-gerrit", line 63, in <module>
args.func(args)
File "/home/andrew/.local/bin/obmc-gerrit", line 51, in do_push
git.push(args.remote, decorate_refspec(args.refspec),
File "/home/andrew/.local/bin/obmc-gerrit", line 45, in decorate_refspec
gargs = gerrit_refspec_args(get_reviewers())
File "/home/andrew/.local/bin/obmc-gerrit", line 24, in get_reviewers
with open(mfile, 'r') as mstream:
FileNotFoundError: [Errno 2] No such file or directory: '/home/andrew/src/openbmc/phosphor-mboxd/MAINTAINERS'
Also, avoid mangling the refspec if the set of reviewers is empty -
there's no need for the trailing '%':
$ obmc-gerrit push ph-gerrit HEAD:refs/for/master
...
To ssh://gerrit.openbmc-project.xyz:29418/openbmc/phosphor-mboxd
* [new branch] HEAD -> refs/for/master%
Change-Id: I35300149f61089d4325532c45329e0fb4df6c009
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/amboar/obmc-scripts/maintainers/obmc-gerrit b/amboar/obmc-scripts/maintainers/obmc-gerrit
index a52abbc..800e561 100755
--- a/amboar/obmc-scripts/maintainers/obmc-gerrit
+++ b/amboar/obmc-scripts/maintainers/obmc-gerrit
@@ -21,6 +21,8 @@
if not root:
root = git('rev-parse', '--show-toplevel').strip()
mfile = os.path.join(root, mname)
+ if not os.path.exists(mfile):
+ return reviewers
with open(mfile, 'r') as mstream:
maintainers.trash_preamble(mstream)
block = maintainers.parse_block(mstream)
@@ -43,6 +45,8 @@
def decorate_refspec(refspec: str) -> str:
gargs = gerrit_refspec_args(get_reviewers())
+ if not gargs:
+ return refspec
if '%' in refspec:
return "{},{}".format(refspec, gargs)
return "{}%{}".format(refspec, gargs)