-
Notifications
You must be signed in to change notification settings - Fork 3
Review coverage dashboard #602
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06e3a82
Add review coverage to dashboard
gonzaM d81088f
Merge branch 'feature/review_coverage' into review_coverage_dashboard
gonzaM be2d6a6
Adjust review coverage tests
gonzaM 839c1b6
Add tests for repository distribution logic
gonzaM b671b3a
Fix tests
gonzaM 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
7 changes: 7 additions & 0 deletions
7
app/controllers/pull_requests/review_coverage_prs_repository_controller.rb
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,7 @@ | ||
| module PullRequests | ||
| class ReviewCoveragePrsRepositoryController < PullRequestsController | ||
| def repository | ||
| Builders::Distribution::PullRequests::ReviewCoverageRepository | ||
| end | ||
| end | ||
| end | ||
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
23 changes: 23 additions & 0 deletions
23
app/services/builders/chartkick/repository_distribution_data_metrics/review_coverage.rb
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,23 @@ | ||
| module Builders | ||
| module Chartkick | ||
| module RepositoryDistributionDataMetrics | ||
| class ReviewCoverage | ||
| def retrieve_records(entity_id:, time_range:) | ||
| ::ReviewCoverage | ||
| .joins(pull_request: :repository) | ||
| .where(repositories: { id: entity_id }) | ||
| .where(events_pull_requests: { merged_at: time_range }) | ||
| .where.not(events_pull_requests: { owner: User.ignored_users }) | ||
| end | ||
|
|
||
| def resolve_interval(entity) | ||
| Metrics::IntervalResolver::Percentage.call(entity.coverage_percentage * 100) | ||
| end | ||
|
|
||
| def value_for_average(entity) | ||
| entity.coverage_percentage * 100 | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
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
37 changes: 37 additions & 0 deletions
37
app/services/builders/distribution/pull_requests/review_coverage_repository.rb
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,37 @@ | ||
| module Builders | ||
| module Distribution | ||
| module PullRequests | ||
| class ReviewCoverageRepository < BaseService | ||
| def initialize(repository_name:, from:, to:) | ||
| @repository_name = repository_name | ||
| @from = from.to_datetime.beginning_of_day | ||
| @to = to.to_datetime.end_of_day | ||
| end | ||
|
|
||
| def call | ||
| review_coverages.each_with_object(hash_of_arrays) { |review_coverage, hash| | ||
| coverage = review_coverage.coverage_percentage * 100 | ||
| interval = Metrics::IntervalResolver::Percentage.call(coverage) | ||
| pr_values = { html_url: review_coverage.pull_request.html_url, value: coverage } | ||
| hash[interval] << pr_values | ||
| }.sort.to_h | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def review_coverages | ||
| @review_coverages ||= ::ReviewCoverage | ||
| .joins(pull_request: :repository) | ||
| .where(repositories: { name: @repository_name }) | ||
| .where(pull_request: { merged_at: @from..@to }) | ||
| .where.not(pull_request: { owner: User.ignored_users }) | ||
| .order(:coverage_percentage) | ||
| end | ||
|
|
||
| def hash_of_arrays | ||
| Hash.new { |hash, key| hash[key] = [] } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module Metrics | ||
| module IntervalResolver | ||
| class Percentage < Metrics::IntervalResolver::Base | ||
| def ranges | ||
| { '0-10': 10, '10-20': 20, '20-40': 40, '40-60': 60, '60-80': 80 } | ||
gonzaM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
| end | ||
| end | ||
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,24 @@ | ||
| module Metrics | ||
| module ReviewCoverage | ||
| class PerRepository < Metrics::Base | ||
| private | ||
|
|
||
| def process | ||
| week_intervals.flat_map do |week| | ||
| interval = build_interval(week) | ||
| query(interval).map do |repository_id, metric_value| | ||
| Metric.new(repository_id, interval.first, metric_value) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def query(interval) | ||
| Repository.joins(pull_requests: :review_coverage) | ||
| .where(events_pull_requests: { merged_at: interval }) | ||
| .where(id: @entity_id) | ||
| .group(:id) | ||
| .pluck(:id, Arel.sql('AVG(review_coverages.coverage_percentage)')) | ||
| end | ||
| end | ||
| end | ||
| end |
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
7 changes: 7 additions & 0 deletions
7
app/views/development_metrics/review_coverage/_main_metric.erb
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,7 @@ | ||
| <%= render partial: 'shared/column-chart', | ||
| locals: { | ||
| chart_id: 'review-coverage', | ||
| metric_name: 'Distribution', | ||
| suffix: " pull requests", | ||
| metric: review_coverage[:per_repository_distribution] | ||
| } if review_coverage && review_coverage[:per_repository_distribution] %> |
17 changes: 17 additions & 0 deletions
17
app/views/pull_requests/review_coverage_prs_repository/index.erb
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,17 @@ | ||
| <%= render 'development_metrics/development_metrics_sidebar', enabled_users_section: @enabled_users_section %> | ||
| <div class="metrics-container"> | ||
| <div class="row title_sidebar"> | ||
| <div class="col-md-6"> | ||
| <b class="rute_title_grey"><%= @repository_name %>/</b> | ||
| <b class="rute_title">Review Coverage</b> | ||
| </div> | ||
| <div class="col-md-6 interval d-flex flex-row-reverse"> | ||
| <%= simple_form_for :metric, url: repository_review_coverage_prs_repository_index_path, method: 'GET', html: { | ||
| id: 'nav-filter-form', style:"display: flex;"} do |f|%> | ||
| <%= hidden_field_tag 'repository_name', @repository_name %> | ||
| <%= render 'shared/interval-filter', form: f %> | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
| <%= render partial: 'shared/pull_request_list' , locals: { pull_requests: @pull_requests, kpi_label: '%' } %> | ||
| </div> |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a fan of using inheritance for controllers but ok