tgstation-server  4.3.2
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;
8 
9 namespace Tgstation.Server.Host.Components.Chat.Commands
10 {
14  sealed class RevisionCommand : ICommand
15  {
17  public string Name => "revision";
18 
20  public string HelpText => "Display live commit sha. Add --repo to view repository revision";
21 
23  public bool AdminOnly => false;
24 
28  readonly IWatchdog watchdog;
29 
34 
40  public RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager)
41  {
42  this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
43  this.repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
44  }
45 
47  public async Task<string> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
48  {
49  string result;
50  if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--REPO"))
51  using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(false))
52  {
53  if (repo == null)
54  return "Repository unavailable!";
55  result = repo.Head;
56  }
57  else
58  {
59  if (!watchdog.Running)
60  return "Server offline!";
61  result = watchdog.ActiveCompileJob?.RevisionInformation.CommitSha;
62  }
63 
64  return String.Format(CultureInfo.InvariantCulture, "^{0}", result);
65  }
66  }
67 }
async Task< string > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand
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:14