From 8f5d92a40f46144fdaec0f9dcb9ca00f1be75e85 Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Wed, 9 Jul 2025 22:21:15 +0200 Subject: [PATCH] Extract commit range representation into presenter --- .../managed_versioning/component_updater.rb | 5 +--- lib/pyxis/presenter/commit_range.rb | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 lib/pyxis/presenter/commit_range.rb diff --git a/lib/pyxis/managed_versioning/component_updater.rb b/lib/pyxis/managed_versioning/component_updater.rb index 43c3016..ad0d7f5 100644 --- a/lib/pyxis/managed_versioning/component_updater.rb +++ b/lib/pyxis/managed_versioning/component_updater.rb @@ -48,9 +48,6 @@ def execute new_version_link = "[#{new_version[0...11]}](https://github.com/#{component.github_path}/commits/#{new_version})" - commit_count = GithubClient.octokit.compare(component.github_path, current_version, new_version).ahead_by - commit_range = "#{current_version[0...11]}...#{new_version[0...11]} (#{commit_count} commits)" - compare_link = "[#{commit_range}](https://github.com/#{component.github_path}/compare/#{current_version}...#{new_version})" pr = GithubClient.octokit.create_pull_request( Project::Reticulum.github_path, Project::Reticulum.default_branch, @@ -59,7 +56,7 @@ def execute <<~DESCRIPTION Update #{component.component_name} to #{new_version_link} as part of managed versioning - #{compare_link} + #{Presenter::CommitRange.new(component, current_version, new_version).as_markdown} DESCRIPTION ) logger.info('Created pull request', pull_request_url: pr.html_url) diff --git a/lib/pyxis/presenter/commit_range.rb b/lib/pyxis/presenter/commit_range.rb new file mode 100644 index 0000000..34ecf69 --- /dev/null +++ b/lib/pyxis/presenter/commit_range.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Pyxis + module Presenter + class CommitRange + attr_reader :project, :current_version, :new_version + + def initialize(project, current_version, new_version) + @project = project + @current_version = current_version + @new_version = new_version + end + + def as_markdown + "[#{current_version[0...11]}...#{new_version[0...11]}](#{compare_link}) (#{commit_amount} commits)" + end + + private + + def compare_link + "https://github.com/#{project.github_path}/compare/#{current_version}...#{new_version}" + end + + def commit_amount + GithubClient.octokit.compare(project.github_path, current_version, new_version).ahead_by + end + end + end +end