tgstation-server 6.8.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
RevisionCommand.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.Linq;
4using System.Threading;
5using System.Threading.Tasks;
6
11
13{
18 {
20 public string Name => "revision";
21
23 public string HelpText => "Display live origin commit sha. Add --repo to view repository revision";
24
26 public bool AdminOnly => false;
27
32
37
44 {
45 this.watchdog = watchdog ?? throw new ArgumentNullException(nameof(watchdog));
46 this.repositoryManager = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
47 }
48
50 public async ValueTask<MessageContent> Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
51 {
52 string result;
53 if (arguments.Split(' ').Any(x => x.ToUpperInvariant() == "--REPO"))
54 {
56 return new MessageContent
57 {
58 Text = "Repository busy! Try again later",
59 };
60
61 using (var repo = await repositoryManager.LoadRepository(cancellationToken))
62 {
63 if (repo == null)
64 return new MessageContent
65 {
66 Text = "Repository unavailable!",
67 };
68 result = repo.Head;
69 }
70 }
71 else
72 {
73 if (watchdog.Status == WatchdogStatus.Offline)
74 return new MessageContent
75 {
76 Text = "Server offline!",
77 };
78 result = watchdog.ActiveCompileJob?.RevisionInformation.OriginCommitSha!;
79 }
80
81 return new MessageContent
82 {
83 Text = String.Format(CultureInfo.InvariantCulture, "^{0}", result),
84 };
85 }
86 }
87}
Represents a tgs_chat_user datum.
Definition: ChatUser.cs:12
For displaying Api.Models.Internal.RevisionInformation.
string Name
The text to invoke the command. May not be "?" or "help" (case-insensitive).
bool AdminOnly
If the command should only be available to ChatUsers who's ChatUser.Channel has ChannelRepresentation...
RevisionCommand(IWatchdog watchdog, IRepositoryManager repositoryManager)
Initializes a new instance of the RevisionCommand class.
string HelpText
The help text to display when queires are made about the command.
async ValueTask< MessageContent > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand. A ValueTask<TResult> resulting in a MessageContent to send to the invoker.
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand.
readonly IWatchdog watchdog
The IWatchdog for the PullRequestsCommand.
Represents a message to send to a chat provider.
Represents a command that can be invoked by talking to chat bots.
Definition: ICommand.cs:12
Factory for creating and loading IRepositorys.
bool CloneInProgress
If a CloneRepository(Uri, string, string, string, JobProgressReporter, bool, CancellationToken) opera...
ValueTask< IRepository?> LoadRepository(CancellationToken cancellationToken)
Attempt to load the IRepository from the default location.
bool InUse
If something is holding a lock on the repository.
Runs and monitors the twin server controllers.
Definition: IWatchdog.cs:16
Models.? CompileJob ActiveCompileJob
Retrieves the Models.CompileJob currently running on the server.
Definition: IWatchdog.cs:35
WatchdogStatus Status
The current WatchdogStatus.
Definition: IWatchdog.cs:25
WatchdogStatus
The current status of the watchdog.