From 873afc6a8303e4a35fceda1a4b666817e42f21cd Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 3 Sep 2020 16:04:04 -0400 Subject: [PATCH] Rearrange some code to detect a potential NullReferenceException --- .../Controllers/RepositoryController.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 17646202ba..88de87bbce 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -742,11 +742,34 @@ namespace Tgstation.Server.Host.Controllers 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)