Skip to content

Commit

Permalink
moving simplecov progress to its own service
Browse files Browse the repository at this point in the history
  • Loading branch information
evsasse committed Dec 23, 2024
1 parent 1de42a5 commit de7201b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ProjectsController < ApplicationController
helper_method :simplecov_progress

def create
@project = Project.new(create_params)

Expand Down Expand Up @@ -26,6 +28,10 @@ def update

private

memoize def simplecov_progress
::Projects::SimplecovProgress.new(@project).call
end

def create_params
params
.require(:project)
Expand Down
8 changes: 0 additions & 8 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,4 @@ def reset_api_auth!
update!(api_auth_digest: Digest::SHA512.hexdigest(token))
token
end

def reports_coverage_progress
reports.map do |report|
next if report.general_coverage.blank?

[ report.created_at, report.general_coverage ]
end.compact
end
end
19 changes: 19 additions & 0 deletions app/services/projects/simplecov_progress.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Projects
class SimplecovProgress
attr_reader :project

def initialize(project)
@project = project
end

def call
# TODO: could be improved to only get the last report of each date.
# TODO: could be improved to remove blank coverage reports at the SQL level.
project.reports.where(branch: "main").order(:created_at).map do |report|
next if report.general_coverage.blank?

[ report.created_at, report.general_coverage ]
end.compact
end
end
end
2 changes: 1 addition & 1 deletion app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<%=
line_chart(
@project.reports_coverage_progress,
simplecov_progress,
library: { scales: { y: { type: 'logarithmic' } } }
)
%>
Expand Down

0 comments on commit de7201b

Please sign in to comment.