mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-23 04:57:17 +01:00
Discord (and IRC to an extent) now mention the changes to TMs in deployment messages
This commit is contained in:
@@ -377,6 +377,7 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
/// <inheritdoc />
|
||||
public Func<string?, string, Action<bool>> QueueDeploymentMessage(
|
||||
Models.RevisionInformation revisionInformation,
|
||||
Models.RevisionInformation? previousRevisionInformation,
|
||||
EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string? gitHubOwner,
|
||||
@@ -407,6 +408,7 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
{
|
||||
var callback = await provider.SendUpdateMessage(
|
||||
revisionInformation,
|
||||
previousRevisionInformation,
|
||||
engineVersion,
|
||||
estimatedCompletionTime,
|
||||
gitHubOwner,
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
/// Send the message for a deployment to configured deployment channels.
|
||||
/// </summary>
|
||||
/// <param name="revisionInformation">The <see cref="RevisionInformation"/> of the deployment.</param>
|
||||
/// <param name="previousRevisionInformation">The optional <see cref="RevisionInformation"/> of the previous deployment.</param>
|
||||
/// <param name="engineVersion">The <see cref="Api.Models.EngineVersion"/> of the deployment.</param>
|
||||
/// <param name="estimatedCompletionTime">The optional <see cref="DateTimeOffset"/> the deployment is expected to be completed at.</param>
|
||||
/// <param name="gitHubOwner">The repository GitHub owner, if any.</param>
|
||||
@@ -69,6 +70,7 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
/// <returns>A <see cref="Func{T1, T2, TResult}"/> to call to update the message at the deployment's conclusion. Parameters: Error message if any, DreamMaker output if any. Returns an <see cref="Action"/> to call to mark the deployment as active/inactive. Parameter: If the deployment is being activated or inactivated.</returns>
|
||||
Func<string?, string, Action<bool>> QueueDeploymentMessage(
|
||||
Models.RevisionInformation revisionInformation,
|
||||
Models.RevisionInformation? previousRevisionInformation,
|
||||
Api.Models.EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string? gitHubOwner,
|
||||
|
||||
@@ -303,6 +303,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// <inheritdoc />
|
||||
public override async ValueTask<Func<string?, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
|
||||
Models.RevisionInformation revisionInformation,
|
||||
Models.RevisionInformation? previousRevisionInformation,
|
||||
EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string? gitHubOwner,
|
||||
@@ -316,7 +317,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
|
||||
localCommitPushed |= revisionInformation.CommitSha == revisionInformation.OriginCommitSha;
|
||||
|
||||
var fields = BuildUpdateEmbedFields(revisionInformation, engineVersion, gitHubOwner, gitHubRepo, localCommitPushed);
|
||||
var fields = BuildUpdateEmbedFields(revisionInformation, previousRevisionInformation, engineVersion, gitHubOwner, gitHubRepo, localCommitPushed);
|
||||
Optional<IEmbedAuthor> author = new EmbedAuthor(assemblyInformationProvider.VersionPrefix)
|
||||
{
|
||||
Url = "https://github.com/tgstation/tgstation-server",
|
||||
@@ -900,6 +901,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// Create a <see cref="List{T}"/> of <see cref="IEmbedField"/>s for a discord update embed.
|
||||
/// </summary>
|
||||
/// <param name="revisionInformation">The <see cref="RevisionInformation"/> of the deployment.</param>
|
||||
/// <param name="previousRevisionInformation">The optional <see cref="RevisionInformation"/> of the previous deployment.</param>
|
||||
/// <param name="engineVersion">The <see cref="EngineVersion"/> of the deployment.</param>
|
||||
/// <param name="gitHubOwner">The repository GitHub owner, if any.</param>
|
||||
/// <param name="gitHubRepo">The repository GitHub name, if any.</param>
|
||||
@@ -907,6 +909,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// <returns>A new <see cref="List{T}"/> of <see cref="IEmbedField"/>s to use.</returns>
|
||||
List<IEmbedField> BuildUpdateEmbedFields(
|
||||
Models.RevisionInformation revisionInformation,
|
||||
Models.RevisionInformation? previousRevisionInformation,
|
||||
EngineVersion engineVersion,
|
||||
string? gitHubOwner,
|
||||
string? gitHubRepo,
|
||||
@@ -936,6 +939,40 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
if (gitHubOwner == null || gitHubRepo == null)
|
||||
return fields;
|
||||
|
||||
previousRevisionInformation ??= new Models.RevisionInformation();
|
||||
previousRevisionInformation.ActiveTestMerges ??= new List<RevInfoTestMerge>();
|
||||
|
||||
revisionInformation.ActiveTestMerges ??= new List<RevInfoTestMerge>();
|
||||
|
||||
var addedTestMerges = revisionInformation
|
||||
.ActiveTestMerges
|
||||
.Select(x => x.TestMerge)
|
||||
.Where(x => !previousRevisionInformation
|
||||
.ActiveTestMerges
|
||||
.Any(y => y.TestMerge.Number == x.Number))
|
||||
.ToList();
|
||||
var removedTestMerges = previousRevisionInformation
|
||||
.ActiveTestMerges
|
||||
.Select(x => x.TestMerge)
|
||||
.Where(x => !revisionInformation
|
||||
.ActiveTestMerges
|
||||
.Any(y => y.TestMerge.Number == x.Number))
|
||||
.ToList();
|
||||
var updatedTestMerges = revisionInformation
|
||||
.ActiveTestMerges
|
||||
.Select(x => x.TestMerge)
|
||||
.Where(x => previousRevisionInformation
|
||||
.ActiveTestMerges
|
||||
.Any(y => y.TestMerge.Number == x.Number && y.TestMerge.TargetCommitSha != x.TargetCommitSha))
|
||||
.ToList();
|
||||
var unchangedTestMerges = revisionInformation
|
||||
.ActiveTestMerges
|
||||
.Select(x => x.TestMerge)
|
||||
.Where(x => previousRevisionInformation
|
||||
.ActiveTestMerges
|
||||
.Any(y => y.TestMerge.Number == x.Number && y.TestMerge.TargetCommitSha == x.TargetCommitSha))
|
||||
.ToList();
|
||||
|
||||
fields.Add(
|
||||
new EmbedField(
|
||||
"Local Commit",
|
||||
@@ -952,13 +989,35 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
: revisionOriginSha[..7],
|
||||
true));
|
||||
|
||||
fields.AddRange((revisionInformation.ActiveTestMerges ?? Enumerable.Empty<RevInfoTestMerge>())
|
||||
.Select(x => x.TestMerge)
|
||||
fields.AddRange(addedTestMerges
|
||||
.Select(x => new EmbedField(
|
||||
$"#{x.Number} (Added)",
|
||||
$"[{x.TitleAtMerge}]({x.Url}) by _[@{x.Author}](https://github.com/{x.Author})_{Environment.NewLine}Commit: [{x.TargetCommitSha![..7]}](https://github.com/{gitHubOwner}/{gitHubRepo}/commit/{x.TargetCommitSha}){(String.IsNullOrWhiteSpace(x.Comment) ? String.Empty : $"{Environment.NewLine}_**{x.Comment}**_")}",
|
||||
false)));
|
||||
|
||||
fields.AddRange(updatedTestMerges
|
||||
.Select(x => new EmbedField(
|
||||
$"#{x.Number} (Updated)",
|
||||
$"[{x.TitleAtMerge}]({x.Url}) by _[@{x.Author}](https://github.com/{x.Author})_{Environment.NewLine}Commit: [{x.TargetCommitSha![..7]}](https://github.com/{gitHubOwner}/{gitHubRepo}/commit/{x.TargetCommitSha}){(String.IsNullOrWhiteSpace(x.Comment) ? String.Empty : $"{Environment.NewLine}_**{x.Comment}**_")}",
|
||||
false)));
|
||||
|
||||
fields.AddRange(unchangedTestMerges
|
||||
.Select(x => new EmbedField(
|
||||
$"#{x.Number}",
|
||||
$"[{x.TitleAtMerge}]({x.Url}) by _[@{x.Author}](https://github.com/{x.Author})_{Environment.NewLine}Commit: [{x.TargetCommitSha![..7]}](https://github.com/{gitHubOwner}/{gitHubRepo}/commit/{x.TargetCommitSha}){(String.IsNullOrWhiteSpace(x.Comment) ? String.Empty : $"{Environment.NewLine}_**{x.Comment}**_")}",
|
||||
false)));
|
||||
|
||||
if (removedTestMerges.Count != 0)
|
||||
{
|
||||
fields.Add(
|
||||
new EmbedField(
|
||||
"Removed:",
|
||||
String.Join(
|
||||
Environment.NewLine,
|
||||
removedTestMerges
|
||||
.Select(x => $"- #{x.Number} [{x.TitleAtMerge}]({x.Url}) by _[@{x.Author}](https://github.com/{x.Author})_"))));
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// Send the message for a deployment.
|
||||
/// </summary>
|
||||
/// <param name="revisionInformation">The <see cref="RevisionInformation"/> of the deployment.</param>
|
||||
/// <param name="previousRevisionInformation">The optional <see cref="RevisionInformation"/> of the previous deployment.</param>
|
||||
/// <param name="engineVersion">The <see cref="Api.Models.EngineVersion"/> of the deployment.</param>
|
||||
/// <param name="estimatedCompletionTime">The optional <see cref="DateTimeOffset"/> the deployment is expected to be completed at.</param>
|
||||
/// <param name="gitHubOwner">The repository GitHub owner, if any.</param>
|
||||
@@ -94,6 +95,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="Func{T1, T2, TResult}"/> to call to update the message at the deployment's conclusion. Parameters: Error message if any, DreamMaker output if any. Returns another callback which should be called to mark the deployment as active.</returns>
|
||||
ValueTask<Func<string?, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
|
||||
Models.RevisionInformation revisionInformation,
|
||||
Models.RevisionInformation? previousRevisionInformation,
|
||||
Api.Models.EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string? gitHubOwner,
|
||||
|
||||
@@ -17,6 +17,7 @@ using Tgstation.Server.Host.Configuration;
|
||||
using Tgstation.Server.Host.Extensions;
|
||||
using Tgstation.Server.Host.IO;
|
||||
using Tgstation.Server.Host.Jobs;
|
||||
using Tgstation.Server.Host.Models;
|
||||
using Tgstation.Server.Host.System;
|
||||
using Tgstation.Server.Host.Utils;
|
||||
|
||||
@@ -217,6 +218,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// <inheritdoc />
|
||||
public override async ValueTask<Func<string?, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
|
||||
Models.RevisionInformation revisionInformation,
|
||||
Models.RevisionInformation? previousRevisionInformation,
|
||||
EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string? gitHubOwner,
|
||||
@@ -230,6 +232,9 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
ArgumentNullException.ThrowIfNull(gitHubOwner);
|
||||
ArgumentNullException.ThrowIfNull(gitHubRepo);
|
||||
|
||||
previousRevisionInformation ??= new Models.RevisionInformation();
|
||||
previousRevisionInformation.ActiveTestMerges ??= new List<RevInfoTestMerge>();
|
||||
|
||||
var commitInsert = revisionInformation.CommitSha![..7];
|
||||
string remoteCommitInsert;
|
||||
if (revisionInformation.CommitSha == revisionInformation.OriginCommitSha)
|
||||
@@ -252,9 +257,26 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
.Select(x => x.TestMerge)
|
||||
.Select(x =>
|
||||
{
|
||||
var status = string.Empty;
|
||||
if (!previousRevisionInformation.ActiveTestMerges.Any(y => y.TestMerge.Number == x.Number))
|
||||
{
|
||||
status = "Added";
|
||||
}
|
||||
else if (revisionInformation.ActiveTestMerges!.Any(y => y.TestMerge.Number == x.Number && y.TestMerge.TargetCommitSha != x.TargetCommitSha))
|
||||
{
|
||||
status = "Updated";
|
||||
}
|
||||
|
||||
var result = String.Format(CultureInfo.InvariantCulture, "#{0} at {1}", x.Number, x.TargetCommitSha![..7]);
|
||||
if (x.Comment != null)
|
||||
result += String.Format(CultureInfo.InvariantCulture, " ({0})", x.Comment);
|
||||
{
|
||||
result += String.Format(CultureInfo.InvariantCulture, " ({1} - {0})", x.Comment, status);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(status))
|
||||
{
|
||||
result += String.Format(CultureInfo.InvariantCulture, " ({0})", status);
|
||||
}
|
||||
|
||||
return result;
|
||||
})));
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
/// <inheritdoc />
|
||||
public abstract ValueTask<Func<string?, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
|
||||
RevisionInformation revisionInformation,
|
||||
RevisionInformation? previousRevisionInformation,
|
||||
Api.Models.EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string? gitHubOwner,
|
||||
|
||||
@@ -326,7 +326,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
likelyPushedTestMergeCommit,
|
||||
cancellationToken);
|
||||
|
||||
var activeCompileJob = await compileJobConsumer.LatestCompileJob();
|
||||
var oldCompileJob = await compileJobConsumer.LatestCompileJob();
|
||||
try
|
||||
{
|
||||
await databaseContextFactory.UseContext(
|
||||
@@ -374,7 +374,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
|
||||
var commentsTask = remoteDeploymentManager!.PostDeploymentComments(
|
||||
compileJob,
|
||||
activeCompileJob?.RevisionInformation,
|
||||
oldCompileJob?.RevisionInformation,
|
||||
repositorySettings,
|
||||
repoOwner,
|
||||
repoName,
|
||||
@@ -478,8 +478,10 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
try
|
||||
{
|
||||
using var engineLock = await engineManager.UseExecutables(null, null, cancellationToken);
|
||||
var oldCompileJob = await compileJobConsumer.LatestCompileJob();
|
||||
currentChatCallback = chatManager.QueueDeploymentMessage(
|
||||
revisionInformation,
|
||||
oldCompileJob?.RevisionInformation,
|
||||
engineLock.Version,
|
||||
DateTimeOffset.UtcNow + estimatedDuration,
|
||||
repository.RemoteRepositoryOwner,
|
||||
|
||||
@@ -105,6 +105,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
|
||||
public override ValueTask<Func<string, string, ValueTask<Func<bool, ValueTask>>>> SendUpdateMessage(
|
||||
RevisionInformation revisionInformation,
|
||||
RevisionInformation previousRevisionInformation,
|
||||
Api.Models.EngineVersion engineVersion,
|
||||
DateTimeOffset? estimatedCompletionTime,
|
||||
string gitHubOwner,
|
||||
|
||||
Reference in New Issue
Block a user