@ -10,33 +10,31 @@ using Octokit;
using Ombi.Api ;
using Ombi.Api ;
using Ombi.Api.Service ;
using Ombi.Api.Service ;
using Ombi.Core.Processor ;
using Ombi.Core.Processor ;
using Ombi.Core.Settings ;
using Ombi.Helpers ;
using Ombi.Helpers ;
using Ombi.Settings.Settings.Models ;
using Branch = Ombi . Settings . Settings . Models . Branch ;
namespace Ombi.Schedule.Processor
namespace Ombi.Schedule.Processor
{
{
public class ChangeLogProcessor : IChangeLogProcessor
public class ChangeLogProcessor : IChangeLogProcessor
{
{
public ChangeLogProcessor ( IApi api , IHttpClientFactory client )
private readonly ISettingsService < OmbiSettings > _ombiSettingsService ;
public ChangeLogProcessor ( ISettingsService < OmbiSettings > ombiSettings )
{
{
_api = api ;
_ombiSettingsService = ombiSettings ;
_client = client . CreateClient ( "OmbiClient" ) ;
}
}
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 ( )
public async Task < UpdateModel > Process ( )
{
{
var release = new Release
var release = new Release
{
{
Downloads = new List < Downloads > ( )
Downloads = new List < Downloads > ( )
} ;
} ;
var settings = _ombiSettingsService . GetSettingsAsync ( ) ;
await GetGitubRelease ( release , settings ) ;
await GetGitubRelease ( release ) ;
return TransformUpdate ( release ) ;
return TransformUpdate ( release ) ;
}
}
@ -50,7 +48,7 @@ namespace Ombi.Schedule.Processor
ChangeLogs = release . Description ,
ChangeLogs = release . Description ,
Downloads = new List < Downloads > ( ) ,
Downloads = new List < Downloads > ( ) ,
UpdateAvailable = release . Version ! = "v" + AssemblyHelper . GetRuntimeVersion ( )
UpdateAvailable = release . Version ! = "v" + AssemblyHelper . GetRuntimeVersion ( )
} ;
} ;
foreach ( var dl in release . Downloads )
foreach ( var dl in release . Downloads )
{
{
@ -64,12 +62,20 @@ namespace Ombi.Schedule.Processor
return newUpdate ;
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 client = new GitHubClient ( Octokit . ProductHeaderValue . Parse ( "OmbiV4" ) ) ;
var releases = await client . Repository . Release . GetAll ( "ombi-app" , "ombi" ) ;
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 )
foreach ( var item in latest . Assets )
{
{