Пример #1
0
        protected override async Task <string> ExecuteRuleAsync(IRule rule, RuleExecutionContext executionContext, CancellationToken cancellationToken = default)
        {
            var result = await rule.ApplyAsync(executionContext, cancellationToken);

            var store = executionContext.store;

            var(created, updated) = await store.SaveChanges(saveMode, !dryRun, rule.ImpersonateExecution, cancellationToken);

            if (created + updated > 0)
            {
                logger.WriteInfo($"Changes saved to Azure DevOps (mode {saveMode}): {created} created, {updated} updated.");
            }
            else
            {
                logger.WriteInfo($"No changes saved to Azure DevOps.");
            }

            return(result.Value);
        }
Пример #2
0
        protected RuleExecutionContext CreateRuleExecutionContext(Guid projectId, WorkItemData workItemPayload, IClientsContext clients)
        {
            var workItem    = workItemPayload.WorkItem;
            var context     = new EngineContext(clients, projectId, workItem.GetTeamProject(), logger);
            var store       = new WorkItemStore(context, workItem);
            var self        = store.GetWorkItem(workItem.Id.Value);
            var selfChanges = new WorkItemUpdateWrapper(workItemPayload.WorkItemUpdate);

            logger.WriteInfo($"Initial WorkItem {self.Id} retrieved from {clients.WitClient.BaseAddress}");

            var globals = new RuleExecutionContext
            {
                self        = self,
                selfChanges = selfChanges,
                store       = store,
                logger      = logger
            };

            return(globals);
        }
Пример #3
0
        /// <inheritdoc />
        public async Task <IRuleResult> ApplyAsync(RuleExecutionContext executionContext, CancellationToken cancellationToken)
        {
            var result = await _roslynScript.RunAsync(executionContext, cancellationToken);

            if (result.Exception != null)
            {
                _logger.WriteError($"Rule failed with {result.Exception}");
                return(new RuleResult()
                {
                    Outcome = RuleExecutionOutcome.Error,
                    Value = result.Exception.ToString()
                });
            }

            _logger.WriteInfo($"Rule succeeded with {result.ReturnValue ?? "no return value"}");
            return(new RuleResult()
            {
                Outcome = RuleExecutionOutcome.Success,
                Value = result.ReturnValue // ?? string.Empty
            });
        }
Пример #4
0
 protected abstract Task <string> ExecuteRuleAsync(IRule rule, RuleExecutionContext executionContext, CancellationToken cancellationToken = default);