Skip to content

Commit

Permalink
feat: ✨ Added the ability to specify which branch you are on
Browse files Browse the repository at this point in the history
Currently this will only affect the update check on the settings page, this will not switch builds for you
  • Loading branch information
tidusjar committed Oct 7, 2021
1 parent ba1bec9 commit 777ed2f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 21 deletions.
34 changes: 20 additions & 14 deletions src/Ombi.Schedule/Processor/ChangeLogProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,31 @@
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<OmbiSettings> _ombiSettingsService;

public ChangeLogProcessor(ISettingsService<OmbiSettings> 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<UpdateModel> Process()
{
var release = new Release
{
Downloads = new List<Downloads>()
};
var settings = _ombiSettingsService.GetSettingsAsync();
await GetGitubRelease(release, settings);

await GetGitubRelease(release);

return TransformUpdate(release);
}

Expand All @@ -50,7 +48,7 @@ private UpdateModel TransformUpdate(Release release)
ChangeLogs = release.Description,
Downloads = new List<Downloads>(),
UpdateAvailable = release.Version != "v" + AssemblyHelper.GetRuntimeVersion()
};
};

foreach (var dl in release.Downloads)
{
Expand All @@ -64,12 +62,20 @@ private UpdateModel TransformUpdate(Release release)
return newUpdate;
}

private async Task GetGitubRelease(Release release)
private async Task GetGitubRelease(Release release, Task<OmbiSettings> 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)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Ombi.Settings/Settings/Models/OmbiSettings.cs
Original file line number Diff line number Diff line change
@@ -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; }
Expand All @@ -12,9 +12,16 @@ public class OmbiSettings : Models.Settings
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,
}
}
6 changes: 6 additions & 0 deletions src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@

</mat-form-field>
</div>
<div>
<mat-form-field>
<mat-select placeholder="Branch" formControlName="branch" matTooltip="This will not update your current version, but only control the update checks on the About page">
<mat-option [value]="Branch.Stable">
Stable
</mat-option>
<mat-option [value]="Branch.Develop">
Develop
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div>
<mat-slide-toggle formControlName="doNotSendNotificationsForAutoApprove">
Do not send Notifications if a User has the Auto Approve permission</mat-slide-toggle>
Expand Down
6 changes: 4 additions & 2 deletions src/Ombi/ClientApp/src/app/settings/ombi/ombi.component.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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,
Expand All @@ -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 = <ILanguageRefine[]>languageData
Expand Down
8 changes: 4 additions & 4 deletions src/Ombi/Ombi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@

<ItemGroup>
<Content Remove="$(SpaRoot)**" />
<Content Remove="Controllers\External\**" />
<None Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>

<ItemGroup>
<!-- Files not to show in IDE -->
<Compile Remove="Controllers\External\**" />
<Compile Remove="Logs\**" />
<Compile Remove="Styles\**" />
<Compile Remove="wwwroot\dist\**" />
Expand All @@ -39,9 +41,11 @@
<Content Remove="Logs\**" />
<Content Remove="Styles\**" />
<Content Remove="wwwroot\dist\**" />
<EmbeddedResource Remove="Controllers\External\**" />
<EmbeddedResource Remove="Logs\**" />
<EmbeddedResource Remove="Styles\**" />
<EmbeddedResource Remove="wwwroot\dist\**" />
<None Remove="Controllers\External\**" />
<None Remove="Logs\**" />
<None Remove="Styles\**" />
<None Remove="wwwroot\dist\**" />
Expand Down Expand Up @@ -99,10 +103,6 @@
<ProjectReference Include="..\Ombi.Updater\Ombi.Updater.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\External\" />
</ItemGroup>


<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<Exec Command="node --version" ContinueOnError="true">
Expand Down

0 comments on commit 777ed2f

Please sign in to comment.