Skip to content

Commit 731d6a9

Browse files
authored
Merge pull request #605 from rootstrap/add_base_branch_to_prs
Add base branch to prs and dashboard
2 parents 8bdb390 + ff7035e commit 731d6a9

33 files changed

+358
-99
lines changed

app/assets/stylesheets/application.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,13 @@ main {
177177
}
178178

179179
.title_sidebar{
180-
padding-top: 48px;
181-
padding-bottom: 10px;
180+
padding-top: 3rem;
181+
padding-bottom: 0.6rem;
182+
}
183+
184+
.filters-bar{
185+
padding-top: 0.6rem;
186+
padding-bottom: 0.6rem;
182187
}
183188

184189
.btn-secondary {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.base-branch-selection {
2+
display: flex;
3+
align-items: baseline;
4+
5+
select {
6+
margin: 0 0.2rem;
7+
width: 120px;
8+
}
9+
}

app/controllers/development_metrics_controller.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def repositories
2222
build_overall_calculations(entity_name)
2323

2424
@code_owners = repository.code_owners.pluck(:login)
25+
@available_base_branches = repository.base_branches
2526
end
2627

2728
def departments
@@ -57,8 +58,14 @@ def build_overall_calculations(entity_name)
5758

5859
def build_metrics(entity_id, entity_name)
5960
validate_from_to(from: metric_params[:from], to: metric_params[:to])
60-
metrics = Builders::Chartkick::DevelopmentMetrics.const_get(entity_name)
61-
.call(entity_id, @from, @to)
61+
metrics = Builders::Chartkick::DevelopmentMetrics
62+
.const_get(entity_name)
63+
.call(
64+
entity_id,
65+
@from,
66+
@to,
67+
metric_params[:base_branch]
68+
)
6269
@merge_time = metrics[:merge_time]
6370
@pull_request_size = metrics[:pull_request_size]
6471
@review_coverage = metrics[:review_coverage]

app/controllers/pull_requests/pull_requests_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def index
1212
@pull_requests = repository.call(
1313
from: @from,
1414
to: @to,
15-
repository_name: @repository_name
15+
repository_name: @repository_name,
16+
base_branch: metric_params[:base_branch]
1617
)
1718
respond_to do |format|
1819
format.html { render :index }
@@ -23,7 +24,7 @@ def index
2324
private
2425

2526
def metric_params
26-
params.require(:metric).permit(:to, :from)
27+
params.require(:metric).permit(:to, :from, :base_branch)
2728
end
2829
end
2930
end

app/helpers/filters_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ def current_department
1313
def chosen_contribution_period
1414
params[:from] || 4
1515
end
16+
17+
def base_branch_chosen
18+
params.dig(:metric, :base_branch) || ''
19+
end
1620
end

app/models/events/pull_request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Table name: events_pull_requests
44
#
55
# id :bigint not null, primary key
6+
# base_branch :string
67
# body :text
78
# branch :string
89
# closed_at :datetime

app/models/repository.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def organization_name
147147
ENV['GITHUB_ORGANIZATION']
148148
end
149149

150+
def base_branches
151+
pull_requests.distinct.pluck(:base_branch).sort
152+
end
153+
150154
private
151155

152156
def set_default_language

app/services/builders/chartkick/development_metrics.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module Builders
22
module Chartkick
33
class DevelopmentMetrics < BaseService
4-
def initialize(entity_id, from, to)
4+
def initialize(entity_id, from, to, base_branch = nil)
55
@entity_id = entity_id
66
@from = from&.to_datetime&.beginning_of_day
77
@to = to&.to_datetime&.end_of_day
8+
@base_branch = base_branch
89
end
910

1011
def call
@@ -25,11 +26,14 @@ def metric_names
2526

2627
def metric_data(metric_name)
2728
Builders::Chartkick::MetricData.call(
28-
@entity_id,
29-
entities_by_metric[metric_name],
30-
metric_name,
31-
@from,
32-
@to
29+
entity_id: @entity_id,
30+
entities: entities_by_metric[metric_name],
31+
metric_name: metric_name,
32+
params: {
33+
from: @from,
34+
to: @to,
35+
base_branch: @base_branch
36+
}
3337
)
3438
end
3539

app/services/builders/chartkick/metric_data.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module Builders
22
module Chartkick
33
class MetricData < BaseService
4-
def initialize(entity_id, entities, metric_name, from, to)
4+
def initialize(entity_id:, entities:, metric_name:, params: {})
55
@entity_id = entity_id
66
@entities = entities
77
@metric_name = metric_name
8-
@from = from
9-
@to = to
8+
@from = params[:from]
9+
@to = params[:to]
10+
@base_branch = params[:base_branch]
1011
end
1112

1213
def call
@@ -15,9 +16,11 @@ def call
1516
entity_name: entity,
1617
entity_id: @entity_id,
1718
metric_name: @metric_name,
18-
from: @from,
19-
to: @to
20-
# prev: (@to.to_date - @from.to_date).to_i / 7
19+
params: {
20+
from: @from,
21+
to: @to,
22+
base_branch: @base_branch
23+
}
2124
)
2225
end
2326
end

app/services/builders/chartkick/repository_distribution_data.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def repository_name
2121
def retrieve_records
2222
@retrieve_records ||= metric.retrieve_records(
2323
entity_id: @entity_id,
24-
time_range: @query[:value_timestamp]
24+
time_range: @query[:value_timestamp],
25+
base_branch: @query[:base_branch]
2526
)
2627
end
2728

0 commit comments

Comments
 (0)