-
Notifications
You must be signed in to change notification settings - Fork 121
feat(pr_filtering): Added Incident PRs Setting, handle race condition and Revert PR filter #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adnanhashmi09
merged 6 commits into
middlewarehq:incidents-pr-filtering
from
Kamlesh72:feat/incident-pr-settings
May 9, 2025
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59308b9
feat(pr_filtering): Added Incident PRs Setting
Kamlesh72 a463686
feat(pr_filtering): Handle race condition when creating default setti…
Kamlesh72 efb6163
feat(pr_filtering): Exclude Revert PR from Incident types based on In…
Kamlesh72 6739552
feat(pr_filtering): tests for incident types setting
Kamlesh72 d835a8a
feat(pr_filtering): updated a test method name
Kamlesh72 4505112
feat(pr_filtering): remove pr_mapping_field and pr_mapping_pattern fr…
Kamlesh72 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
backend/analytics_server/tests/service/Incidents/test_incident_types_setting.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
from mhq.service.incidents.incident_filter import ConfigurationsIncidentFilterProcessor | ||
from mhq.store.models.incidents import IncidentFilter | ||
from mhq.store.models.settings.configuration_settings import SettingType | ||
from mhq.service.settings.configuration_settings import ( | ||
IncidentTypesSetting, | ||
IncidentPrsSetting, | ||
) | ||
from mhq.store.models.incidents.enums import IncidentType | ||
from mhq.store.models.settings import EntityType | ||
|
||
|
||
def test_get_incident_types_when_only_types_setting_present(): | ||
setting_types = [SettingType.INCIDENT_TYPES_SETTING] | ||
setting_type_to_settings_map = { | ||
SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting( | ||
incident_types=[ | ||
IncidentType.INCIDENT, | ||
IncidentType.ALERT, | ||
IncidentType.REVERT_PR, | ||
] | ||
) | ||
} | ||
|
||
incident_filter = ConfigurationsIncidentFilterProcessor( | ||
incident_filter=IncidentFilter(), | ||
entity_type=EntityType.TEAM, | ||
entity_id="team_id", | ||
setting_types=setting_types, | ||
setting_type_to_settings_map=setting_type_to_settings_map, | ||
).apply() | ||
|
||
expected_incident_types = [ | ||
IncidentType.INCIDENT, | ||
IncidentType.ALERT, | ||
IncidentType.REVERT_PR, | ||
] | ||
|
||
assert incident_filter.incident_types == expected_incident_types | ||
|
||
|
||
def test_get_incident_types_when_types_setting_is_empty(): | ||
setting_types = [SettingType.INCIDENT_TYPES_SETTING] | ||
setting_type_to_settings_map = { | ||
SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting(incident_types=[]) | ||
} | ||
|
||
incident_filter = ConfigurationsIncidentFilterProcessor( | ||
incident_filter=IncidentFilter(), | ||
entity_type=EntityType.TEAM, | ||
entity_id="dummy_id", | ||
setting_types=setting_types, | ||
setting_type_to_settings_map=setting_type_to_settings_map, | ||
).apply() | ||
|
||
assert incident_filter.incident_types == [] | ||
|
||
|
||
def test_get_incident_types_when_only_prs_setting_present_returns_none(): | ||
setting_types = [SettingType.INCIDENT_PRS_SETTING] | ||
incident_prs_setting = IncidentPrsSetting( | ||
include_revert_prs=True, | ||
title_filters=[], | ||
head_branch_filters=[], | ||
pr_mapping_field="", | ||
pr_mapping_pattern="", | ||
) | ||
setting_type_to_settings_map = { | ||
SettingType.INCIDENT_PRS_SETTING: incident_prs_setting | ||
} | ||
|
||
incident_filter = ConfigurationsIncidentFilterProcessor( | ||
incident_filter=IncidentFilter(), | ||
entity_type=EntityType.TEAM, | ||
entity_id="team_id", | ||
setting_types=setting_types, | ||
setting_type_to_settings_map=setting_type_to_settings_map, | ||
).apply() | ||
|
||
assert incident_filter.incident_types is None | ||
|
||
|
||
def test_get_incident_types_when_both_types_and_prs_settings_present_and_includes_revert_prs(): | ||
setting_types = [ | ||
SettingType.INCIDENT_TYPES_SETTING, | ||
SettingType.INCIDENT_PRS_SETTING, | ||
] | ||
incident_prs_setting = IncidentPrsSetting( | ||
include_revert_prs=True, | ||
title_filters=[], | ||
head_branch_filters=[], | ||
pr_mapping_field="", | ||
pr_mapping_pattern="", | ||
) | ||
setting_type_to_settings_map = { | ||
SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting( | ||
incident_types=[IncidentType.INCIDENT, IncidentType.REVERT_PR] | ||
), | ||
SettingType.INCIDENT_PRS_SETTING: incident_prs_setting, | ||
} | ||
|
||
incident_filter = ConfigurationsIncidentFilterProcessor( | ||
incident_filter=IncidentFilter(), | ||
entity_type=EntityType.TEAM, | ||
entity_id="team_id", | ||
setting_types=setting_types, | ||
setting_type_to_settings_map=setting_type_to_settings_map, | ||
).apply() | ||
|
||
expected_incident_types = [IncidentType.INCIDENT, IncidentType.REVERT_PR] | ||
|
||
assert incident_filter.incident_types == expected_incident_types | ||
|
||
|
||
def test_get_incident_types_when_both_settings_present_and_not_includes_revert_prs(): | ||
setting_types = [ | ||
SettingType.INCIDENT_TYPES_SETTING, | ||
SettingType.INCIDENT_PRS_SETTING, | ||
] | ||
incident_prs_setting = IncidentPrsSetting( | ||
include_revert_prs=False, | ||
title_filters=[], | ||
head_branch_filters=[], | ||
pr_mapping_field="", | ||
pr_mapping_pattern="", | ||
) | ||
setting_type_to_settings_map = { | ||
SettingType.INCIDENT_TYPES_SETTING: IncidentTypesSetting( | ||
incident_types=[IncidentType.INCIDENT, IncidentType.REVERT_PR] | ||
), | ||
SettingType.INCIDENT_PRS_SETTING: incident_prs_setting, | ||
} | ||
|
||
incident_filter = ConfigurationsIncidentFilterProcessor( | ||
incident_filter=IncidentFilter(), | ||
entity_type=EntityType.TEAM, | ||
entity_id="team_id", | ||
setting_types=setting_types, | ||
setting_type_to_settings_map=setting_type_to_settings_map, | ||
).apply() | ||
|
||
expected_incident_types = [IncidentType.INCIDENT] | ||
|
||
assert incident_filter.incident_types == expected_incident_types |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.