public async Task BuildInfoProcessorShouldReturnJobInfo() { var accessor = Substitute.For <IPluginPropertiesAccessor>(); accessor.GetAllUserPropertyValuesAsync <string>(null).ReturnsForAnyArgs(new[] { "TestJob" }); accessor.GetPluginPropertyGroup("Jenkins.Hosts") .Returns( new[] { new [] { new PluginPropertyValue { Key = "Jenkins.Host", Value = "https://jenkins.com", }, new PluginPropertyValue { Key = "Jenkins.User", Value = "Bill", }, new PluginPropertyValue { Key = "Jenkins.Token", Value = "ABC123", }, } }); var result = new JenkinsClient.JobResponse { DisplayName = "Job 1", Description = "Job 1 Desc", Building = true, Result = "RUNNING", Url = "https://jenkins.com/job/1", ChangeSet = new JenkinsClient.ChangeSet { Items = new[] { new JenkinsClient.ChangeSetItem { Comment = "Job Comment" } } } }; var chatEvent = CreateEvent("*****@*****.**"); _jenkinsClient.QueryAsync("TestJob", "https://jenkins.com", "Bill", "ABC123").Returns(result); var info = await _processor.ProcessCommandAsync(null, chatEvent, null, accessor); var widget = info.Cards[0].Sections[0].Widgets[0]; Assert.AreEqual("Job 1", widget.KeyValue.TopLabel); Assert.AreEqual("RUNNING", widget.KeyValue.BottomLabel); Assert.AreEqual("Job Comment", widget.KeyValue.Content); }
/// <inheritdoc/> public async ValueTask <ChatEventResult> ProcessCommandAsync( TextDeconstructionInformation info, ChatEvent originalChatEvent, IAsyncResponder responder, IPluginPropertiesAccessor accessor) { var jobNames = await accessor.GetAllUserPropertyValuesAsync <string>(BuildInfoProperties.JobName); if (jobNames == null || jobNames.Count == 0) { return(new ChatEventResult("No jobs are assign to you!")); } var hosts = accessor.GetPluginPropertyGroup(BuildInfoProperties.HostsGroup).FirstOrDefault(); if (hosts == null) { return(new ChatEventResult("No jenkins hosts are configured!")); } var host = hosts.GetValue <string>(BuildInfoProperties.Host); var user = hosts.GetValue <string>(BuildInfoProperties.User); var token = hosts.GetValue <string>(BuildInfoProperties.Token); var jenkinsResults = await Task.WhenAll( jobNames.Select(jobName => _jenkinsClient.QueryAsync(jobName, host, user, token))); var widgets = jenkinsResults.Select(it => new WidgetMarkup { KeyValue = new KeyValue { TopLabel = it.DisplayName, Content = string.Join(", ", it.ChangeSet?.Items?.Select(cs => cs.Comment)), BottomLabel = it.Result, Button = ChatEventFactory.CreateTextButton("Link", it.Url), }, }).ToList(); return(new ChatEventResult( new Card { Sections = new[] { new Section { Widgets = widgets }, }, })); }