mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-11-26 19:50:36 +00:00
remove appveyor client now that it's no longer used
This commit is contained in:
parent
b9df3f4901
commit
c835deb6a6
@ -1,16 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CompatApiClient\CompatApiClient.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,341 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AppveyorClient.POCOs;
|
||||
using CompatApiClient;
|
||||
using CompatApiClient.Compression;
|
||||
using CompatApiClient.Utils;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json;
|
||||
using JsonContractResolver = CompatApiClient.JsonContractResolver;
|
||||
|
||||
namespace AppveyorClient
|
||||
{
|
||||
public class Client
|
||||
{
|
||||
private readonly HttpClient client;
|
||||
private readonly MediaTypeFormatterCollection formatters;
|
||||
|
||||
private static readonly TimeSpan CacheTime = TimeSpan.FromDays(1);
|
||||
private static readonly TimeSpan PrToArtifactCacheTime = TimeSpan.FromMinutes(1);
|
||||
private static readonly TimeSpan JobToBuildCacheTime = TimeSpan.FromDays(30);
|
||||
private static readonly TimeSpan MasterBuildCacheTime = TimeSpan.FromDays(1);
|
||||
private static readonly TimeSpan JobIdSearchThreshold = TimeSpan.FromDays(6 * 30);
|
||||
private static readonly MemoryCache ResponseCache = new MemoryCache(new MemoryCacheOptions {ExpirationScanFrequency = TimeSpan.FromMinutes(5)});
|
||||
|
||||
public Client()
|
||||
{
|
||||
client = HttpClientFactory.Create(new CompressionMessageHandler());
|
||||
var settings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new JsonContractResolver(NamingStyles.CamelCase),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
formatters = new MediaTypeFormatterCollection(new[] {new JsonMediaTypeFormatter {SerializerSettings = settings}});
|
||||
}
|
||||
|
||||
public async Task<ArtifactInfo> GetPrDownloadAsync(string githubStatusTargetUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var buildUrl = githubStatusTargetUrl.Replace("ci.appveyor.com/project/", "ci.appveyor.com/api/projects/");
|
||||
if (buildUrl == githubStatusTargetUrl)
|
||||
{
|
||||
ApiConfig.Log.Warn("Unexpected AppVeyor link: " + githubStatusTargetUrl);
|
||||
return null;
|
||||
}
|
||||
|
||||
var buildInfo = await GetBuildInfoAsync(buildUrl, cancellationToken).ConfigureAwait(false);
|
||||
var job = buildInfo?.Build.Jobs?.FirstOrDefault(j => j.Status == "success");
|
||||
if (string.IsNullOrEmpty(job?.JobId))
|
||||
return null;
|
||||
|
||||
var artifacts = await GetJobArtifactsAsync(job.JobId, cancellationToken).ConfigureAwait(false);
|
||||
var rpcs3Build = artifacts?.FirstOrDefault(a => a.Name == "rpcs3");
|
||||
if (rpcs3Build == null)
|
||||
return null;
|
||||
|
||||
var result = new ArtifactInfo
|
||||
{
|
||||
Artifact = rpcs3Build,
|
||||
DownloadUrl = $"https://ci.appveyor.com/api/buildjobs/{job.JobId}/artifacts/{rpcs3Build.FileName}",
|
||||
};
|
||||
ResponseCache.Set(githubStatusTargetUrl, result, CacheTime);
|
||||
ApiConfig.Log.Debug($"Cached item for {githubStatusTargetUrl} for {CacheTime}");
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
if (ResponseCache.TryGetValue(githubStatusTargetUrl, out ArtifactInfo o))
|
||||
ApiConfig.Log.Debug($"Returned cached item for {githubStatusTargetUrl}");
|
||||
return o;
|
||||
}
|
||||
|
||||
public async Task<ArtifactInfo> GetPrDownloadAsync(int prNumber, DateTime dateTimeLimit, CancellationToken cancellationToken)
|
||||
{
|
||||
if (ResponseCache.TryGetValue(prNumber, out ArtifactInfo result))
|
||||
{
|
||||
ApiConfig.Log.Debug($"Returned cached {nameof(ArtifactInfo)} for {prNumber}");
|
||||
return result;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var build = await FindBuildAsync(
|
||||
historyPage => historyPage.Builds.Last(b => b.Started.HasValue).Started?.ToUniversalTime() > dateTimeLimit,
|
||||
b => b.PullRequestId == prNumber && b.Status == "success",
|
||||
cancellationToken
|
||||
).ConfigureAwait(false);
|
||||
if (build == null)
|
||||
{
|
||||
ApiConfig.Log.Debug($"Couldn't find successful build for PR {prNumber} in appveyor history");
|
||||
return null;
|
||||
}
|
||||
|
||||
var buildInfo = await GetBuildInfoAsync(build.BuildId, cancellationToken).ConfigureAwait(false);
|
||||
var job = buildInfo?.Build.Jobs?.FirstOrDefault(j => j.Status == "success");
|
||||
if (string.IsNullOrEmpty(job?.JobId))
|
||||
{
|
||||
ApiConfig.Log.Debug($"No successful {nameof(Job.JobId)}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var artifacts = await GetJobArtifactsAsync(job.JobId, cancellationToken).ConfigureAwait(false);
|
||||
var rpcs3Build = artifacts?.FirstOrDefault(a => a.Name == "rpcs3");
|
||||
if (rpcs3Build == null)
|
||||
{
|
||||
ApiConfig.Log.Debug("No rpcs3 artifacts");
|
||||
return null;
|
||||
}
|
||||
|
||||
result = new ArtifactInfo
|
||||
{
|
||||
Artifact = rpcs3Build,
|
||||
DownloadUrl = $"https://ci.appveyor.com/api/buildjobs/{job.JobId}/artifacts/{rpcs3Build.FileName}",
|
||||
};
|
||||
ResponseCache.Set(prNumber, result, PrToArtifactCacheTime);
|
||||
ApiConfig.Log.Debug($"Cached {nameof(ArtifactInfo)} for {prNumber} for {CacheTime}");
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
ApiConfig.Log.Debug($"Failed to get {nameof(ArtifactInfo)} for {prNumber}");
|
||||
return null;
|
||||
}
|
||||
|
||||
public Task<BuildInfo> GetBuildInfoAsync(int buildId, CancellationToken cancellationToken) { return GetBuildInfoAsync("https://ci.appveyor.com/api/projects/rpcs3/rpcs3/builds/" + buildId, cancellationToken); }
|
||||
|
||||
public async Task<BuildInfo> GetBuildInfoAsync(string buildUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var message = new HttpRequestMessage(HttpMethod.Get, buildUrl);
|
||||
message.Headers.UserAgent.Add(ApiConfig.ProductInfoHeader);
|
||||
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
|
||||
var result = await response.Content.ReadAsAsync<BuildInfo>(formatters, cancellationToken).ConfigureAwait(false);
|
||||
ResponseCache.Set(buildUrl, result, CacheTime);
|
||||
//ApiConfig.Log.Debug($"Cached {nameof(BuildInfo)} for {buildUrl} for {CacheTime}");
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleLogger.PrintError(e, response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
if (ResponseCache.TryGetValue(buildUrl, out BuildInfo o))
|
||||
ApiConfig.Log.Debug($"Returning cached {nameof(BuildInfo)} for {buildUrl}");
|
||||
return o;
|
||||
}
|
||||
|
||||
public async Task<Build> GetBuildAsync(string jobId, CancellationToken cancellationToken)
|
||||
{
|
||||
if (ResponseCache.TryGetValue(jobId, out Build result))
|
||||
return result;
|
||||
|
||||
try
|
||||
{
|
||||
var oldestBuildDate = DateTime.UtcNow - JobIdSearchThreshold;
|
||||
return await FindBuildAsync(
|
||||
h => h.Builds.Last().Created?.ToUniversalTime() > oldestBuildDate,
|
||||
b =>
|
||||
{
|
||||
var buildInfo = GetBuildInfoAsync(b.BuildId, cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
foreach (var j in buildInfo?.Build?.Jobs ?? Enumerable.Empty<Job>())
|
||||
{
|
||||
ResponseCache.Set(j.JobId, b, JobToBuildCacheTime);
|
||||
#if DEBUG
|
||||
//ApiConfig.Log.Debug($"Cached {b.GetType().Name} for {j.JobId}");
|
||||
#endif
|
||||
}
|
||||
return buildInfo?.Build?.Jobs?.Any(j => j.JobId == jobId) ?? false;
|
||||
},
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
ApiConfig.Log.Debug($"Failed to find {nameof(Build)} for job {jobId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<List<Artifact>> GetJobArtifactsAsync(string jobId, CancellationToken cancellationToken)
|
||||
{
|
||||
var requestUri = $"https://ci.appveyor.com/api/buildjobs/{jobId}/artifacts";
|
||||
try
|
||||
{
|
||||
using var message = new HttpRequestMessage(HttpMethod.Get, requestUri);
|
||||
message.Headers.UserAgent.Add(ApiConfig.ProductInfoHeader);
|
||||
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
|
||||
var result = await response.Content.ReadAsAsync<List<Artifact>>(formatters, cancellationToken).ConfigureAwait(false);
|
||||
ResponseCache.Set(requestUri, result, CacheTime);
|
||||
ApiConfig.Log.Debug($"Cached {nameof(Artifact)} for {jobId} for {CacheTime}");
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleLogger.PrintError(e, response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
if (ResponseCache.TryGetValue(requestUri, out List<Artifact> o))
|
||||
ApiConfig.Log.Debug($"Returning cached {nameof(Artifact)} for {jobId}");
|
||||
return o;
|
||||
}
|
||||
|
||||
public async Task<Build> GetMasterBuildAsync(string commit, DateTime? mergeDate, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrEmpty(commit))
|
||||
return null;
|
||||
|
||||
if (ResponseCache.TryGetValue(commit, out Build result))
|
||||
return result;
|
||||
|
||||
try
|
||||
{
|
||||
mergeDate ??= DateTime.UtcNow - JobIdSearchThreshold;
|
||||
result = await FindBuildAsync(
|
||||
h => h.Builds.Last().Created?.ToUniversalTime() > mergeDate,
|
||||
b => b.CommitId.StartsWith(commit, StringComparison.InvariantCultureIgnoreCase) && b.Status == "success",
|
||||
cancellationToken
|
||||
);
|
||||
if (result != null)
|
||||
ResponseCache.Set(commit, result, MasterBuildCacheTime);
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
ApiConfig.Log.Debug($"Failed to find master {nameof(Build)} for commit {commit}");
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<List<Build>> GetMasterBuildsAsync(string oldestPrCommit, string newestPrCommit, DateTime? oldestDateTime, CancellationToken cancellationToken)
|
||||
{
|
||||
var emptyList = new List<Build>();
|
||||
if (string.IsNullOrEmpty(oldestPrCommit))
|
||||
return emptyList;
|
||||
|
||||
oldestDateTime ??= DateTime.UtcNow - MasterBuildCacheTime;
|
||||
try
|
||||
{
|
||||
var baseUrl = new Uri("https://ci.appveyor.com/api/projects/rpcs3/RPCS3/history?recordsNumber=100");
|
||||
var historyUrl = baseUrl;
|
||||
HistoryInfo historyPage = null;
|
||||
var builds = new List<Build>(10);
|
||||
bool hasOldestBuild = false;
|
||||
do
|
||||
{
|
||||
using var message = new HttpRequestMessage(HttpMethod.Get, historyUrl);
|
||||
message.Headers.UserAgent.Add(ApiConfig.ProductInfoHeader);
|
||||
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
|
||||
historyPage = await response.Content.ReadAsAsync<HistoryInfo>(formatters, cancellationToken).ConfigureAwait(false);
|
||||
var buildsOnPage = historyPage?.Builds?.Where(b => b.Branch == "master" && b.IsTag == false) ?? emptyList;
|
||||
hasOldestBuild = buildsOnPage.Any(b => b.CommitId.StartsWith(oldestPrCommit, StringComparison.InvariantCultureIgnoreCase));
|
||||
builds.AddRange(buildsOnPage);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleLogger.PrintError(e, response);
|
||||
break;
|
||||
}
|
||||
historyUrl = baseUrl.SetQueryParameter("startBuildId", historyPage?.Builds?.Last().BuildId.ToString());
|
||||
} while (!hasOldestBuild && historyPage?.Builds?.Count > 0);
|
||||
return builds
|
||||
.SkipWhile(b => !b.CommitId.StartsWith(newestPrCommit, StringComparison.InvariantCultureIgnoreCase))
|
||||
.Skip(1)
|
||||
.TakeWhile(b => !b.CommitId.StartsWith(oldestPrCommit, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
ApiConfig.Log.Debug($"Failed to find master {nameof(Build)}s between commits {oldestPrCommit} and {newestPrCommit}");
|
||||
return emptyList;
|
||||
}
|
||||
|
||||
public async Task<Build> FindBuildAsync(Func<HistoryInfo, bool> takePredicate, Func<Build, bool> selectPredicate, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var baseUrl = new Uri("https://ci.appveyor.com/api/projects/rpcs3/RPCS3/history?recordsNumber=100");
|
||||
var historyUrl = baseUrl;
|
||||
HistoryInfo historyPage = null;
|
||||
Build build = null;
|
||||
do
|
||||
{
|
||||
using var message = new HttpRequestMessage(HttpMethod.Get, historyUrl);
|
||||
message.Headers.UserAgent.Add(ApiConfig.ProductInfoHeader);
|
||||
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
|
||||
historyPage = await response.Content.ReadAsAsync<HistoryInfo>(formatters, cancellationToken).ConfigureAwait(false);
|
||||
build = historyPage?.Builds?.FirstOrDefault(selectPredicate);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleLogger.PrintError(e, response);
|
||||
break;
|
||||
}
|
||||
historyUrl = baseUrl.SetQueryParameter("startBuildId", historyPage?.Builds?.Last().BuildId.ToString());
|
||||
} while (build == null && historyPage?.Builds?.Count > 0 && takePredicate(historyPage));
|
||||
return build;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ApiConfig.Log.Error(e);
|
||||
}
|
||||
ApiConfig.Log.Debug($"Failed to find {nameof(Build)}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class Artifact
|
||||
{
|
||||
public DateTime? Created;
|
||||
public string FileName;
|
||||
public string Name;
|
||||
public long Size;
|
||||
public string Type;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class ArtifactInfo
|
||||
{
|
||||
public Artifact Artifact;
|
||||
public string DownloadUrl;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class Build
|
||||
{
|
||||
public string AuthorName;
|
||||
public string AuthorUsername;
|
||||
public string Branch;
|
||||
public bool IsTag;
|
||||
public int BuildId;
|
||||
public int BuildNumber;
|
||||
public DateTime? Created;
|
||||
public DateTime? Started;
|
||||
public DateTime? Updated;
|
||||
public DateTime? Finished;
|
||||
public List<Job> Jobs;
|
||||
public string Message;
|
||||
public string CommitId;
|
||||
public string PullRequestHeadBranch;
|
||||
public string PullRequestHeadCommitId;
|
||||
public string PullRequestHeadRepository;
|
||||
public int PullRequestId;
|
||||
public string PullRequestName;
|
||||
public string Status;
|
||||
public string Version;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class BuildInfo
|
||||
{
|
||||
public Build Build;
|
||||
public Project Project;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class HistoryInfo
|
||||
{
|
||||
public List<Build> Builds;
|
||||
public Project Project;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class Job
|
||||
{
|
||||
public int ArtifactsCount;
|
||||
public int CompilationErrorsCount;
|
||||
public DateTime? Created;
|
||||
public DateTime? Started;
|
||||
public DateTime? Updated;
|
||||
public DateTime? Finished;
|
||||
public string OsType;
|
||||
public string Status;
|
||||
public string JobId;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
namespace AppveyorClient.POCOs
|
||||
{
|
||||
public class Project { }
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
AppVeyor Client
|
||||
===============
|
||||
|
||||
[AppVeyor API documentation](https://www.appveyor.com/docs/api/) for reference. There are some inaccuracies and legacy quirks though. As we use the API for read-only queries, on a publicly available data, we don't need any form of authentication. `User-Agent` header is provided as a courtesy.
|
||||
|
||||
What AppVeyor client is used for, is to get the direct download links for PR builds. For that we need to get the job artifacts. And for that we need job id, which can only be associated with the corresponding GitHub PR through the build info, which we can find in the build history. Phew, easy.
|
||||
|
||||
`FindBuildAsync` is a general history search function that can be used to search through the history until some criteria is met. We use it at startup with the bogus predicate to get and cache the whole history to map job IDs to their build info, which is used for quick lookup when we want to show PR download for direct links.
|
||||
|
||||
`GetMasterBuildAsync` is mainly used to get the build time, as [CompatApi client](../CompatApiClient) provides merge time instead of the build time currently.
|
||||
|
||||
`GetPrDownloadAsync` that accepts `githubStatusTargetUrl` uses `string.Replace()` instead of constructing the url manually because of the legacy quirks. AppVeyor has changed the link format at some point, and there's not backwards compatibility there, so old direct links work only with the old link format.
|
@ -27,7 +27,6 @@ namespace CompatBot.Commands
|
||||
internal sealed class CompatList : BaseCommandModuleCustom
|
||||
{
|
||||
private static readonly Client client = new Client();
|
||||
private static readonly AppveyorClient.Client appveyorClient = new AppveyorClient.Client();
|
||||
private static readonly GithubClient.Client githubClient = new GithubClient.Client();
|
||||
private static readonly SemaphoreSlim updateCheck = new SemaphoreSlim(1, 1);
|
||||
private static string lastUpdateInfo = null;
|
||||
|
@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AppveyorClient.POCOs;
|
||||
using CompatApiClient.Utils;
|
||||
using CompatBot.Commands.Attributes;
|
||||
using CompatBot.Utils;
|
||||
@ -25,7 +24,6 @@ namespace CompatBot.Commands
|
||||
internal sealed class Pr: BaseCommandModuleCustom
|
||||
{
|
||||
private static readonly GithubClient.Client githubClient = new GithubClient.Client();
|
||||
private static readonly AppveyorClient.Client appveyorClient = new AppveyorClient.Client();
|
||||
private static readonly CompatApiClient.Client compatApiClient = new CompatApiClient.Client();
|
||||
private static readonly TimeSpan AvgBuildTime = TimeSpan.FromMinutes(30); // it's 20, but on merge we have pr + master builds
|
||||
private const string appveyorContext = "continuous-integration/appveyor/pr";
|
||||
@ -110,24 +108,7 @@ namespace CompatBot.Commands
|
||||
string linuxDownloadText = null;
|
||||
|
||||
// windows build
|
||||
if (prInfo.StatusesUrl is string statusesUrl)
|
||||
{
|
||||
if (await appveyorClient.GetPrDownloadAsync(prInfo.Number, prInfo.CreatedAt, Config.Cts.Token).ConfigureAwait(false) is ArtifactInfo artifactInfo)
|
||||
{
|
||||
if (artifactInfo.Artifact.Created is DateTime buildTime)
|
||||
downloadHeader = $"{downloadHeader} ({(DateTime.UtcNow - buildTime.ToUniversalTime()).AsTimeDeltaDescription()} ago)";
|
||||
var name = artifactInfo.Artifact.FileName;
|
||||
name = name.Replace("rpcs3-", "").Replace("_win64", "");
|
||||
downloadText = $"[⏬ {name}]({artifactInfo.DownloadUrl})";
|
||||
}
|
||||
else
|
||||
{
|
||||
var statuses = await githubClient.GetStatusesAsync(statusesUrl, Config.Cts.Token).ConfigureAwait(false);
|
||||
statuses = statuses?.Where(s => s.Context == appveyorContext).ToList();
|
||||
downloadText = statuses?.FirstOrDefault()?.Description ?? downloadText;
|
||||
}
|
||||
}
|
||||
else if (await appveyorClient.GetPrDownloadAsync(prInfo.Number, prInfo.CreatedAt, Config.Cts.Token).ConfigureAwait(false) is ArtifactInfo artifactInfo)
|
||||
if (await appveyorClient.GetPrDownloadAsync(prInfo.Number, prInfo.CreatedAt, Config.Cts.Token).ConfigureAwait(false) is ArtifactInfo artifactInfo)
|
||||
{
|
||||
if (artifactInfo.Artifact.Created is DateTime buildTime)
|
||||
downloadHeader = $"{downloadHeader} ({(DateTime.UtcNow - buildTime.ToUniversalTime()).AsTimeDeltaDescription()} ago)";
|
||||
|
@ -59,7 +59,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Clients\AppveyorClient\AppveyorClient.csproj" />
|
||||
<ProjectReference Include="..\Clients\CompatApiClient\CompatApiClient.csproj" />
|
||||
<ProjectReference Include="..\Clients\GithubClient\GithubClient.csproj" />
|
||||
<ProjectReference Include="..\Clients\OneDriveClient\OneDriveClient.csproj" />
|
||||
|
@ -1,74 +0,0 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CompatBot.Utils;
|
||||
using DSharpPlus.EventArgs;
|
||||
|
||||
namespace CompatBot.EventHandlers
|
||||
{
|
||||
internal sealed class AppveyorLinksHandler
|
||||
{
|
||||
// https://ci.appveyor.com/project/rpcs3/rpcs3/build/0.0.4-7952/artifacts
|
||||
// https://ci.appveyor.com/project/rpcs3/rpcs3/build/0.0.5-952c5c92/artifacts
|
||||
// https://ci.appveyor.com/project/rpcs3/rpcs3/builds/21496243/artifacts
|
||||
// https://ci.appveyor.com/api/buildjobs/08a2gmwttqo1j86r/artifacts/rpcs3-v0.0.5-8362ab1e_win64.7z
|
||||
|
||||
private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture;
|
||||
private static readonly Regex BuildLinks = new Regex(@"https?://ci\.appveyor\.com/(project/rpcs3/rpcs3/build(s/(?<build_number>\d+)|/(?<build_id>[0-5\.]+-[^/ ]+))|api/buildjobs/(?<job_id>[^/ ]+))", DefaultOptions);
|
||||
private static readonly GithubClient.Client GithubClient = new GithubClient.Client();
|
||||
private static readonly AppveyorClient.Client AppveyorClient = new AppveyorClient.Client();
|
||||
|
||||
public static async Task OnMessageCreated(MessageCreateEventArgs args)
|
||||
{
|
||||
if (DefaultHandlerFilter.IsFluff(args.Message))
|
||||
return;
|
||||
|
||||
var matches = BuildLinks.Matches(args.Message.Content);
|
||||
if (matches.Count == 0)
|
||||
return;
|
||||
|
||||
await args.Message.ReactWithAsync(Config.Reactions.PleaseWait).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
var lookedUp = 0;
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
if (lookedUp > 0 && global::GithubClient.Client.RateLimitRemaining < Math.Max(20, global::GithubClient.Client.RateLimit / 2))
|
||||
{
|
||||
await args.Message.RespondAsync("Further lookups are rate limited by github API").ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lookedUp > 4)
|
||||
break;
|
||||
|
||||
int? pr = null;
|
||||
if (match.Groups["build_id"].Value is string buildId && !string.IsNullOrEmpty(buildId))
|
||||
{
|
||||
var buildInfo = await AppveyorClient.GetBuildInfoAsync("https://ci.appveyor.com/api/projects/rpcs3/rpcs3/build/" + buildId, Config.Cts.Token).ConfigureAwait(false);
|
||||
pr = buildInfo?.Build?.PullRequestId;
|
||||
} else if (match.Groups["build_number"].Value is string buildNum && int.TryParse(buildNum, out var build))
|
||||
{
|
||||
var buildInfo = await AppveyorClient.GetBuildInfoAsync(build, Config.Cts.Token).ConfigureAwait(false);
|
||||
pr = buildInfo?.Build?.PullRequestId;
|
||||
}
|
||||
else if (match.Groups["job_id"].Value is string jobId && !string.IsNullOrEmpty(jobId))
|
||||
{
|
||||
using var timeoutCts = new CancellationTokenSource(Config.LogParsingTimeout);
|
||||
using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(Config.Cts.Token, timeoutCts.Token);
|
||||
var buildInfo = await AppveyorClient.GetBuildAsync(jobId, combinedCts.Token).ConfigureAwait(false);
|
||||
pr = buildInfo?.PullRequestId;
|
||||
}
|
||||
if (pr > 0)
|
||||
await Commands.Pr.LinkPrBuild(args.Client, args.Message, pr.Value).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
await args.Message.RemoveReactionAsync(Config.Reactions.PleaseWait).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -111,7 +111,6 @@ namespace CompatBot
|
||||
new PsnScraper().RunAsync(Config.Cts.Token),
|
||||
GameTdbScraper.RunAsync(Config.Cts.Token),
|
||||
#endif
|
||||
new AppveyorClient.Client().GetBuildAsync(Guid.NewGuid().ToString(), Config.Cts.Token),
|
||||
StatsStorage.BackgroundSaveAsync(),
|
||||
MediaScreenshotMonitor.ProcessWorkQueue()
|
||||
);
|
||||
@ -226,7 +225,6 @@ namespace CompatBot
|
||||
client.MessageCreated += DiscordInviteFilter.OnMessageCreated;
|
||||
client.MessageCreated += PostLogHelpHandler.OnMessageCreated;
|
||||
client.MessageCreated += BotReactionsHandler.OnMessageCreated;
|
||||
client.MessageCreated += AppveyorLinksHandler.OnMessageCreated;
|
||||
client.MessageCreated += GithubLinksHandler.OnMessageCreated;
|
||||
client.MessageCreated += NewBuildsMonitor.OnMessageCreated;
|
||||
client.MessageCreated += TableFlipMonitor.OnMessageCreated;
|
||||
|
@ -16,7 +16,6 @@ namespace CompatBot.Utils.ResultFormatters
|
||||
internal static class UpdateInfoFormatter
|
||||
{
|
||||
private static readonly GithubClient.Client githubClient = new GithubClient.Client();
|
||||
private static readonly AppveyorClient.Client appveyorClient = new AppveyorClient.Client();
|
||||
|
||||
public static async Task<DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, DiscordClient client, bool includePrBody = false, DiscordEmbedBuilder builder = null)
|
||||
{
|
||||
|
@ -19,8 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Clients", "Clients", "{E7FE
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GithubClient", "Clients\GithubClient\GithubClient.csproj", "{AF8FDA29-864E-4A1C-9568-99DECB7E4B36}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppveyorClient", "Clients\AppveyorClient\AppveyorClient.csproj", "{595ED201-1456-49F9-AD60-54B08499A5C1}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AD87F38F-BFCE-4EA6-A430-20C497552FD7}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
azure-pipelines.yml = azure-pipelines.yml
|
||||
@ -31,7 +29,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
SECURITY.md = SECURITY.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneDriveClient", "Clients\OneDriveClient\OneDriveClient.csproj", "{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneDriveClient", "Clients\OneDriveClient\OneDriveClient.csproj", "{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -66,10 +64,6 @@ Global
|
||||
{AF8FDA29-864E-4A1C-9568-99DECB7E4B36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF8FDA29-864E-4A1C-9568-99DECB7E4B36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF8FDA29-864E-4A1C-9568-99DECB7E4B36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{595ED201-1456-49F9-AD60-54B08499A5C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{595ED201-1456-49F9-AD60-54B08499A5C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{595ED201-1456-49F9-AD60-54B08499A5C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{595ED201-1456-49F9-AD60-54B08499A5C1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -83,7 +77,6 @@ Global
|
||||
{AA5FF441-BD1D-4444-9178-7DC7BFF3C139} = {E7FE0ADD-CBA6-4321-8A1C-0A3B5C3F54C2}
|
||||
{AA2A333B-CD30-41A5-A680-CC9BCB2D726B} = {E7FE0ADD-CBA6-4321-8A1C-0A3B5C3F54C2}
|
||||
{AF8FDA29-864E-4A1C-9568-99DECB7E4B36} = {E7FE0ADD-CBA6-4321-8A1C-0A3B5C3F54C2}
|
||||
{595ED201-1456-49F9-AD60-54B08499A5C1} = {E7FE0ADD-CBA6-4321-8A1C-0A3B5C3F54C2}
|
||||
{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD} = {E7FE0ADD-CBA6-4321-8A1C-0A3B5C3F54C2}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
|
Loading…
Reference in New Issue
Block a user