2using System.Collections.Generic;
5using System.Threading.Tasks;
7using Microsoft.EntityFrameworkCore;
24 public string Name =>
"prs";
27 public string HelpText =>
"Display live test merge numbers. Add --repo to view test merges in the repository as opposed to live. Add --staged to view PRs in the upcoming deployment.";
72 this.watchdog =
watchdog ??
throw new ArgumentNullException(nameof(
watchdog));
76 this.instance =
instance ??
throw new ArgumentNullException(nameof(
instance));
81#pragma warning disable CA1506
82 public async ValueTask<MessageContent>
Invoke(
string arguments,
ChatUser user, CancellationToken cancellationToken)
84 IEnumerable<Models.TestMerge> results;
85 var splits = arguments.Split(
' ');
86 var hasRepo = splits.Any(x => x.Equals(
"--repo", StringComparison.OrdinalIgnoreCase));
87 var hasStaged = splits.Any(x => x.Equals(
"--staged", StringComparison.OrdinalIgnoreCase));
89 if (hasStaged && hasRepo)
92 Text =
"Please use only one of `--staged` or `--repo`",
100 Text =
"Repository busy! Try again later",
109 Text =
"Repository unavailable!",
117 async db => results = await db
118 .RevisionInformations
120 .Where(x => x.Instance!.Id ==
instance.Id && x.CommitSha == head)
121 .SelectMany(x => x.ActiveTestMerges!)
122 .Select(x => x.TestMerge)
123 .Select(x =>
new Models.TestMerge
126 TargetCommitSha = x.TargetCommitSha,
128 .ToListAsync(cancellationToken));
133 Text =
"Server offline!",
141 if (latestCompileJob?.Id != compileJobToUse?.Id)
142 compileJobToUse = latestCompileJob;
144 compileJobToUse =
null;
147 results = compileJobToUse?.RevisionInformation.ActiveTestMerges?.Select(x => x.TestMerge).ToList() ?? Enumerable.Empty<Models.TestMerge>();
152 Text = !results.Any()
157 x => $
"#{x.Number} at {x.TargetCommitSha![..7]}")),
160#pragma warning restore CA1506
Represents a tgs_chat_user datum.
Command for reading the active TestMerges.
readonly IDatabaseContextFactory databaseContextFactory
The IDatabaseContextFactory for the PullRequestsCommand.
string Name
The text to invoke the command. May not be "?" or "help" (case-insensitive).
readonly Models.Instance instance
The Models.Instance for the PullRequestsCommand.
string HelpText
The help text to display when queires are made about the command.
bool AdminOnly
If the command should only be available to ChatUsers who's ChatUser.Channel has ChannelRepresentation...
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 IWatchdog watchdog
The IWatchdog for the PullRequestsCommand.
PullRequestsCommand(IWatchdog watchdog, IRepositoryManager repositoryManager, IDatabaseContextFactory databaseContextFactory, ILatestCompileJobProvider compileJobProvider, Models.Instance instance)
Initializes a new instance of the PullRequestsCommand class.
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand.
readonly ILatestCompileJobProvider compileJobProvider
The ILatestCompileJobProvider for the PullRequestsCommand.
Represents a message to send to a chat provider.
Represents an Api.Models.Instance in the database.
Represents a command that can be invoked by talking to chat bots.
Provides the most recently deployed CompileJob.
ValueTask< CompileJob?> LatestCompileJob()
Gets the latest CompileJob.
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.
Models.? CompileJob ActiveCompileJob
Retrieves the Models.CompileJob currently running on the server.
WatchdogStatus Status
The current WatchdogStatus.
Factory for scoping usage of IDatabaseContexts. Meant for use by Components.
ValueTask UseContext(Func< IDatabaseContext, ValueTask > operation)
Run an operation in the scope of an IDatabaseContext.
WatchdogStatus
The current status of the watchdog.