1 using Microsoft.EntityFrameworkCore;
3 using System.Collections.Generic;
7 using System.Threading.Tasks;
20 public string Name =>
"prs";
23 public string HelpText =>
"Display live test merge pull request numbers. Add --repo to view repository test merges";
26 public bool AdminOnly =>
false;
57 this.watchdog = watchdog ??
throw new ArgumentNullException(nameof(watchdog));
58 this.repositoryManager = repositoryManager ??
throw new ArgumentNullException(nameof(repositoryManager));
59 this.databaseContextFactory = databaseContextFactory ??
throw new ArgumentNullException(nameof(databaseContextFactory));
60 this.instance = instance ??
throw new ArgumentNullException(nameof(instance));
65 #pragma warning disable CA1506 66 public async Task<string>
Invoke(
string arguments,
ChatUser user, CancellationToken cancellationToken)
68 IEnumerable<Models.TestMerge> results = null;
69 if (arguments.Split(
' ').Any(x => x.ToUpperInvariant() ==
"--REPO"))
72 using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(
false))
75 return "Repository unavailable!";
79 await databaseContextFactory.UseContext(
80 async db => results = await db
83 .Where(x => x.Instance.Id == instance.Id && x.CommitSha == head)
84 .SelectMany(x => x.ActiveTestMerges)
85 .Select(x => x.TestMerge)
86 .Select(x =>
new Models.TestMerge
89 PullRequestRevision = x.PullRequestRevision
91 .ToListAsync(cancellationToken)
92 .ConfigureAwait(
false))
93 .ConfigureAwait(
false);
97 if (!watchdog.Running)
98 return "Server offline!";
99 results = watchdog.ActiveCompileJob?.RevisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList() ??
new List<Models.TestMerge>();
102 return !results.Any() ?
"None!" : String.Join(
", ", results.Select(x => String.Format(CultureInfo.InvariantCulture,
"#{0} at {1}", x.Number, x.PullRequestRevision.Substring(0, 7))));
104 #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
readonly Models.Instance instance
The Models.Instance for the PullRequestsCommand
Command for reading the active Api.Models.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