Add filtering for PRs to match issue filtering behavior#418
Add filtering for PRs to match issue filtering behavior#418Bala-Sakabattula wants to merge 2 commits intorelease-engineering:mainfrom
Conversation
Review Summary by QodoAdd PR filtering to match issue filtering behavior
WalkthroughsDescription• Add filtering logic to PR handler matching issue filtering behavior • Support label, milestone, and custom field filtering for PRs • Ensure consistent filtering across both issue and PR handler paths • Add comprehensive test coverage for all filtering conditions Diagramflowchart LR
A["PR Handler"] --> B["Extract Filters Config"]
B --> C["Check Labels Filter"]
C --> D["Check Milestone Filter"]
D --> E["Check Other Fields Filter"]
E --> F{All Filters Pass?}
F -->|No| G["Return None"]
F -->|Yes| H["Process PR"]
File Changes1. sync2jira/upstream_pr.py
|
Code Review by Qodo
✅
📘 Rule violation ⛯ Reliability |
sync2jira/upstream_pr.py
Outdated
| _filter = config["sync2jira"].get("filters", {}).get("github", {}).get(upstream, {}) | ||
|
|
||
| pr = body["pull_request"] | ||
| for key, expected in _filter.items(): |
There was a problem hiding this comment.
To what extent is this whole section a copy/paste of the same code in upstream_issue.py?
Can it be refactored into a shared function?
There was a problem hiding this comment.
Yes it can be ..
webbnh
left a comment
There was a problem hiding this comment.
@Bala-Sakabattula, congratulations the perfect testing coverage for this change! 🏆
However, rather than adding this code here, I think you should refactor the body of upstream_issue.handle_github_message() into a subroutine which we can call from here.
sync2jira/upstream_pr.py
Outdated
| expected, | ||
| upstream, | ||
| ) | ||
| return None |
There was a problem hiding this comment.
This code in upstream_pr.py is now basically identical to the analogous code in upstream_issue.py. There are two significant differences, but the code in upstream_issue.py already makes provisions to handle one of them, and the other is that the Issue information is found in body["issue"] while the PR information is found in body["pull_request"], but that shouldn't be hard to code around (e.g., see how upstream_issue.py handles the analogous problem of accessing the "sync" field in the configuration; or, alternatively, the respective expressions could be specified as arguments to a common subroutine).
It's probably not worth trying to make a single handle_github_message() function which handles both PRs and Issues (because the outputs are different and the inputs are different currently), but the bulk of the body (e.g., lines 40-80) should be able to be refactored into a common subroutine used by both functions.
| github_client = Github(config["sync2jira"]["github_token"]) | ||
| reformat_github_pr(pr, upstream, github_client) |
There was a problem hiding this comment.
It looks like upstream_issue.py has some additional logic around creating the GitHub client which should either be reproduced here or refactored into a helper routine called from here.
Summary
This PR adds filtering (and other filter types) to PR handling in
upstream_pr.pyto ensure consistent filtering behavior between issues and PRs, regardless of which handler path they take.Problem
Previously, PRs were filtered inconsistently depending on which handler path they used:
u_issue.handle_github_message()withis_pr=True): PRs were filtered by labels, milestone, and other configured filters ✅u_pr.handle_github_message()): PRs were not filtered at all ❌This inconsistency meant that PRs coming through the PR handler path would bypass filtering and could create JIRA issues even when they didn't match the configured filter criteria (e.g., missing required labels).
Solution
Added the same filtering logic used in
upstream_issue.pytoupstream_pr.py'shandle_github_message()function. The filtering now supports:The same filter configuration (
config["sync2jira"]["filters"]["github"][upstream]) is used for both issues and PRs, ensuring consistent behavior.Changes
sync2jira/upstream_pr.py: Added filtering logic (lines 52-80) that mirrors the filtering inupstream_issue.pytests/test_upstream_pr.py: Added comprehensive test cases to verify all three filtering conditions work correctlyTesting
Added test cases:
test_handle_github_message_filtering: Tests that PRs are correctly filtered out when they don't match labels, milestone, or other field criteriatest_handle_github_message_filtering_passes: Tests that PRs pass through when all filters match