Esempio n. 1
0
    public async Task <ActionResult> MarkFixedAsync(string ids, string version = null)
    {
        SemanticVersion semanticVersion = null;

        if (!String.IsNullOrEmpty(version))
        {
            semanticVersion = await _semanticVersionParser.ParseAsync(version);

            if (semanticVersion == null)
            {
                return(BadRequest("Invalid semantic version"));
            }
        }

        var stacks = await GetModelsAsync(ids.FromDelimitedString(), false);

        if (!stacks.Any())
        {
            return(NotFound());
        }

        if (stacks.Count > 0)
        {
            foreach (var stack in stacks)
            {
                stack.MarkFixed(semanticVersion);
            }

            await _stackRepository.SaveAsync(stacks);
        }

        return(Ok());
    }
        public override async Task ProcessBatchAsync(ICollection <EventContext> contexts)
        {
            var stacks = contexts.Where(c => !c.Stack.IsRegressed && c.Stack.DateFixed.HasValue).OrderBy(c => c.Event.Date).GroupBy(c => c.Event.StackId);

            foreach (var stackGroup in stacks)
            {
                try {
                    var stack = stackGroup.First().Stack;

                    EventContext    regressedContext = null;
                    SemanticVersion regressedVersion = null;
                    if (String.IsNullOrEmpty(stack.FixedInVersion))
                    {
                        regressedContext = stackGroup.FirstOrDefault(c => stack.DateFixed < c.Event.Date.UtcDateTime);
                    }
                    else
                    {
                        var fixedInVersion = await _semanticVersionParser.ParseAsync(stack.FixedInVersion).AnyContext();

                        var versions = stackGroup.GroupBy(c => c.Event.GetVersion());
                        foreach (var versionGroup in versions)
                        {
                            var version = await _semanticVersionParser.ParseAsync(versionGroup.Key).AnyContext() ?? _semanticVersionParser.Default;

                            if (version < fixedInVersion)
                            {
                                continue;
                            }

                            regressedVersion = version;
                            regressedContext = versionGroup.First();
                            break;
                        }
                    }

                    if (regressedContext == null)
                    {
                        return;
                    }

                    _logger.LogTrace("Marking stack and events as regressed in version: {Version}", regressedVersion);
                    stack.IsRegressed = true;
                    await _stackRepository.MarkAsRegressedAsync(stack.Id).AnyContext();

                    await _workItemQueue.EnqueueAsync(new StackWorkItem {
                        OrganizationId = stack.OrganizationId,
                        ProjectId      = stack.ProjectId,
                        StackId        = stack.Id,
                        UpdateIsFixed  = true,
                        IsFixed        = false
                    }).AnyContext();

                    foreach (var ctx in stackGroup)
                    {
                        ctx.Event.IsFixed = false;
                        ctx.IsRegression  = ctx == regressedContext;
                    }
                } catch (Exception ex) {
                    foreach (var context in stackGroup)
                    {
                        bool cont = false;
                        try {
                            cont = HandleError(ex, context);
                        } catch {}

                        if (!cont)
                        {
                            context.SetError(ex.Message, ex);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public async Task CanParseSemanticVersion(string input, string expected)
        {
            var actual = await _parser.ParseAsync(input);

            Assert.Equal(expected, actual?.ToString());
        }