Skip to content

Commit

Permalink
Rearrange some code to detect a potential NullReferenceException
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Sep 3, 2020
1 parent d231b3d commit 873afc6
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/Tgstation.Server.Host/Controllers/RepositoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,34 @@ await databaseContextFactory.UseContext(
foreach (var I in search)
{
revInfoWereLookingFor = dbPull
.Where(x => model.NewTestMerges.Any(z =>
x.PrimaryTestMerge.Number == z.Number
&& x.PrimaryTestMerge.PullRequestRevision.StartsWith(z.PullRequestRevision, StringComparison.Ordinal)
&& (x.PrimaryTestMerge.Comment?.Trim().ToUpperInvariant() == z.Comment?.Trim().ToUpperInvariant() || z.Comment == null))
&& x.ActiveTestMerges.Select(y => y.TestMerge).All(y => appliedTestMergeIds.Contains(y.Id)))
.Where(testRevInfo =>
{
var testMergeMatch = model.NewTestMerges.Any(testTestMerge =>
{
var numberMatch = testRevInfo.PrimaryTestMerge.Number == testTestMerge.Number;
if (!numberMatch)
return false;

var shaMatch = testRevInfo.PrimaryTestMerge.PullRequestRevision.StartsWith(
testTestMerge.PullRequestRevision,
StringComparison.Ordinal);
if (!shaMatch)
return false;

var commentMatch = testRevInfo.PrimaryTestMerge.Comment == testTestMerge.Comment;
return commentMatch;
});

if (!testMergeMatch)
return false;

var previousTestMergesMatch = testRevInfo
.ActiveTestMerges
.Select(previousRevInfoTestMerge => previousRevInfoTestMerge.TestMerge)
.All(previousTestMerge => appliedTestMergeIds.Contains(previousTestMerge.Id));

return previousTestMergesMatch;
})
.FirstOrDefault();

if (revInfoWereLookingFor != null)
Expand Down

0 comments on commit 873afc6

Please sign in to comment.