Skip to content

feat: add FILTER_TEAMS env var for dynamic team-based PR filtering#14

Merged
zkoppert merged 5 commits intomainfrom
feature/filter-teams
Mar 13, 2026
Merged

feat: add FILTER_TEAMS env var for dynamic team-based PR filtering#14
zkoppert merged 5 commits intomainfrom
feature/filter-teams

Conversation

@zkoppert
Copy link
Contributor

Summary

Adds a new FILTER_TEAMS environment variable that accepts comma-separated GitHub team slugs in org/team-slug format. At runtime, team members are resolved via the GitHub API and merged (union) with any FILTER_AUTHORS entries.

This addresses the maintenance burden of hardcoding individual usernames in FILTER_AUTHORS — team membership changes propagate automatically.

Changes

File Change
env.py Add filter_teams field to EnvVars dataclass with parsing
auth.py Add get_team_members() function using github3-py team API
pr_conflict_detector.py Resolve teams after auth, merge with filter_authors
README.md Document FILTER_TEAMS in config table + example workflow
.env-example Add FILTER_TEAMS template
test_env.py 3 new tests for FILTER_TEAMS parsing
test_auth.py 4 new tests for get_team_members()
test_pr_conflict_detector.py 3 new integration tests

Usage

env:
  GH_TOKEN: ${{ secrets.GH_TOKEN }}
  ORGANIZATION: my-org
  FILTER_TEAMS: "my-org/frontend-team,my-org/backend-team"

Can be combined with FILTER_AUTHORS:

  FILTER_TEAMS: "my-org/frontend-team"
  FILTER_AUTHORS: "alice,bob"  # Additional individual users

Notes

  • Requires read:org scope on the token (or Members: Read for GitHub Apps)
  • Missing teams or permission errors log a warning and skip gracefully
  • 200 tests pass, 99.29% coverage

@github-actions github-actions bot added the feature New feature or functionality label Mar 12, 2026
@zkoppert zkoppert self-assigned this Mar 12, 2026
Add support for filtering PRs by GitHub team membership instead of
hardcoding individual usernames in FILTER_AUTHORS. The new FILTER_TEAMS
env var accepts comma-separated org/team-slug values (e.g.,
'my-org/frontend-team,my-org/backend-team'). At runtime, team members
are resolved via the GitHub API and merged with any FILTER_AUTHORS
entries (union).

Changes:
- env.py: Add filter_teams field to EnvVars dataclass with parsing
- auth.py: Add get_team_members() function using github3-py team API
- pr_conflict_detector.py: Resolve teams after auth, merge with
  filter_authors, pass combined set to existing filter logic
- README.md: Document FILTER_TEAMS in config table, add example,
  note read:org permission requirement
- action.yml: No changes needed (env-based config)
- .env-example: Add FILTER_TEAMS template
- Tests: 7 new tests (3 env parsing, 4 auth, 3 integration)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@zkoppert zkoppert force-pushed the feature/filter-teams branch from f625183 to f8cca52 Compare March 12, 2026 05:00
zkoppert and others added 2 commits March 12, 2026 10:40
- Use set instead of sorted list for O(1) membership lookups
- Truncate log output to show count instead of full author list
- Add test for overlapping team members deduplication
- Fix README YAML snippet to include env: context wrapper

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@zkoppert zkoppert marked this pull request as ready for review March 12, 2026 22:57
@zkoppert zkoppert requested a review from jmeridth as a code owner March 12, 2026 22:57
Copy link
Collaborator

@jmeridth jmeridth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple suggestions

zkoppert and others added 2 commits March 13, 2026 01:24
- Remove effective_filter_authors alias, use combined_filter_authors directly
- Move FILTER_TEAMS format validation to env.py with ValueError (fail-fast)
- Add warning when FILTER_TEAMS resolves no members and no FILTER_AUTHORS set
- Add tests for validation in env.py and empty resolution warning

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@zkoppert zkoppert merged commit 0e604a1 into main Mar 13, 2026
35 checks passed
@zkoppert zkoppert deleted the feature/filter-teams branch March 13, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants