1 using Microsoft.EntityFrameworkCore;
3 using System.Collections.Generic;
7 using System.Threading.Tasks;
21 public string Name =>
"prs";
24 public string HelpText =>
"Display live test merge pull request numbers. Add --repo to view repository test merges";
27 public bool AdminOnly =>
false;
58 this.watchdog = watchdog ??
throw new ArgumentNullException(nameof(watchdog));
59 this.repositoryManager = repositoryManager ??
throw new ArgumentNullException(nameof(repositoryManager));
60 this.databaseContextFactory = databaseContextFactory ??
throw new ArgumentNullException(nameof(databaseContextFactory));
61 this.instance = instance ??
throw new ArgumentNullException(nameof(instance));
66 #pragma warning disable CA1506 67 public async Task<string>
Invoke(
string arguments,
ChatUser user, CancellationToken cancellationToken)
69 IEnumerable<Models.TestMerge> results = null;
70 if (arguments.Split(
' ').Any(x => x.ToUpperInvariant() ==
"--REPO"))
73 using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(
false))
76 return "Repository unavailable!";
80 await databaseContextFactory.UseContext(
81 async db => results = await db
84 .Where(x => x.Instance.Id == instance.Id && x.CommitSha == head)
85 .SelectMany(x => x.ActiveTestMerges)
86 .Select(x => x.TestMerge)
87 .Select(x =>
new Models.TestMerge
90 PullRequestRevision = x.PullRequestRevision
92 .ToListAsync(cancellationToken)
93 .ConfigureAwait(
false))
94 .ConfigureAwait(
false);
99 return "Server offline!";
100 results = watchdog.ActiveCompileJob?.RevisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList() ??
new List<Models.TestMerge>();
103 return !results.Any() ?
"None!" : String.Join(
", ", results.Select(x => String.Format(CultureInfo.InvariantCulture,
"#{0} at {1}", x.Number, x.PullRequestRevision.Substring(0, 7))));
105 #pragma warning restore CA1506 readonly IDatabaseContextFactory databaseContextFactory
The IDatabaseContextFactory for the PullRequestsCommand
Use server authentication
Factory for scoping usage of IDatabaseContexts. Meant for use by Components
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand
WatchdogStatus
The current status of the watchdog.
readonly Models.Instance instance
The Models.Instance for the PullRequestsCommand
Command for reading the active TestMerges
Represents a tgs_chat_user datum
readonly IWatchdog watchdog
The IWatchdog for the PullRequestsCommand
Factory for creating and loading IRepositorys
async Task< string > Invoke(string arguments, ChatUser user, CancellationToken cancellationToken)
Invoke the ICommand
PullRequestsCommand(IWatchdog watchdog, IRepositoryManager repositoryManager, IDatabaseContextFactory databaseContextFactory, Models.Instance instance)
Construct a PullRequestsCommand
Represents a command that can be invoked by talking to chat bots
Runs and monitors the twin server controllers