/// <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 }, }, })); }
/// <inheritdoc/> public async ValueTask <ChatEventResult> ProcessCommandAsync( TextDeconstructionInformation info, ChatEvent originalChatEvent, IAsyncResponder responder, IPluginPropertiesAccessor accessor) { var hosts = accessor.GetPluginPropertyGroup(IssuesProperties.HostsGroup).FirstOrDefault(); if (hosts == null) { return(new ChatEventResult("No jira hosts are configured!")); } var host = hosts.GetValue <string>(IssuesProperties.Host); var user = hosts.GetValue <string>(IssuesProperties.User); var token = hosts.GetValue <string>(IssuesProperties.Token); var project = info.Entities.GetValueOrDefault("Project")?.FirstOrDefault(); var status = info.Entities.GetValueOrDefault("State")?.FirstOrDefault(); if (string.IsNullOrEmpty(project) || string.IsNullOrEmpty(status)) { return(new ChatEventResult("If you try to get Jira issues, please provide project and status!")); } var result = await _jenkinsClient.QueryAsync(project, status, host, user, token); var widgets = result.Issues.Select(it => new WidgetMarkup { KeyValue = new KeyValue { TopLabel = it.Key, Content = it.Fields.Summary, BottomLabel = it.Fields.Assignee != null ? $"Assigned to {it.Fields.Assignee.DisplayName}" : null }, }).ToList(); return(new ChatEventResult( new Card { Sections = new[] { new Section { Widgets = widgets }, }, })); }
private async Task SaveGlobalStatisticsAsync( DateTime scheduleDate, IReadOnlyList <string> customerToExcludes, IPluginPropertiesAccessor accessor, ITimesheetProcessor processor) { var group = accessor.GetPluginPropertyGroup(TimesheetsProperties.GlobalStatisticsGroup).FirstOrDefault(); if (group == null) { return; } var cron = group.GetValue <string>(TimesheetsProperties.GlobalStatisticsCron); if (string.IsNullOrEmpty(cron) || !CronCheck(cron, scheduleDate)) { return; } const TimesheetStates state = TimesheetStates.Unsubmitted; var dateValue = scheduleDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); var timeValue = scheduleDate.ToString("HH:00", CultureInfo.InvariantCulture); var email = group.GetValue <string>(TimesheetsProperties.GlobalStatisticsEmail); var timesheets = await processor.GetTimesheetsAsync(scheduleDate, state, email, true, customerToExcludes); var statistics = new Statistics <TimesheetStatistics[]> { Id = Guid.NewGuid().ToString(), Date = dateValue, Time = timeValue, Type = nameof(TimesheetStatistics), Data = timesheets .Select(it => new TimesheetStatistics { UserName = it.UserName, ManagerName = it.ManagerName, DepartmentName = it.DepartmentName, State = state, }) .ToArray() }; await _storageService.AddOrUpdateStatisticsAsync(statistics); }