From dddfd7eb55fae94241a8da054ce8245293c8576f Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Tue, 17 Oct 2023 21:54:17 +0000 Subject: [PATCH] pr_labeler: use @release-management-wg team for porting_guide check Instead of hardcoding the list of release managers, we can use the Github API to retrieve the members of the `@ansible/release-management-wg` team. --- hacking/pr_labeler/label.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/hacking/pr_labeler/label.py b/hacking/pr_labeler/label.py index e13f13c47eb..6fa0ed97e92 100644 --- a/hacking/pr_labeler/label.py +++ b/hacking/pr_labeler/label.py @@ -27,14 +27,6 @@ LABELS_BY_CODEOWNER: dict[OwnerTuple, list[str]] = { ("TEAM", "@ansible/steering-committee"): ["sc_approval"], } -RELEASE_MANAGEMENT_MEMBERS = { - "anweshadas", - "felixfontein", - "gotmax23", - "mariolenz", - "rooftopcellist", - "webknjaz", -} HERE = Path(__file__).resolve().parent ROOT = HERE.parent.parent CODEOWNERS = (ROOT / ".github/CODEOWNERS").read_text("utf-8") @@ -182,6 +174,18 @@ def create_boilerplate_comment(ctx: IssueOrPrCtx, name: str, **kwargs) -> None: create_comment(ctx, tmpl) +def get_team_members(ctx: IssueOrPrCtx, team: str) -> list[str]: + """ + Get the members of a Github team + """ + return [ + user.login + for user in ctx.client.get_organization(ctx.repo.organization.login) + .get_team_by_slug(team) + .get_members() + ] + + def handle_codeowner_labels(ctx: PRLabelerCtx) -> None: labels = LABELS_BY_CODEOWNER.copy() owners = CodeOwners(CODEOWNERS) @@ -241,8 +245,16 @@ def warn_porting_guide_change(ctx: PRLabelerCtx) -> None: """ Complain if a user outside of the Release Management WG changes porting_guide """ - if ctx.pr.user.login in RELEASE_MANAGEMENT_MEMBERS: + # If the API token does not have permisisons to view teams in the ansible + # org, fall back to an empty list. + members = [] + try: + members = get_team_members(ctx, "release-management-wg") + except github.UnknownObjectException: + log(ctx, "Failed to get members of @ansible/release-management-wg") + if ctx.pr.user.login in members: return + matches: list[str] = [] for file in ctx.pr.get_files(): if re.fullmatch(