maintainers: move MAINTAINER parsing to module
In prep for supporting 'OWNERS' move maintainers parsing
details to the appropriate submodule.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I38aa703f36a82cc0ed34cc78d9ece76150f73b01
diff --git a/maintainers/obmc-gerrit b/maintainers/obmc-gerrit
index db6bcfe..b666652 100755
--- a/maintainers/obmc-gerrit
+++ b/maintainers/obmc-gerrit
@@ -24,23 +24,11 @@
reviewers: List[str] = list()
if not root:
root = git("rev-parse", "--show-toplevel").strip()
+
mfile = os.path.join(root, mname)
- if not os.path.exists(mfile):
- return (maints, reviewers)
- with open(mfile, "r") as mstream:
- maintainers.trash_preamble(mstream)
- block = maintainers.parse_block(mstream)
- if not block:
- return (maints, reviewers)
- mlist = cast(
- List[maintainers.Identity], block[maintainers.LineType.MAINTAINER]
- )
- maints.extend(i.email.address for i in mlist)
- if maintainers.LineType.REVIEWER in block:
- rlist = cast(
- List[maintainers.Identity], block[maintainers.LineType.REVIEWER]
- )
- reviewers.extend(i.email.address for i in rlist)
+ if os.path.exists(mfile):
+ return maintainers.get_reviewers(mfile)
+
return (maints, reviewers)
diff --git a/maintainers/obmc/maintainers.py b/maintainers/obmc/maintainers.py
index fe93d5d..f541e36 100755
--- a/maintainers/obmc/maintainers.py
+++ b/maintainers/obmc/maintainers.py
@@ -10,6 +10,7 @@
from typing import (
Dict,
NamedTuple,
+ Tuple,
Iterator,
Sequence,
Union,
@@ -184,6 +185,23 @@
return maintainers
+def get_reviewers(mfile: str) -> Tuple[List[str], List[str]]:
+ maintainers: List[str] = list()
+ reviewers: List[str] = list()
+
+ with open(mfile) as mstream:
+ trash_preamble(mstream)
+ block = parse_block(mstream)
+ if not block:
+ return (maintainers, reviewers)
+ mlist = cast(List[Identity], block[LineType.MAINTAINER])
+ maintainers.extend(i.email.address for i in mlist)
+ if LineType.REVIEWER in block:
+ rlist = cast(List[Identity], block[LineType.REVIEWER])
+ reviewers.extend(i.email.address for i in rlist)
+ return (maintainers, reviewers)
+
+
def assemble_name(name: str, dst: IO[str]) -> None:
dst.write(name)