Skip to content

Commit

Permalink
pr_labeler: use @release-management-wg team for porting_guide check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gotmax23 committed Oct 18, 2023
1 parent d2e6625 commit dddfd7e
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions hacking/pr_labeler/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit dddfd7e

Please sign in to comment.