@ -10,32 +10,30 @@ 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 < 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 > ( )
} ;
await GetGitubRelease ( release );
var settings = _ombiSettingsService . GetSettingsAsync ( ) ;
await GetGitubRelease ( release , settings );
return TransformUpdate ( release ) ;
}
@ -64,12 +62,20 @@ namespace Ombi.Schedule.Processor
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 )
{