tgstation-server  4.4.0
The /tg/station 13 server suite
RevisionCommand.cs
Go to the documentation of this file.
1 using System;
2 using System.Globalization;
3 using System.Linq;
4 using System.Threading;
5 using System.Threading.Tasks;
9 
10 namespace Tgstation.Server.Host.Components.Chat.Commands
11 {
15  sealed class RevisionCommand : ICommand
16  {
18  public string Name => "revision";
19 
21  public string HelpText => "Display live commit sha. Add --repo to view repository revision";
22 
24  public bool AdminOnly => false;
25 
29  readonly IWatchdog watchdog;
30 
35 
41  public RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager)
42  {
43  this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
44  this.repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
45  }
46 
48  public async Task<string> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
49  {
50  string result;
51  if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--REPO"))
52  using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(false))
53  {
54  if (repo == null)
55  return "Repository unavailable!";
56  result = repo.Head;
57  }
58  else
59  {
60  if (watchdog.Status == WatchdogStatus.Offline)
61  return "Server offline!";
62  result = watchdog.ActiveCompileJob?.RevisionInformation.CommitSha;
63  }
64 
65  return String.Format(CultureInfo.InvariantCulture, "^{0}", result);
66  }
67  }
68 }
async Task< string > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand
WatchdogStatus
The current status of the watchdog.
readonly IWatchdog watchdog
The IWatchdog for the PullRequestsCommand
Represents a tgs_chat_user datum
Definition: ChatUser.cs:10
For displaying Api.Models.Internal.RevisionInformation
Factory for creating and loading IRepositorys
RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager)
Construct a RevisionCommand
Represents a command that can be invoked by talking to chat bots
Definition: ICommand.cs:9
Runs and monitors the twin server controllers
Definition: IWatchdog.cs:15