From 61f3e94308fb3d239140b73d34c12f1496459989 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 7 Oct 2021 16:36:42 +0100 Subject: [PATCH] feat: :sparkles: Added the ability to specify which branch you are on Currently this will only affect the update check on the settings page, this will not switch builds for you --- .../Processor/ChangeLogProcessor.cs | 34 +++++++++++-------- .../Settings/Models/OmbiSettings.cs | 9 ++++- .../ClientApp/src/app/interfaces/ISettings.ts | 6 ++++ .../src/app/settings/ombi/ombi.component.html | 12 +++++++ .../src/app/settings/ombi/ombi.component.ts | 6 ++-- src/Ombi/Ombi.csproj | 8 ++--- 6 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/Ombi.Schedule/Processor/ChangeLogProcessor.cs b/src/Ombi.Schedule/Processor/ChangeLogProcessor.cs index cffb5e508..0368984dd 100644 --- a/src/Ombi.Schedule/Processor/ChangeLogProcessor.cs +++ b/src/Ombi.Schedule/Processor/ChangeLogProcessor.cs @@ -10,33 +10,31 @@ using Octokit; using Ombi.Api; using Ombi.Api.Service; using Ombi.Core.Processor; +using Ombi.Core.Settings; using Ombi.Helpers; +using Ombi.Settings.Settings.Models; +using Branch = Ombi.Settings.Settings.Models.Branch; namespace Ombi.Schedule.Processor { public class ChangeLogProcessor : IChangeLogProcessor { - public ChangeLogProcessor(IApi api, IHttpClientFactory client) + private readonly ISettingsService _ombiSettingsService; + + public ChangeLogProcessor(ISettingsService ombiSettings) { - _api = api; - _client = client.CreateClient("OmbiClient"); + _ombiSettingsService = ombiSettings; } - private readonly IApi _api; - private readonly HttpClient _client; - private const string _changeLogUrl = "https://raw.githubusercontent.com/tidusjar/Ombi/{0}/CHANGELOG.md"; - private const string AppveyorApiUrl = "https://ci.appveyor.com/api"; - private string ChangeLogUrl(string branch) => string.Format(_changeLogUrl, branch); - public async Task Process() { var release = new Release { Downloads = new List() }; + var settings = _ombiSettingsService.GetSettingsAsync(); + await GetGitubRelease(release, settings); - await GetGitubRelease(release); - return TransformUpdate(release); } @@ -50,7 +48,7 @@ namespace Ombi.Schedule.Processor ChangeLogs = release.Description, Downloads = new List(), UpdateAvailable = release.Version != "v" + AssemblyHelper.GetRuntimeVersion() - }; + }; foreach (var dl in release.Downloads) { @@ -64,12 +62,20 @@ namespace Ombi.Schedule.Processor return newUpdate; } - private async Task GetGitubRelease(Release release) + private async Task GetGitubRelease(Release release, Task settingsTask) { var client = new GitHubClient(Octokit.ProductHeaderValue.Parse("OmbiV4")); var releases = await client.Repository.Release.GetAll("ombi-app", "ombi"); - var latest = releases.OrderByDescending(x => x.CreatedAt).FirstOrDefault(); + + var settings = await settingsTask; + + var latest = settings.Branch switch + { + Branch.Develop => releases.Where(x => x.Prerelease).OrderByDescending(x => x.CreatedAt).FirstOrDefault(), + Branch.Stable => releases.Where(x => !x.Prerelease).OrderByDescending(x => x.CreatedAt).FirstOrDefault(), + _ => throw new NotImplementedException(), + }; foreach (var item in latest.Assets) { diff --git a/src/Ombi.Settings/Settings/Models/OmbiSettings.cs b/src/Ombi.Settings/Settings/Models/OmbiSettings.cs index 6c622f2ce..ba460a2bd 100644 --- a/src/Ombi.Settings/Settings/Models/OmbiSettings.cs +++ b/src/Ombi.Settings/Settings/Models/OmbiSettings.cs @@ -1,6 +1,6 @@ namespace Ombi.Settings.Settings.Models { - public class OmbiSettings : Models.Settings + public class OmbiSettings : Settings { public string BaseUrl { get; set; } public bool CollectAnalyticData { get; set; } @@ -12,9 +12,16 @@ public string DefaultLanguageCode { get; set; } = "en"; public bool AutoDeleteAvailableRequests { get; set; } public int AutoDeleteAfterDays { get; set; } + public Branch Branch { get; set; } //INTERNAL public bool HasMigratedOldTvDbData { get; set; } public bool Set { get; set; } } + + public enum Branch + { + Develop = 0, + Stable = 1, + } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts index 841ff2d86..c4a57154d 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts @@ -18,6 +18,12 @@ export interface IOmbiSettings extends ISettings { disableHealthChecks: boolean; autoDeleteAvailableRequests: boolean; autoDeleteAfterDays: number; + branch: Branch; +} + +export enum Branch { + Stable = 0, + Develop = 1 } export interface IUpdateSettings extends ISettings { diff --git a/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.html b/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.html index ccdb57cb2..a575c24a7 100644 --- a/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.html +++ b/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.html @@ -21,6 +21,18 @@ +
+ + + + Stable + + + Develop + + + +
Do not send Notifications if a User has the Auto Approve permission diff --git a/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.ts b/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.ts index 9681784b4..f797703bc 100644 --- a/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from "@angular/core"; import { FormBuilder, FormGroup } from "@angular/forms"; -import { ILanguageRefine, IOmbiSettings } from "../../interfaces"; +import { Branch, ILanguageRefine, IOmbiSettings } from "../../interfaces"; import { NotificationService } from "../../services"; import { SettingsService } from "../../services"; @@ -15,6 +15,7 @@ export class OmbiComponent implements OnInit { public form: FormGroup; public langauges: ILanguageRefine[]; + public Branch = Branch; constructor(private settingsService: SettingsService, private notificationService: NotificationService, @@ -31,7 +32,8 @@ export class OmbiComponent implements OnInit { defaultLanguageCode: [x.defaultLanguageCode], disableHealthChecks: [x.disableHealthChecks], autoDeleteAvailableRequests: [x.autoDeleteAvailableRequests], - autoDeleteAfterDays: [x.autoDeleteAfterDays] + autoDeleteAfterDays: [x.autoDeleteAfterDays], + branch: [x.branch] }); }); this.langauges = languageData diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index d1545ff36..063dc65db 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -24,12 +24,14 @@ + + @@ -39,9 +41,11 @@ + + @@ -99,10 +103,6 @@ - - - -