feat: extend self-approval to team membership (self_approval_via_teams)#166
feat: extend self-approval to team membership (self_approval_via_teams)#166daniil-pushin wants to merge 2 commits into
Conversation
allow_self_approval currently matches the PR author against individually listed logins only — an OR group like `* @org/backend` is never satisfied by a backend member authoring the PR, even though approvals from team members do satisfy it (issue multimediallc#49). Add an opt-in `self_approval_via_teams` config option: when enabled (together with allow_self_approval), the author's team memberships are resolved through the existing user-reviewer map and OR groups containing any of those teams are treated as satisfied. Teams are not removed from the groups, so other members remain valid reviewers. Default mode is unchanged; the option defaults to false. Requires a token able to read org team members — the same requirement as the documented GitHub Teams support. Closes multimediallc#49 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Additional-reviewer rules represent mandatory extra reviewers, and the
existing test suite documents the intent ("Self-approval only applies to
OR groups") — but the implementation satisfied any group containing the
author, including "&" groups the author (or now their team) is listed in.
Tag groups created from "&" rules with a new ReviewerGroup.Additional
flag (memoized separately from owner groups so the flag cannot leak
between roles) and skip them in SetAuthor self-approval, for both the
author's login and their team memberships. Emptiness satisfaction is
unchanged: if the author was the sole listed additional reviewer, the
group is still satisfied to avoid deadlocking the PR. The merge key in
MergeCodeOwners also includes the flag so owner and additional groups
with identical names are not deduplicated into one.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Pushed a second commit that tightens the semantics: self-approval (both by login and via teams) no longer satisfies additional-reviewer ( The test suite already documents this intent ("Self-approval only applies to OR groups"), but the implementation satisfied any group containing the author — including Implementation: |
Summary / Background
allow_self_approvalmatches the PR author against individually listed logins only: with a rule like* @org/backend @alice, a backend team member authoring a PR does not satisfy the group, even though an approval from the same person would (approvals are resolved through the user-reviewer map, the author is not).This implements the behavior requested in #49: an opt-in
self_approval_via_teamsconfig option that extends self-approval to team membership.Behavior
self_approval_via_teams = true(defaultfalse, effective together withallow_self_approval = true): the author's team memberships are resolved through the existing user-reviewer map, and OR groups containing any of those teams are treated as satisfied.AuthorModeDefaultis unchanged: team memberships are ignored there, since other members of the team must still be able to (and are expected to) review.Implementation notes
CodeOwners.SetAuthorgains a variadicauthorTeams ...Slugparameter — existing two-argument call sites keep compiling.Client.UserReviewers(user)getter over the already-builtuserReviewerMap; no new GitHub API surface.InitUserReviewerMapis called once beforeSetAuthor(with the pre-author owner set) and later re-initialized as before — one extra members fetch per team in the rules, only when the option is on. Happy to add caching inteamFetchif you'd prefer.allow_self_approvalitself would arguably match the README wording ("any OR ownership group they belong to") — happy to change if you prefer that.allow_self_approvalto make the login-only matching explicit.Testing
TestSetAuthorSelfApprovalViaTeamMembership— OR group containing the author's team is auto-satisfiedTestSetAuthorTeamsIgnoredInDefaultMode— default mode unchanged, team stays in the groupTestSetAuthorTeamsDoNotAffectUnrelatedGroups— groups without the author's teams remain requiredgo test ./...,go vet ./...cleanCloses #49
🤖 Generated with Claude Code