tgstation-server
The /tg/station 13 server suite
RevisionCommand.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Globalization;
4 using System.Linq;
5 using System.Threading;
6 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 
39  readonly Models.Instance instance;
40 
47  public RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager, Models.Instance instance)
48  {
49  this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
50  this.repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
51  this.instance = instance ?? throw new ArgumentNullException(nameof(instance));
52  }
53 
55  public async Task<string> Invoke(string arguments, User user, CancellationToken cancellationToken)
56  {
57  string result;
58  if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--REPO"))
59  using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(false))
60  {
61  if (repo == null)
62  return "Repository unavailable!";
63  result = repo.Head;
64  }
65  else
66  {
67  if (!watchdog.Running)
68  return "Server offline!";
69  result = watchdog.ActiveCompileJob?.RevisionInformation.CommitSha;
70  }
71 
72  return String.Format(CultureInfo.InvariantCulture, "^{0}", result);
73  }
74  }
75 }
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand
async Task< string > Invoke(string arguments, User user, CancellationToken cancellationToken)
Invoke the ICommand
readonly IWatchdog watchdog
The IWatchdog for the PullRequestsCommand
readonly Models.Instance instance
The Models.Instance for the PullRequestsCommand
RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager, Models.Instance instance)
Construct a RevisionCommand
For displaying Api.Models.Internal.RevisionInformation
Represents a tgs_chat_user datum
Definition: User.cs:10
Factory for creating and loading IRepositorys
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:12