Skip to content

Commit

Permalink
Merge pull request #46 from Cyberboss/UpdateOckto
Browse files Browse the repository at this point in the history
Update Octokit to 3.1
  • Loading branch information
Cyberboss committed Jul 21, 2018
2 parents 4295b80 + 394b3d1 commit 1b7f2b2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion IconDiffBot/Core/GitHubManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task<byte[]> GetFileAtCommit(long repositoryId, long installationId
public async Task<IEnumerable<CheckRun>> GetMatchingCheckRuns(long repositoryId, long installationId, long checkSuiteId, CancellationToken cancellationToken)
{
var client = await CreateInstallationClient(installationId, cancellationToken).ConfigureAwait(false);
return await client.Check.Run.GetAllForCheckSuite(repositoryId, checkSuiteId).ConfigureAwait(false);
return (await client.Check.Run.GetAllForCheckSuite(repositoryId, checkSuiteId).ConfigureAwait(false)).CheckRuns;
}
}
}
51 changes: 19 additions & 32 deletions IconDiffBot/Core/PayloadProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,12 @@ async Task RunCheck()

if (!checkRunId.HasValue)
{
var ncr = new NewCheckRun
var ncr = new NewCheckRun(String.Format(CultureInfo.InvariantCulture, "Diffs - Pull Request #{0}", pullRequest.Number), pullRequest.Head.Sha)
{
HeadSha = pullRequest.Head.Sha,
Name = String.Format(CultureInfo.InvariantCulture, "Diffs - Pull Request #{0}", pullRequest.Number),
StartedAt = DateTimeOffset.Now,
Status = CheckStatus.Queued
};

if (pullRequest.Head.Repository.Id == repositoryId)
ncr.HeadBranch = pullRequest.Head.Ref;

checkRunId = await gitHubManager.CreateCheckRun(repositoryId, installationId, ncr, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -150,7 +146,7 @@ async Task RunCheck()
CompletedAt = DateTimeOffset.Now,
Status = CheckStatus.Completed,
Conclusion = CheckConclusion.Neutral,
Output = new CheckRunOutput(stringLocalizer["No Modified Icons"], stringLocalizer["No modified .dmi files were detected in this pull request"], null, null, null)
Output = new NewCheckRunOutput(stringLocalizer["No Modified Icons"], stringLocalizer["No modified .dmi files were detected in this pull request"])
}, cancellationToken).ConfigureAwait(false);
return;
}
Expand Down Expand Up @@ -194,7 +190,7 @@ async Task RunCheck()
CompletedAt = DateTimeOffset.Now,
Status = CheckStatus.Completed,
Conclusion = CheckConclusion.Failure,
Output = new CheckRunOutput(stringLocalizer["Error generating diffs!"], stringLocalizer["Exception details:\n\n```\n{0}\n```\n\nPlease report this [here]({1})", e.ToString(), IssueReportUrl], null, null, null)
Output = new NewCheckRunOutput(stringLocalizer["Error generating diffs!"], stringLocalizer["Exception details:\n\n```\n{0}\n```\n\nPlease report this [here]({1})", e.ToString(), IssueReportUrl])
}, default).ConfigureAwait(false);
}
catch (Exception innerException)
Expand All @@ -213,7 +209,7 @@ async Task RunCheck()
CompletedAt = DateTimeOffset.Now,
Status = CheckStatus.Completed,
Conclusion = CheckConclusion.Neutral,
Output = new CheckRunOutput(stringLocalizer["Operation Cancelled"], stringLocalizer["The operation was cancelled on the server, most likely due to app shutdown. You may attempt re-running it."], null, null, null)
Output = new NewCheckRunOutput(stringLocalizer["Operation Cancelled"], stringLocalizer["The operation was cancelled on the server, most likely due to app shutdown. You may attempt re-running it."])
}, default).ConfigureAwait(false);
}
}
Expand All @@ -236,7 +232,7 @@ async Task GenerateDiffs(PullRequest pullRequest, long installationId, long chec
var checkRunDequeueUpdate = gitHubManager.UpdateCheckRun(pullRequest.Base.Repository.Id, installationId, checkRunId, new CheckRunUpdate
{
Status = CheckStatus.InProgress,
Output = new CheckRunOutput(stringLocalizer["Generating Diffs"], stringLocalizer["Aww geez rick, I should eventually put some progress message here"], null, null, null),
Output = new NewCheckRunOutput(stringLocalizer["Generating Diffs"], stringLocalizer["Aww geez rick, I should eventually put some progress message here"]),
}, cancellationToken);

var results = new List<IconDiff>();
Expand Down Expand Up @@ -357,12 +353,7 @@ async Task<MemoryStream> GetImageFor(string commit, bool before)
async Task HandleResults(PullRequest pullRequest, long installationId, long checkRunId, List<IconDiff> diffResults, IServiceScope scope, IDatabaseContext databaseContext, CancellationToken cancellationToken)
{
logger.LogTrace("Generating check run output and preparing database query...");

var outputImages = new List<CheckRunImage>()
{
Capacity = diffResults.Count
};


var prefix = generalConfiguration.ApplicationPrefix;
var commentBuilder = new StringBuilder();

Expand Down Expand Up @@ -445,11 +436,9 @@ async Task HandleResults(PullRequest pullRequest, long installationId, long chec
(I < cutoff ? set1 : set2).Add(diffResults[I]);

var firstCR = HandleResults(pullRequest, installationId, checkRunId, set1, scope, null, cancellationToken);
var nextCheckRunId = await ghm.CreateCheckRun(pullRequest.Base.Repository.Id, installationId, new NewCheckRun
var nextCheckRunId = await ghm.CreateCheckRun(pullRequest.Base.Repository.Id, installationId, new NewCheckRun(stringLocalizer["Additional Diffs - Pull Request #{0} - Set Base: {1}", pullRequest.Number, set2.First().DmiPath], pullRequest.Head.Sha)
{
StartedAt = DateTimeOffset.Now,
HeadSha = pullRequest.Head.Sha,
Name = stringLocalizer["Additional Diffs - Pull Request #{0} - Set Base: {1}", pullRequest.Number, set2.First().DmiPath],
Status = CheckStatus.InProgress
}, cancellationToken).ConfigureAwait(false);
await HandleResults(pullRequest, installationId, nextCheckRunId, set2, scope, null, cancellationToken).ConfigureAwait(false);
Expand All @@ -465,7 +454,10 @@ async Task HandleResults(PullRequest pullRequest, long installationId, long chec
{
Status = CheckStatus.Completed,
CompletedAt = DateTimeOffset.Now,
Output = new CheckRunOutput(stringLocalizer["Icon Diffs"], stringLocalizer["Icons with diff:"], comment, null, outputImages),
Output = new NewCheckRunOutput(stringLocalizer["Icon Diffs"], stringLocalizer["Icons with diff:"])
{
Text = comment
},
Conclusion = CheckConclusion.Success
};
await ghm.UpdateCheckRun(pullRequest.Base.Repository.Id, installationId, checkRunId, ncr, cancellationToken).ConfigureAwait(false);
Expand All @@ -478,22 +470,18 @@ async Task HandleResults(PullRequest pullRequest, long installationId, long chec
/// <param name="installationId">The <see cref="InstallationId.Id"/></param>
/// <param name="gitHubManager">The <see cref="IGitHubManager"/> for the operation</param>
/// <param name="checkSuiteSha">The <see cref="CheckSuite.HeadSha"/></param>
/// <param name="checkSuiteBranch">The <see cref="CheckSuite.HeadBranch"/></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
async Task CreateUnassociatedCheck(long repositoryId, long installationId, IGitHubManager gitHubManager, string checkSuiteSha, string checkSuiteBranch, CancellationToken cancellationToken)
async Task CreateUnassociatedCheck(long repositoryId, long installationId, IGitHubManager gitHubManager, string checkSuiteSha, CancellationToken cancellationToken)
{
var now = DateTimeOffset.Now;
var nmc = stringLocalizer["No Associated Pull Request"];
await gitHubManager.CreateCheckRun(repositoryId, installationId, new NewCheckRun
await gitHubManager.CreateCheckRun(repositoryId, installationId, new NewCheckRun(nmc, checkSuiteSha)
{
CompletedAt = now,
StartedAt = now,
Conclusion = CheckConclusion.Neutral,
HeadSha = checkSuiteSha,
HeadBranch = checkSuiteBranch,
Name = nmc,
Output = new CheckRunOutput(nmc, String.Empty, null, null, null),
Output = new NewCheckRunOutput(nmc, String.Empty),
Status = CheckStatus.Completed
}, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -505,11 +493,10 @@ async Task CreateUnassociatedCheck(long repositoryId, long installationId, IGitH
/// <param name="installationId">The <see cref="InstallationId.Id"/></param>
/// <param name="checkSuiteId">The <see cref="CheckSuite.Id"/></param>
/// <param name="checkSuiteSha">The <see cref="CheckSuite.HeadSha"/></param>
/// <param name="checkSuiteBranch">The <see cref="CheckSuite.HeadBranch"/></param>
/// <param name="jobCancellationToken">The <see cref="IJobCancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
[AutomaticRetry(Attempts = 0)]
public async Task ScanCheckSuite(long repositoryId, long installationId, long checkSuiteId, string checkSuiteSha, string checkSuiteBranch, IJobCancellationToken jobCancellationToken)
public async Task ScanCheckSuite(long repositoryId, long installationId, long checkSuiteId, string checkSuiteSha, IJobCancellationToken jobCancellationToken)
{
using (logger.BeginScope("Scanning check suite {0} for repository {1}. Sha: ", checkSuiteId, repositoryId, checkSuiteSha))
using (var scope = serviceProvider.CreateScope())
Expand All @@ -531,7 +518,7 @@ await Task.WhenAll(checkRuns.Select(x =>
})).ConfigureAwait(false);

if (!testedAny)
await CreateUnassociatedCheck(repositoryId, installationId, gitHubManager, checkSuiteSha, checkSuiteBranch, cancellationToken).ConfigureAwait(false);
await CreateUnassociatedCheck(repositoryId, installationId, gitHubManager, checkSuiteSha, cancellationToken).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -566,7 +553,7 @@ public void ProcessPayload(CheckSuiteEventPayload payload)
return;

//don't rely on CheckSuite.PullRequests, it doesn't include PRs from forks.
backgroundJobClient.Enqueue(() => ScanCheckSuite(payload.Repository.Id, payload.Installation.Id, payload.CheckSuite.Id, payload.CheckSuite.HeadSha, payload.CheckSuite.HeadBranch, JobCancellationToken.Null));
backgroundJobClient.Enqueue(() => ScanCheckSuite(payload.Repository.Id, payload.Installation.Id, payload.CheckSuite.Id, payload.CheckSuite.HeadSha, JobCancellationToken.Null));
}

/// <inheritdoc />
Expand All @@ -578,7 +565,7 @@ public async Task ProcessPayload(CheckRunEventPayload payload, IGitHubManager gi
if (prNumber.HasValue)
backgroundJobClient.Enqueue(() => ScanPullRequest(payload.Repository.Id, prNumber.Value, payload.Installation.Id, JobCancellationToken.Null));
else
await CreateUnassociatedCheck(payload.Repository.Id, payload.Installation.Id, gitHubManager, payload.CheckRun.CheckSuite.HeadSha, payload.CheckRun.CheckSuite.HeadBranch, cancellationToken).ConfigureAwait(false);
await CreateUnassociatedCheck(payload.Repository.Id, payload.Installation.Id, gitHubManager, payload.CheckRun.CheckSuite.HeadSha, cancellationToken).ConfigureAwait(false);
}
}
}
1 change: 1 addition & 0 deletions IconDiffBot/IconDiffBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Octokit" Version="0.31.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0" />
<PackageReference Include="ZNetCS.AspNetCore.Logging.EntityFrameworkCore" Version="2.0.1" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions IconDiffBot/Octokit-Build.txt

This file was deleted.

Binary file removed IconDiffBot/Octokit.dll
Binary file not shown.

0 comments on commit 1b7f2b2

Please sign in to comment.