public void Execute(SlashCommand command) { try { Entities.Merge merge = Slack.MessageParser.ForMerge(command); merge.Verify(); Entities.Queue queue = new Entities.Queue() { MaxWokers = 1, Name = merge.Target }; queueBLL.Insert(queue); long enqueuedCount = Hangfire.JobStorage.Current.GetMonitoringApi().EnqueuedCount(queue.Name); IBackgroundJobClient client = new BackgroundJobClient(); IState state = new EnqueuedState(queue.Name); client.Create<BusinessLogic.Merge.Base.ITrigger>(x => x.Execute(command), state); if(enqueuedCount > 0) { slackBLL.DirectMessage(command, $"There {(enqueuedCount > 1 ? "are" : "is")} {enqueuedCount} {(enqueuedCount > 1 ? "merges" : "merge")} ahead of yours."); } } catch(ArgumentException ex) { slackBLL.DirectMessage(command, $"Failed to schedule merge: {ex.Message}"); } }
public async void Channel(SlashCommand command, string text) { if(command.channel_name == "privategroup" || command.channel_name == "directmessage") { this.DirectMessage(command, text); } else { Dictionary<string, string> settings = settingsBLL.Get(); List<string> toAddress = new List<string>(); using (var client = factory.HttpClient()) { client.BaseAddress = new Uri(settings["Notification.SlackWebhook"]); Entities.Slack.OutboundPayload payload = new Entities.Slack.OutboundPayload { channel = command.channel_name, text = $"<@{command.user_name}>: " + text, username = userName }; await client.PostAsJsonAsync<Entities.Slack.OutboundPayload>("", payload).ConfigureAwait(false); } } }
public void Execute(SlashCommand command) { Dictionary<string, string> settings = settingsBLL.Get(); string workingCopyBase = SettingsHelper.ValidateAndReturnMergeWorkingCopyBase(settings); Entities.Merge merge = Slack.MessageParser.ForMerge(command); merge.Verify(); List<string> branchNames = new List<string> { merge.Source, merge.Target }; List<Entities.Branch> branches = selectBranchBLL.Execute(branchNames); Entities.Branch source = branches.Find(x => x.Name.ToLower() == merge.Source.ToLower()); Entities.Branch target = branches.Find(x => x.Name.ToLower() == merge.Target.ToLower()); StringBuilder logMessages = new StringBuilder(); List<Entities.RevisionRange> eligible = eligibleRevisions.Execute(source, target); List<Entities.RevisionRange> ranges = searchLogBLL.Execute(source, merge.Query, logMessages, eligible); mergeBLL = BusinessLogic.Core.UnityConfig.Container.Resolve<BusinessLogic.VersionControl.Base.IMerge>("Svn.IMerge"); commitBLL = BusinessLogic.Core.UnityConfig.Container.Resolve<BusinessLogic.VersionControl.Base.ICommit>("Svn.ICommit"); bool successful = mergeBLL.Execute(workingCopyBase, source, target, ranges); string message = Notifications.Message.Merge(merge, successful); if (successful) { StringBuilder sb = new StringBuilder(); sb.Append(message); sb.AppendLine(""); StringBuilder revisions = new StringBuilder(); ranges.ForEach(x => revisions.Append($"{x.EndRevision},")); sb.AppendLine(revisions.ToString().TrimEnd(',')); sb.AppendLine(""); if (!string.IsNullOrWhiteSpace(merge.Message)) { sb.AppendLine(merge.Message); } sb.AppendLine(logMessages.ToString()); commitBLL.Execute(workingCopyBase, target, sb.ToString()); } slackNotificationBLL.Channel(command, message); }
public async void DirectMessage(SlashCommand command, string text) { Dictionary<string, string> settings = settingsBLL.Get(); List<string> toAddress = new List<string>(); using (var client = factory.HttpClient()) { client.BaseAddress = new Uri(settings["Notification.SlackWebhook"]); Entities.Slack.OutboundPayload payload = new Entities.Slack.OutboundPayload { channel = $"@{command.user_name}", text = text, username = userName }; await client.PostAsJsonAsync<Entities.Slack.OutboundPayload>("", payload).ConfigureAwait(false); } }