tgstation-server 6.12.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.Equals("--repo", StringComparison.OrdinalIgnoreCase)))
54 {
56 return new MessageContent
57 {
58 Text = "Repository busy! Try again later",
59 };
60
61 using var repo = await repositoryManager.LoadRepository(cancellationToken);
62 if (repo == null)
63 return new MessageContent
64 {
65 Text = "Repository unavailable!",
66 };
67 result = repo.Head;
68 }
69 else
70 {
71 if (watchdog.Status == WatchdogStatus.Offline)
72 return new MessageContent
73 {
74 Text = "Server offline!",
75 };
76 result = watchdog.ActiveCompileJob?.RevisionInformation.OriginCommitSha!;
77 }
78
79 return new MessageContent
80 {
81 Text = String.Format(CultureInfo.InvariantCulture, "^{0}", result),
82 };
83 }
84 }
85}
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
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:50
WatchdogStatus Status
The current WatchdogStatus.
Definition IWatchdog.cs:35
WatchdogStatus
The current status of the watchdog.