Skip to content

Commit

Permalink
[581] fix: Fix broken Documentation link in UI (#583)
Browse files Browse the repository at this point in the history
* [581] fix: Fix broken Documentation link in UI

* fix test
  • Loading branch information
philosowaffle authored Dec 31, 2023
1 parent 7170c44 commit 75733a2
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Api.Service/Api.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Philosowaffle.Capability.ReleaseChecks" Version="1.0.0" />
<PackageReference Include="Philosowaffle.Capability.ReleaseChecks" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Api.Service/ApiStartupServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static void ConfigureP2GApiServices(this IServiceCollection services)
services.AddSingleton<ISyncStatusDb, SyncStatusDb>();
services.AddSingleton<ISyncService, SyncService>();

// SYSTEM INFO
// SYSTEM INFO
services.AddSingleton<IVersionInformationService, VersionInformationService>();
services.AddSingleton<ISystemInfoService, SystemInfoService>();

// USERS
Expand Down
14 changes: 8 additions & 6 deletions src/Api.Service/SystemInfoService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Api.Contract;
using Api.Service;
using Common;
using Common.Dto;
using Common.Observe;
using Common.Service;
using Core.GitHub;
using Philosowaffle.Capability.ReleaseChecks.Model;

namespace Api.Services;
Expand All @@ -16,12 +16,12 @@ public interface ISystemInfoService

public class SystemInfoService : ISystemInfoService
{
private readonly IGitHubReleaseCheckService _gitHubService;
private readonly IVersionInformationService _versionInformationService;
private readonly ISettingsService _settingsService;

public SystemInfoService(IGitHubReleaseCheckService gitHubService, ISettingsService settingsService)
public SystemInfoService(ISettingsService settingsService, IVersionInformationService versionInformationService)
{
_gitHubService = gitHubService;
_versionInformationService = versionInformationService;
_settingsService = settingsService;
}

Expand All @@ -30,7 +30,9 @@ public async Task<SystemInfoGetResponse> GetAsync(SystemInfoGetRequest request,
LatestReleaseInformation? versionInformation = null;

if (request.CheckForUpdate)
versionInformation = await _gitHubService.GetLatestReleaseInformationAsync("philosowaffle", "peloton-to-garmin", Constants.AppVersion);
versionInformation = await _versionInformationService.GetLatestReleaseInformationAsync();

var documentationVersion = versionInformation?.IsInstalledVersionReleaseCandidate ?? true ? "master" : $"v{Constants.AppVersion}";

var settings = await _settingsService.GetSettingsAsync();

Expand All @@ -52,7 +54,7 @@ public async Task<SystemInfoGetResponse> GetAsync(SystemInfoGetRequest request,
} : null,

GitHub = "https://github.com/philosowaffle/peloton-to-garmin",
Documentation = "https://philosowaffle.github.io/peloton-to-garmin/",
Documentation = $"https://philosowaffle.github.io/peloton-to-garmin/{documentationVersion}",
Forums = "https://github.com/philosowaffle/peloton-to-garmin/discussions",
Donate = "https://www.buymeacoffee.com/philosowaffle",
Issues = "https://github.com/philosowaffle/peloton-to-garmin/issues",
Expand Down
52 changes: 52 additions & 0 deletions src/Api.Service/VersionInformationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Common;
using Common.Observe;
using Core.GitHub;
using Microsoft.Extensions.Caching.Memory;
using Philosowaffle.Capability.ReleaseChecks.Model;
using Serilog;

namespace Api.Service;

public interface IVersionInformationService
{
Task<LatestReleaseInformation> GetLatestReleaseInformationAsync();
}

public class VersionInformationService : IVersionInformationService
{
private static readonly ILogger _logger = LogContext.ForClass<VersionInformationService>();
private static readonly object _lock = new object();

private readonly IGitHubReleaseCheckService _gitHubService;
private readonly IMemoryCache _cache;

public VersionInformationService(IGitHubReleaseCheckService gitHubService, IMemoryCache cache)
{
_gitHubService = gitHubService;
_cache = cache;
}

public Task<LatestReleaseInformation> GetLatestReleaseInformationAsync()
{
using var tracing = Tracing.Trace($"{nameof(VersionInformationService)}.{nameof(GetLatestReleaseInformationAsync)}");

try
{
lock (_lock)
{
var key = $"LatestReleaseInformation";
return _cache.GetOrCreateAsync(key, (cacheEntry) =>
{
cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
return _gitHubService.GetLatestReleaseInformationAsync("philosowaffle", "peloton-to-garmin", Constants.AppVersion);
});
}
}
catch (Exception e)
{
_logger.Error("Failed to fetch Latest P2G Release information.", e);
return Task.FromResult(new LatestReleaseInformation());
}
}
}
6 changes: 4 additions & 2 deletions src/SharedUI/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
private async Task LoadDataAsync()
{
using var tracing = Tracing.ClientTrace($"{nameof(Settings)}.{nameof(LoadDataAsync)}", kind: ActivityKind.Client);
var systemInfo = await _apiClient.SystemInfoGetAsync(new SystemInfoGetRequest() { CheckForUpdate = false });

configDocumentation = systemInfo.Documentation + "/configuration/json.html";
var settings = await _apiClient.SettingsGetAsync();
var systemInfo = await _apiClient.SystemInfoGetAsync(new SystemInfoGetRequest() { CheckForUpdate = settings.App.CheckForUpdates });

configDocumentation = systemInfo.Documentation + "/configuration/json";
}
}
7 changes: 4 additions & 3 deletions src/UnitTests/Api.Service/SystemInfoServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Api.Contract;
using Api.Service;
using Api.Services;
using Common;
using Core.GitHub;
Expand Down Expand Up @@ -42,9 +43,9 @@ public async Task GetAsync_WhenRequest_Enriches_LatestVersionInfo()
// SETUP
var autoMocker = new AutoMocker();
var controller = autoMocker.CreateInstance<SystemInfoService>();
var ghService = autoMocker.GetMock<IGitHubReleaseCheckService>();
var ghService = autoMocker.GetMock<IVersionInformationService>();

ghService.Setup(x => x.GetLatestReleaseInformationAsync("philosowaffle", "peloton-to-garmin", Constants.AppVersion))
ghService.Setup(x => x.GetLatestReleaseInformationAsync())
.ReturnsAsync(new LatestReleaseInformation()
{
IsReleaseNewerThanInstalledVersion = true,
Expand All @@ -64,6 +65,6 @@ public async Task GetAsync_WhenRequest_Enriches_LatestVersionInfo()
response.NewerVersionAvailable.Should().NotBeNull();
response.LatestVersionInformation.Should().NotBeNull();

ghService.Verify(x => x.GetLatestReleaseInformationAsync("philosowaffle", "peloton-to-garmin", Constants.AppVersion), Times.Once());
ghService.Verify(x => x.GetLatestReleaseInformationAsync(), Times.Once());
}
}
4 changes: 4 additions & 0 deletions vNextReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- [#564] Set a custom title prefix on Workouts
- [#559] Ability to exclude Outdoor Cycling workouts from sycning

## Fixes

- [#581] Fix broken Documentation link in UI

## Docker Tags

- Console
Expand Down

0 comments on commit 75733a2

Please sign in to comment.