Skip to content

Conversation

@gonzaM
Copy link
Contributor

@gonzaM gonzaM commented Jun 26, 2025

Add Base Branch Filtering to Pull Request Metrics

Summary

This PR introduces the ability to filter pull request metrics by base branch, enabling more granular insights into development workflows across different branches (e.g., develop, staging).
For example, PRs targeting the staging branch (typically used for releases) are usually larger and could affect the accuracy of the overall metrics. In such cases, it may be useful to view metrics exclusively for PRs with develop as the base branch.

Changes Made

Database Changes

  • Migration: Added base_branch column to events_pull_requests table to store the target branch for each PR

Backend Changes

Models

  • Updated Events::PullRequest model to include base branch data
  • Added base_branches method to Repository model to fetch available branches

Controllers

  • Modified DevelopmentMetricsController to pass base branch parameter to metrics builders
  • Updated PullRequestsController to accept and filter by base branch

Services

Enhanced multiple service classes to support base branch filtering:

  • Builders::Chartkick::DevelopmentMetrics and related metric builders
  • Distribution builders for pull request analysis
  • Metric group services for weekly reporting

Frontend Changes

UI Components

  • Added base branch dropdown filter in the metrics interface
  • Updated navigation filters to include branch selection

Styling

  • Added CSS styles for the new base branch filter component
  • Improved spacing and layout for the filters bar

Data Processing

  • Event Processing: Updated pull request event builder to capture base branch information from GitHub webhook data
  • Query Optimization: Modified database queries across metric builders to conditionally filter by base branch when specified

Technical Notes

  • All existing functionality remains unchanged when no base branch is selected
  • The filter integrates seamlessly with existing time-based filters
  • Database queries are optimized to only apply base branch filtering when a specific branch is selected

Testing

  • Updated existing tests to accommodate the new parameter structure
  • Ensured backward compatibility with existing metric calculations

Screenshot 2025-06-26 at 4 25 49 PM

@gonzaM gonzaM marked this pull request as ready for review June 26, 2025 20:39
@gonzaM gonzaM requested a review from a team as a code owner June 26, 2025 20:39
@gonzaM gonzaM requested review from rodrieiz and santib and removed request for a team June 26, 2025 20:39
@gonzaM gonzaM merged commit 731d6a9 into develop Jun 27, 2025
2 of 3 checks passed
@gonzaM gonzaM deleted the add_base_branch_to_prs branch June 27, 2025 17:55
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.

3 participants