mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 06:55:21 +02:00
Fix changelog page crash when GitHub release notes are unavailable
This commit is contained in:
parent
6dae236fe0
commit
803d22a2f6
3 changed files with 45 additions and 3 deletions
|
@ -29,6 +29,17 @@ class PagesController < ApplicationController
|
|||
def changelog
|
||||
@release_notes = github_provider.fetch_latest_release_notes
|
||||
|
||||
# Fallback if no release notes are available
|
||||
if @release_notes.nil?
|
||||
@release_notes = {
|
||||
avatar: "https://github.com/maybe-finance.png",
|
||||
username: "maybe-finance",
|
||||
name: "Release notes unavailable",
|
||||
published_at: Date.current,
|
||||
body: "<p>Unable to fetch the latest release notes at this time. Please check back later or visit our <a href='https://github.com/maybe-finance/maybe/releases' target='_blank'>GitHub releases page</a> directly.</p>"
|
||||
}
|
||||
end
|
||||
|
||||
render layout: "settings"
|
||||
end
|
||||
|
||||
|
|
|
@ -5,17 +5,17 @@
|
|||
<div class="w-full md:w-1/3">
|
||||
<div class="md:px-3 flex items-center gap-3">
|
||||
<div class="text-white shrink-0 w-9 h-9">
|
||||
<%= image_tag @release_notes[:avatar], class: "rounded-full w-full h-full object-cover" %>
|
||||
<%= image_tag @release_notes[:avatar], class: "rounded-full w-full h-full object-cover" if @release_notes[:avatar].present? %>
|
||||
</div>
|
||||
<div>
|
||||
<a class="text-primary font-medium text-sm" href="https://github.com/<%= @release_notes[:username] %>"><%= "@#{@release_notes[:username]}" %></a>
|
||||
<div class="text-secondary text-sm"><%= @release_notes[:published_at].strftime("%B %d, %Y") %></div>
|
||||
<div class="text-secondary text-sm"><%= @release_notes[:published_at]&.strftime("%B %d, %Y") %></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-full md:w-2/3 text-secondary text-sm prose prose--github-release-notes">
|
||||
<h2 class="mb-5 text-xl text-primary"><%= @release_notes[:name] %></h2>
|
||||
<%= @release_notes[:body].html_safe %>
|
||||
<%= @release_notes[:body]&.html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -16,4 +16,35 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_response :ok
|
||||
end
|
||||
end
|
||||
|
||||
test "changelog with nil release notes" do
|
||||
# Mock the GitHub provider to return nil (simulating API failure or no releases)
|
||||
github_provider = mock
|
||||
github_provider.expects(:fetch_latest_release_notes).returns(nil)
|
||||
Provider::Registry.stubs(:get_provider).with(:github).returns(github_provider)
|
||||
|
||||
get changelog_path
|
||||
assert_response :ok
|
||||
assert_select "h2", text: "Release notes unavailable"
|
||||
assert_select "a[href='https://github.com/maybe-finance/maybe/releases']"
|
||||
end
|
||||
|
||||
test "changelog with incomplete release notes" do
|
||||
# Mock the GitHub provider to return incomplete data (missing some fields)
|
||||
github_provider = mock
|
||||
incomplete_data = {
|
||||
avatar: nil,
|
||||
username: "maybe-finance",
|
||||
name: "Test Release",
|
||||
published_at: nil,
|
||||
body: nil
|
||||
}
|
||||
github_provider.expects(:fetch_latest_release_notes).returns(incomplete_data)
|
||||
Provider::Registry.stubs(:get_provider).with(:github).returns(github_provider)
|
||||
|
||||
get changelog_path
|
||||
assert_response :ok
|
||||
assert_select "h2", text: "Test Release"
|
||||
# Should not crash even with nil values
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue