public static string GetCard(AzureDevOpsWorkItem workItem)
        {
            var filePath = $"Cards\\{typeof(BugCard).Name}.mustache";
            var fileContentsWithMustachePlaceholders = File.ReadAllText(filePath);
            var compiler      = new FormatCompiler();
            var generator     = compiler.Compile(fileContentsWithMustachePlaceholders);
            var processedCard = generator.Render(BugViewModel.CreateFrom(workItem));

            return(processedCard);
        }
Пример #2
0
        public static BugViewModel CreateFrom(AzureDevOpsWorkItem workItem)
        {
            var result = new BugViewModel()
            {
                Id       = workItem.Id,
                Title    = workItem.Fields.Title,
                Priority = workItem.Fields.Priority,
                State    = workItem.Fields.State,
                Severity = workItem.Fields.Severity,
                BugLink  = workItem.Links.Html.Href
            };

            if (workItem.Fields.AssignedTo != null)
            {
                result.AssignedTo = new BuggablePerson()
                {
                    DisplayName = workItem.Fields.AssignedTo.DisplayName,
                    TeamsUserId = workItem.Fields.AssignedTo.TeamsUserId
                };
            }

            if (workItem.Fields.EMOwner != null)
            {
                result.EMOwner = new BuggablePerson()
                {
                    DisplayName = workItem.Fields.EMOwner.DisplayName,
                    TeamsUserId = workItem.Fields.EMOwner.TeamsUserId
                };
            }

            if (workItem.Fields.PMOwner != null)
            {
                result.PMOwner = new BuggablePerson()
                {
                    DisplayName = workItem.Fields.PMOwner.DisplayName,
                    TeamsUserId = workItem.Fields.PMOwner.TeamsUserId
                };
            }

            return(result);
        }
Пример #3
0
        private async Task CheckAndPostBug(AzureDevOpsWorkItem workItem, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var bugAdaptiveCard = BugCard.GetCard(workItem);

            var exponentialBackoffRetryStrategy = new ExponentialBackoff(3, TimeSpan.FromSeconds(2),
                                                                         TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(1));


            // Define the Retry Policy
            var retryPolicy = new RetryPolicy(new BotSdkTransientExceptionDetectionStrategy(), exponentialBackoffRetryStrategy);

            var replyActivity = MessageFactory.Attachment(new Attachment()
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content     = JsonConvert.DeserializeObject(bugAdaptiveCard),
            });

            // Set summary text so make sure users have more useful information in the notifcation feed in Teams instead of just "Sent a card".
            replyActivity.Summary = GetActivitySummaryText(workItem);

            await retryPolicy.ExecuteAsync(() => turnContext.SendActivityAsync(replyActivity));
        }
Пример #4
0
 private static string GetActivitySummaryText(AzureDevOpsWorkItem workItem)
 {
     return($"BUG {workItem.Id} - {workItem.Fields.Title}");
 }