Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Include Major Version support for branch updates #31

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ServarrAPI/Controllers/UpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public async Task<object> GetUpdates([FromRoute(Name = "branch")] string updateB
[FromQuery(Name = "runtime")] Runtime runtime,
[FromQuery(Name = "runtimeVer")] string urlRuntimeVersion,
[FromQuery(Name = "arch")] Architecture arch,
[FromQuery(Name = "includeMajorVersion")] bool includeMajorVersion = false,
[FromQuery(Name = "dbType")] string dbType = "SQLite",
[FromQuery(Name = "active")] bool activeInstall = true)
{
Expand Down Expand Up @@ -120,7 +121,7 @@ public async Task<object> GetUpdates([FromRoute(Name = "branch")] string updateB
});
}

var files = await _updateFileService.Find(updateBranch, operatingSystem, runtime, arch, false, 1, urlVersion, urlRuntimeVersion);
var files = await _updateFileService.Find(updateBranch, operatingSystem, runtime, arch, false, 1, urlVersion, urlRuntimeVersion, !includeMajorVersion);

var updateFile = files.FirstOrDefault();

Expand Down
30 changes: 16 additions & 14 deletions src/ServarrAPI/Model/UpdateFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IUpdateFileService
{
Task<UpdateFileEntity> Insert(UpdateFileEntity model);
Task<UpdateFileEntity> Find(string version, string branch, OperatingSystem os, Runtime runtime, Architecture arch, bool installer);
Task<List<UpdateFileEntity>> Find(string branch, OperatingSystem os, Runtime runtime, Architecture arch, bool installer, int count, string installedVersion = null, string runtimeVersion = null);
Task<List<UpdateFileEntity>> Find(string branch, OperatingSystem os, Runtime runtime, Architecture arch, bool installer, int count, string installedVersion = null, string runtimeVersion = null, bool excludeMajorVersions = false);
}

public class UpdateFileService : IUpdateFileService
Expand Down Expand Up @@ -45,12 +45,12 @@ public Task<UpdateFileEntity> Find(string version, string branch, OperatingSyste
return _repo.Find(version, mappedBranch, os, runtime, arch, installer);
}

public Task<List<UpdateFileEntity>> Find(string branch, OperatingSystem os, Runtime runtime, Architecture arch, bool installer, int count, string installedVersion = null, string runtimeVersion = null)
public Task<List<UpdateFileEntity>> Find(string branch, OperatingSystem os, Runtime runtime, Architecture arch, bool installer, int count, string installedVersion = null, string runtimeVersion = null, bool excludeMajorVersions = false)
{
runtime = SetRuntime(runtime);
arch = SetArch(runtime, arch, os);
os = SetOs(runtime, os);
var maxVersion = GetMaxVersion(installedVersion, os, runtime, runtimeVersion);
var maxVersion = GetMaxVersion(installedVersion, os, runtime, runtimeVersion, excludeMajorVersions);
var mappedBranch = GetMappedBranch(branch);

return _repo.Find(mappedBranch, os, runtime, arch, installer, count, maxVersion);
Expand Down Expand Up @@ -96,37 +96,39 @@ private OperatingSystem SetOs(Runtime runtime, OperatingSystem os)
return os;
}

private Version GetMaxVersion(string currentVersion, OperatingSystem os, Runtime runtime, string runtimeVersion)
private Version GetMaxVersion(string currentVersion, OperatingSystem os, Runtime runtime, string runtimeVersion, bool excludeMajorVersions)
{
var bounds = new List<Version>();

if (!string.IsNullOrWhiteSpace(currentVersion))
if (!string.IsNullOrWhiteSpace(currentVersion) &&
Version.TryParse(currentVersion, out var installedVersion))
{
var installedVersion = new Version(currentVersion);
var maxVersion = _config.VersionGates.OrderBy(x => x.MaxVersion).FirstOrDefault(x => installedVersion <= x.MaxVersion)?.MaxUpgradeVersion;
if (maxVersion != null)
{
bounds.Add(maxVersion);
}

if (excludeMajorVersions)
{
bounds.Add(new Version(installedVersion.Major, 99, 99, 999_999));
}
}

// We override mono runtime to dotnet earlier, so check for dotnet and not windows
if (runtime == Runtime.DotNet && os != OperatingSystem.Windows && !string.IsNullOrWhiteSpace(runtimeVersion))
if (runtime == Runtime.DotNet &&
os != OperatingSystem.Windows &&
!string.IsNullOrWhiteSpace(runtimeVersion) &&
Version.TryParse(runtimeVersion, out var monoVersion))
{
var monoVersion = new Version(runtimeVersion);
var maxVersion = _config.MonoGates.OrderBy(x => x.MonoVersion).FirstOrDefault(x => monoVersion <= x.MonoVersion)?.MaxUpgradeVersion;
if (maxVersion != null)
{
bounds.Add(maxVersion);
}
}

if (bounds.Any())
{
return bounds.Min();
}

return null;
return bounds.Any() ? bounds.Min() : null;
}

private string GetMappedBranch(string branch)
Expand Down