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));
64 public async Task<string>
Invoke(
string arguments,
User user, CancellationToken cancellationToken)
66 IEnumerable<Models.TestMerge> results = null;
67 if (arguments.Split(
' ').Any(x => x.ToUpperInvariant() ==
"--REPO"))
70 using (var repo = await repositoryManager.LoadRepository(cancellationToken).ConfigureAwait(
false))
73 return "Repository unavailable!";
76 await databaseContextFactory.UseContext(async db => results = await db.RevisionInformations.Where(x => x.Instance.Id == instance.Id && x.CommitSha == head)
77 .SelectMany(x => x.ActiveTestMerges)
78 .Select(x => x.TestMerge)
79 .Select(x =>
new Models.TestMerge
82 PullRequestRevision = x.PullRequestRevision
83 }).ToListAsync(cancellationToken).ConfigureAwait(
false)).ConfigureAwait(
false);
87 if (!watchdog.Running)
88 return "Server offline!";
89 results = watchdog.ActiveCompileJob?.RevisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList() ??
new List<Models.TestMerge>();
95 return String.Join(
", ", results.Select(x => String.Format(CultureInfo.InvariantCulture,
"#{0} at {1}", x.Number, x.PullRequestRevision.Substring(0, 7))));
readonly IDatabaseContextFactory databaseContextFactory
The IDatabaseContextFactory for the PullRequestsCommand
Use server authentication
readonly IRepositoryManager repositoryManager
The IRepositoryManager for the PullRequestsCommand
Factory for scoping usage of IDatabaseContexts. Meant for use by Components
readonly Models.Instance instance
The Models.Instance for the PullRequestsCommand
Command for reading the active Api.Models.TestMerges
readonly IWatchdog watchdog
The IWatchdog for the PullRequestsCommand
Represents a tgs_chat_user datum
Factory for creating and loading IRepositorys
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
async Task< string > Invoke(string arguments, User user, CancellationToken cancellationToken)
Invoke the ICommand
Runs and monitors the twin server controllers