Skip to content

Commit c01bcc7

Browse files
Pull from upstream master
2 parents 9363fb0 + 892264a commit c01bcc7

17 files changed

Lines changed: 175 additions & 203 deletions

RadarrAPI.sln

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26403.3
4+
VisualStudioVersion = 15.0.26730.16
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RadarrAPI", "RadarrAPI\RadarrAPI.csproj", "{A2E9D642-2A33-464E-8330-135B3BA6B8BF}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RadarrAPI", "RadarrAPI\RadarrAPI.csproj", "{100DDF07-706D-4428-9F8A-B81A6791B60D}"
77
EndProject
88
Global
9+
GlobalSection(SolutionProperties) = preSolution
10+
HideSolutionNode = FALSE
11+
EndGlobalSection
12+
GlobalSection(ExtensibilityGlobals) = postSolution
13+
SolutionGuid = {967AD9C3-A215-4168-B591-67900BEFAB7D}
14+
EndGlobalSection
915
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1016
Debug|Any CPU = Debug|Any CPU
11-
Debug|x64 = Debug|x64
12-
Debug|x86 = Debug|x86
1317
Release|Any CPU = Release|Any CPU
14-
Release|x64 = Release|x64
15-
Release|x86 = Release|x86
1618
EndGlobalSection
1719
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
20-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Debug|x64.ActiveCfg = Debug|Any CPU
21-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Debug|x64.Build.0 = Debug|Any CPU
22-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Debug|x86.ActiveCfg = Debug|Any CPU
23-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Debug|x86.Build.0 = Debug|Any CPU
24-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
25-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Release|Any CPU.Build.0 = Release|Any CPU
26-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Release|x64.ActiveCfg = Release|Any CPU
27-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Release|x64.Build.0 = Release|Any CPU
28-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Release|x86.ActiveCfg = Release|Any CPU
29-
{A2E9D642-2A33-464E-8330-135B3BA6B8BF}.Release|x86.Build.0 = Release|Any CPU
30-
EndGlobalSection
31-
GlobalSection(SolutionProperties) = preSolution
32-
HideSolutionNode = FALSE
20+
{100DDF07-706D-4428-9F8A-B81A6791B60D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{100DDF07-706D-4428-9F8A-B81A6791B60D}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{100DDF07-706D-4428-9F8A-B81A6791B60D}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{100DDF07-706D-4428-9F8A-B81A6791B60D}.Release|Any CPU.Build.0 = Release|Any CPU
3324
EndGlobalSection
3425
EndGlobal

RadarrAPI/Controllers/UpdateController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.EntityFrameworkCore;
66
using RadarrAPI.Database;
7-
using RadarrAPI.Update;
87
using RadarrAPI.Update.Data;
98
using StatsdClient;
109
using Branch = RadarrAPI.Update.Branch;
10+
using OperatingSystem = RadarrAPI.Update.OperatingSystem;
1111

1212
namespace RadarrAPI.Controllers
1313
{

RadarrAPI/Controllers/WebhookController.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc;
23
using Microsoft.Extensions.Options;
34
using RadarrAPI.Release;
45
using RadarrAPI.Update;
@@ -9,6 +10,7 @@ namespace RadarrAPI.Controllers
910
public class WebhookController
1011
{
1112
private readonly ReleaseService _releaseService;
13+
1214
private readonly Config _config;
1315

1416
public WebhookController(ReleaseService releaseService, IOptions<Config> optionsConfig)
@@ -19,14 +21,14 @@ public WebhookController(ReleaseService releaseService, IOptions<Config> options
1921

2022
[Route("refresh")]
2123
[HttpGet, HttpPost]
22-
public string Refresh([FromQuery] Branch branch, [FromQuery(Name = "api_key")] string apiKey)
24+
public async Task<string> Refresh([FromQuery] Branch branch, [FromQuery(Name = "api_key")] string apiKey)
2325
{
2426
if (!_config.ApiKey.Equals(apiKey))
2527
{
2628
return "No, thank you.";
2729
}
2830

29-
_releaseService.UpdateReleases(branch);
31+
await _releaseService.UpdateReleasesAsync(branch);
3032

3133
return "Thank you.";
3234
}

RadarrAPI/Database/DatabaseContext.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.EntityFrameworkCore.Metadata;
32
using RadarrAPI.Database.Models;
43

54
namespace RadarrAPI.Database
65
{
76
public class DatabaseContext : DbContext
87
{
9-
108
public DatabaseContext(DbContextOptions options) : base(options)
119
{
1210
}

RadarrAPI/Program.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
using System.IO;
1+
using Microsoft.AspNetCore;
22
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Logging;
34

45
namespace RadarrAPI
56
{
67
public class Program
78
{
89
public static void Main(string[] args)
910
{
10-
var host = new WebHostBuilder()
11-
.UseKestrel()
12-
.UseContentRoot(Directory.GetCurrentDirectory())
13-
.UseIISIntegration()
11+
BuildWebHost(args).Run();
12+
}
13+
14+
private static IWebHost BuildWebHost(string[] args) =>
15+
WebHost.CreateDefaultBuilder(args)
1416
.UseStartup<Startup>()
17+
.ConfigureLogging(builder =>
18+
{
19+
builder.ClearProviders();
20+
})
1521
.Build();
16-
17-
host.Run();
18-
}
1922
}
20-
}
23+
}

RadarrAPI/Properties/launchSettings.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

RadarrAPI/RadarrAPI.csproj

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
32
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1</TargetFramework>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
54
</PropertyGroup>
5+
<ItemGroup>
6+
<Folder Include="wwwroot\" />
7+
</ItemGroup>
68
<ItemGroup>
79
<PackageReference Include="DogStatsD-CSharp-Client" Version="3.0.0" />
8-
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
9-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
11-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
12-
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0-rtm-beta3" />
13-
<PackageReference Include="NLog.Web.AspNetCore" Version="4.4.0" />
14-
<PackageReference Include="Octokit" Version="0.24.1-alpha0001" />
15-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.2" />
16-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
17-
<PackageReference Include="TraktApiSharp" Version="1.0.0-alpha1" />
10+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
11+
<PackageReference Include="NLog" Version="5.0.0-beta11" />
12+
<PackageReference Include="NLog.Web.AspNetCore" Version="4.4.1" />
13+
<PackageReference Include="Octokit" Version="0.26.0" />
14+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1-preview-10066" />
15+
<PackageReference Include="TraktApiSharp" Version="1.0.0-alpha2" />
1816
</ItemGroup>
1917
<ItemGroup>
20-
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
21-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" />
18+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
19+
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
2220
</ItemGroup>
2321
<ItemGroup>
2422
<Content Update="appsettings.json">
@@ -30,11 +28,8 @@
3028
<Content Update="appsettings.Development.json">
3129
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3230
</Content>
33-
</ItemGroup>
34-
<ItemGroup>
35-
<None Update="nlog.config">
31+
<Content Update="nlog.config">
3632
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
37-
</None>
33+
</Content>
3834
</ItemGroup>
39-
40-
</Project>
35+
</Project>

RadarrAPI/Release/AppVeyor/AppVeyorReleaseSource.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Options;
1111
using Newtonsoft.Json;
12-
using NLog;
1312
using RadarrAPI.Database;
1413
using RadarrAPI.Release.AppVeyor.Responses;
1514
using RadarrAPI.Update;
1615
using Microsoft.EntityFrameworkCore;
1716
using RadarrAPI.Database.Models;
17+
using OperatingSystem = RadarrAPI.Update.OperatingSystem;
1818

1919
namespace RadarrAPI.Release.AppVeyor
2020
{
@@ -23,35 +23,44 @@ public class AppVeyorReleaseSource : ReleaseSourceBase
2323
private const string AccountName = "lidarr";
2424
private const string ProjectSlug = "lidarr";
2525

26+
private static int? _lastBuildId;
27+
28+
private readonly DatabaseContext _database;
29+
30+
private readonly Config _config;
31+
2632
private readonly HttpClient _httpClient;
2733

2834
private readonly HttpClient _downloadHttpClient;
2935

30-
private int? _lastBuildId;
31-
32-
public AppVeyorReleaseSource(IServiceProvider serviceProvider, Branch branch) : base(serviceProvider, branch)
36+
public AppVeyorReleaseSource(DatabaseContext database, IOptions<Config> config)
3337
{
34-
var config = serviceProvider.GetService<IOptions<Config>>().Value;
38+
_database = database;
39+
_config = config.Value;
3540

3641
_httpClient = new HttpClient();
3742
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
38-
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", config.AppVeyorApiKey);
43+
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _config.AppVeyorApiKey);
3944

4045
_downloadHttpClient = new HttpClient();
4146
}
4247

4348
protected override async Task DoFetchReleasesAsync()
4449
{
50+
if (ReleaseBranch == Branch.Unknown)
51+
{
52+
throw new ArgumentException("ReleaseBranch must not be unknown when fetching releases.");
53+
}
54+
4555
var historyUrl = $"https://ci.appveyor.com/api/projects/{AccountName}/{ProjectSlug}/history?recordsNumber=10&branch=develop";
4656

4757
var historyData = await _httpClient.GetStringAsync(historyUrl);
4858
var history = JsonConvert.DeserializeObject<AppVeyorProjectHistory>(historyData);
4959

5060
// Store here temporarily so we don't break on not processed builds.
5161
var lastBuild = _lastBuildId;
52-
var database = ServiceProvider.GetService<DatabaseContext>();
5362

54-
foreach (var build in history.Builds)
63+
foreach (var build in history.Builds.Take(5).ToList()) // Only take last 5.
5564
{
5665
if (lastBuild.HasValue &&
5766
lastBuild.Value >= build.BuildId) break;
@@ -78,7 +87,7 @@ protected override async Task DoFetchReleasesAsync()
7887
var artifacts = JsonConvert.DeserializeObject<AppVeyorArtifact[]>(artifactsData);
7988

8089
// Get an updateEntity
81-
var updateEntity = database.UpdateEntities
90+
var updateEntity = _database.UpdateEntities
8291
.Include(x => x.UpdateFiles)
8392
.FirstOrDefault(x => x.Version.Equals(buildExtended.Version) && x.Branch.Equals(ReleaseBranch));
8493

@@ -103,7 +112,7 @@ protected override async Task DoFetchReleasesAsync()
103112
}
104113

105114
// Start tracking this object
106-
await database.AddAsync(updateEntity);
115+
await _database.AddAsync(updateEntity);
107116
}
108117

109118
// Process artifacts
@@ -130,7 +139,7 @@ protected override async Task DoFetchReleasesAsync()
130139
}
131140

132141
// Check if exists in database.
133-
var updateFileEntity = database.UpdateFileEntities
142+
var updateFileEntity = _database.UpdateFileEntities
134143
.FirstOrDefault(x =>
135144
x.UpdateEntityId == updateEntity.UpdateEntityId &&
136145
x.OperatingSystem == operatingSystem);
@@ -140,7 +149,7 @@ protected override async Task DoFetchReleasesAsync()
140149
// Calculate the hash of the zip file.
141150
var releaseDownloadUrl = $"{artifactsPath}/{artifact.FileName}";
142151
var releaseFileName = artifact.FileName.Split('/').Last();
143-
var releaseZip = Path.Combine(Config.DataDirectory, ReleaseBranch.ToString(), releaseFileName);
152+
var releaseZip = Path.Combine(_config.DataDirectory, ReleaseBranch.ToString(), releaseFileName);
144153
string releaseHash;
145154

146155
if (!File.Exists(releaseZip))
@@ -170,7 +179,7 @@ protected override async Task DoFetchReleasesAsync()
170179
}
171180

172181
// Save all changes to the database.
173-
await database.SaveChangesAsync();
182+
await _database.SaveChangesAsync();
174183

175184
// Make sure we atleast skip this build next time.
176185
if (_lastBuildId == null ||

0 commit comments

Comments
 (0)