mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 08:33:19 +01:00
Add revision command
This commit is contained in:
@@ -77,6 +77,7 @@ namespace Tgstation.Server.Host.Components.Chat.Commands
|
||||
{
|
||||
new VersionCommand(application),
|
||||
new ByondCommand(byondManager),
|
||||
new RevisionCommand(watchdog, repositoryManager, instance),
|
||||
new PullRequestsCommand(watchdog, repositoryManager, databaseContextFactory, instance),
|
||||
new KekCommand()
|
||||
};
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Host.Components.Repository;
|
||||
using Tgstation.Server.Host.Components.Watchdog;
|
||||
|
||||
namespace Tgstation.Server.Host.Components.Chat.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// For displaying <see cref="Api.Models.Internal.RevisionInformation"/>
|
||||
/// </summary>
|
||||
sealed class RevisionCommand : ICommand
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string Name => "revision";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string HelpText => "Display live commit sha. Add --repo to view repository revision";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool AdminOnly => false;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IWatchdog"/> for the <see cref="PullRequestsCommand"/>
|
||||
/// </summary>
|
||||
readonly IWatchdog watchdog;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IRepositoryManager"/> for the <see cref="PullRequestsCommand"/>
|
||||
/// </summary>
|
||||
readonly IRepositoryManager repositoryManager;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Models.Instance"/> for the <see cref="PullRequestsCommand"/>
|
||||
/// </summary>
|
||||
readonly Models.Instance instance;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="RevisionCommand"/>
|
||||
/// </summary>
|
||||
/// <param name="watchdog">The value of <see cref="watchdog"/></param>
|
||||
/// <param name="repositoryManager">The value of <see cref="repositoryManager"/></param>
|
||||
/// <param name="instance">The value of <see cref="instance"/></param>
|
||||
public RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager, Models.Instance instance)
|
||||
{
|
||||
this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
|
||||
this.repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
|
||||
this.instance = instance ?? throw new ArgumentNullException(nameof(instance));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> Invoke(string arguments, User user, CancellationToken cancellationToken)
|
||||
{
|
||||
string result;
|
||||
if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--REPO"))
|
||||
using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (repo == null)
|
||||
return "Repository unavailable!";
|
||||
result = repo.Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!watchdog.Running)
|
||||
return "Server offline!";
|
||||
result = watchdog.ActiveCompileJob?.RevisionInformation.CommitSha;
|
||||
}
|
||||
|
||||
return String.Format(CultureInfo.InvariantCulture, "^{0}", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user