Skip to content

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

Conversation

Kamlesh72
Copy link
Contributor

@Kamlesh72 Kamlesh72 commented Apr 28, 2025

Linked Issue(s)

Ref #557

Acceptance Criteria fulfillment

  • Incident PR setting to filter Incident PRs
  • Handle race condition on creating default settings in DB
  • Option to exclude REVERT_PR from Incident types if Incident PRs Setting has set include_revert_prs to false.
  • Tests for Incident Types setting in incident_filter file

Summary by CodeRabbit

  • New Features

    • Introduced a new incident pull request setting with configurable options including revert PR inclusion, title and branch filters, and PR mapping details.
    • Added default values and validation support for the new incident pull request setting.
    • Enhanced incident type filtering to conditionally exclude revert PRs based on the new setting.
  • Bug Fixes

    • Improved concurrency handling during settings creation to avoid conflicts and ensure reliable retrieval.

Sorry, something went wrong.

Copy link

coderabbitai bot commented Apr 28, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce a new configuration setting type called IncidentPrsSetting throughout the analytics server backend. This includes adding the new type to the SettingType enum, implementing its dataclass, providing default values, updating the settings service to handle conversions to and from this type, and extending API and validation logic to support it. Additionally, incident filtering logic now respects the include_revert_prs flag from this new setting, conditionally excluding "REVERT_PR" incidents. The settings service also improves concurrency handling when creating default settings.

Changes

File(s) Change Summary
.../settings/models.py Added new dataclass IncidentPrsSetting with fields for PR-related configuration.
.../settings/configuration_settings.py Added support for IncidentPrsSetting in adapters, JSON conversion, and settings retrieval; improved concurrency handling in default setting creation.
.../settings/default_settings_data.py Added default values for IncidentPrsSetting in get_default_setting_data.
.../settings/setting_type_validator.py Added validation logic for INCIDENT_PRS_SETTING in settings_type_validator.
.../store/models/settings/configuration_settings.py Added INCIDENT_PRS_SETTING to SettingType enum.
.../api/resources/settings_resource.py Updated imports and response adaptation logic to handle IncidentPrsSetting fields in API responses.
.../service/incidents/incident_filter.py Modified incident type filtering to respect the include_revert_prs flag from IncidentPrsSetting, excluding REVERT_PR as needed.
.../tests/service/Incidents/test_incident_types_setting.py Added unit tests covering incident type filtering behavior with different combinations of IncidentTypesSetting and IncidentPrsSetting.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Client
    participant API
    participant SettingsService
    participant DB

    Client->>API: Request configuration settings
    API->>SettingsService: Fetch settings
    SettingsService->>DB: Query settings by type
    DB-->>SettingsService: Return settings data
    SettingsService-->>API: Adapt settings (including IncidentPrsSetting)
    API-->>Client: Return settings (with IncidentPrsSetting fields)
Loading
sequenceDiagram
    participant IncidentFilter
    participant SettingsService

    IncidentFilter->>SettingsService: Get IncidentPrsSetting
    SettingsService-->>IncidentFilter: Return IncidentPrsSetting (include_revert_prs)
    IncidentFilter->>IncidentFilter: Filter incident types (exclude REVERT_PR if needed)

Poem

In the warren of code, a new setting appears,
For PRs and incidents, it now steers.
With filters and flags, and a pattern or two,
Revert PRs can vanish, if you want them to!
The rabbits rejoice, with their settings so neat—
Hopping through configs, their work is complete!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
backend/analytics_server/tests/service/Incidents/test_incident_types_setting.py (2)

58-80: Test name doesn't match assertion behavior.

The test name indicates "returns_empty_list" but the assertion checks for None rather than an empty list. This creates a discrepancy between the test name and its actual behavior.

-def test_get_incident_types_when_only_prs_setting_present_returns_empty_list():
+def test_get_incident_types_when_only_prs_setting_present_returns_none():

1-144: Consider adding an edge case test.

The tests cover most scenarios well, but consider adding a test for when IncidentTypesSetting contains only REVERT_PR and include_revert_prs is False, which should result in an empty list of incident types.

def test_get_incident_types_when_only_revert_pr_type_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.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()

    # Should be empty list as REVERT_PR is excluded
    assert incident_filter.incident_types == []
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efb6163 and 6739552.

📒 Files selected for processing (1)
  • backend/analytics_server/tests/service/Incidents/test_incident_types_setting.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: All file linting
🔇 Additional comments (5)
backend/analytics_server/tests/service/Incidents/test_incident_types_setting.py (5)

1-10: Imports look good and appropriate.

The necessary imports for testing the ConfigurationsIncidentFilterProcessor with the new IncidentPrsSetting feature are correctly included.


12-39: Test case correctly verifies behavior with only IncidentTypesSetting.

This test properly verifies that when only the IncidentTypesSetting is present, the incident types are directly passed through to the filter.


41-56: Test case correctly handles empty incident types setting.

Good test case confirming that an empty list in the settings produces an empty list in the filter.


82-112: Test correctly verifies 'include_revert_prs=True' behavior.

This test properly confirms that when both settings are present and include_revert_prs is True, the REVERT_PR type is included in the incident filter.


114-144: Test correctly verifies 'include_revert_prs=False' behavior.

The test properly confirms that when include_revert_prs is False, the REVERT_PR type is excluded from the incident filter, which is a key requirement from the PR objectives.

@adnanhashmi09 adnanhashmi09 changed the base branch from main to incidents-pr-filtering May 6, 2025 14:38
@adnanhashmi09 adnanhashmi09 merged commit b5c9275 into middlewarehq:incidents-pr-filtering May 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants