diff --git a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs index 48079534c7..a7fb801b9e 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs @@ -602,13 +602,15 @@ namespace Tgstation.Server.Host.Components.Deployment .CreateRemoteDeploymentManager(metadata, repo.RemoteGitProvider.Value); var repoSha = repo.Head; + repoOwner = repo.RemoteRepositoryOwner; + repoName = repo.RemoteRepositoryName; revInfo = await databaseContext .RevisionInformations .AsQueryable() .Where(x => x.CommitSha == repoSha && x.Instance.Id == metadata.Id) .Include(x => x.ActiveTestMerges) - .ThenInclude(x => x.TestMerge) - .ThenInclude(x => x.MergedBy) + .ThenInclude(x => x.TestMerge) + .ThenInclude(x => x.MergedBy) .FirstOrDefaultAsync(cancellationToken) .ConfigureAwait(false); @@ -661,10 +663,12 @@ namespace Tgstation.Server.Host.Components.Deployment await databaseContextFactory.UseContext( async databaseContext => { + var fullJob = compileJob.Job; compileJob.Job = new Models.Job { Id = job.Id }; + var fullRevInfo = compileJob.RevisionInformation; compileJob.RevisionInformation = new Models.RevisionInformation { Id = revInfo.Id @@ -690,6 +694,9 @@ namespace Tgstation.Server.Host.Components.Deployment await databaseContext.Save(default).ConfigureAwait(false); throw; } + + compileJob.Job = fullJob; + compileJob.RevisionInformation = fullRevInfo; }) .ConfigureAwait(false); } diff --git a/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs b/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs index 6b80ec9cb4..a9ea424e52 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs @@ -47,23 +47,49 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote if (repositorySettings?.AccessToken == null) return; - if ((previousRevisionInformation != null && previousRevisionInformation.CommitSha == previousRevisionInformation.CommitSha) + var deployedRevisionInformation = compileJob.RevisionInformation; + if ((previousRevisionInformation != null && previousRevisionInformation.CommitSha == deployedRevisionInformation.CommitSha) || !repositorySettings.PostTestMergeComment.Value) return; previousRevisionInformation ??= new RevisionInformation(); previousRevisionInformation.ActiveTestMerges ??= new List(); - var deployedRevisionInformation = compileJob.RevisionInformation; + deployedRevisionInformation.ActiveTestMerges ??= new List(); var tasks = new List(); // added prs - foreach (var I in deployedRevisionInformation + var tmsAdded = deployedRevisionInformation .ActiveTestMerges .Select(x => x.TestMerge) .Where(x => !previousRevisionInformation .ActiveTestMerges - .Any(y => y.TestMerge.Number == x.Number))) + .Any(y => y.TestMerge.Number == x.Number)) + .ToList(); + var tmsRemoved = previousRevisionInformation + .ActiveTestMerges + .Select(x => x.TestMerge) + .Where(x => !deployedRevisionInformation + .ActiveTestMerges + .Any(y => y.TestMerge.Number == x.Number)) + .ToList(); + var tmsUpdated = deployedRevisionInformation + .ActiveTestMerges + .Select(x => x.TestMerge) + .Where(x => previousRevisionInformation + .ActiveTestMerges + .Any(y => y.TestMerge.Number == x.Number)) + .ToList(); + + if (!tmsAdded.Any() && !tmsRemoved.Any() && !tmsUpdated.Any()) + return; + + Logger.LogTrace( + "Commenting on {0} added, {1} removed, and {2} updated test merge sources...", + tmsAdded.Count, + tmsRemoved.Count, + tmsUpdated.Count); + foreach (var I in tmsAdded) tasks.Add( CommentOnTestMergeSource( repositorySettings, @@ -79,13 +105,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote I.Number, cancellationToken)); - // removed prs - foreach (var I in previousRevisionInformation - .ActiveTestMerges - .Select(x => x.TestMerge) - .Where(x => !deployedRevisionInformation - .ActiveTestMerges - .Any(y => y.TestMerge.Number == x.Number))) + foreach (var I in tmsRemoved) tasks.Add( CommentOnTestMergeSource( repositorySettings, @@ -95,13 +115,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote I.Number, cancellationToken)); - // updated prs - foreach (var I in deployedRevisionInformation - .ActiveTestMerges - .Select(x => x.TestMerge) - .Where(x => previousRevisionInformation - .ActiveTestMerges - .Any(y => y.TestMerge.Number == x.Number))) + foreach (var I in tmsUpdated) tasks.Add( CommentOnTestMergeSource( repositorySettings,