Ejemplo n.º 1
0
        public async Task <IActionResult> OnGet()
        {
            const int PageSize = 25;

            if (string.IsNullOrEmpty(BuildQuery))
            {
                BuildQuery = new SearchBuildsRequest()
                {
                    Definition = "runtime"
                }.GetQueryString();
                return(Page());
            }

            if (!SearchBuildsRequest.TryCreate(BuildQuery ?? "", out var buildsRequest, out var errorMessage) ||
                !SearchTimelinesRequest.TryCreate(TimelineQuery ?? "", out var timelinesRequest, out errorMessage))
            {
                ErrorMessage = errorMessage;
                return(Page());
            }

            try
            {
                IQueryable <ModelTimelineIssue> query = TriageContextUtil.Context.ModelTimelineIssues;
                query = buildsRequest.Filter(query);
                query = timelinesRequest.Filter(query);
                var totalCount = await query.CountAsync();

                query = query
                        .OrderByDescending(x => x.ModelBuild.BuildNumber)
                        .Skip(PageNumber * PageSize)
                        .Take(PageSize);
                TimelineIssuesDisplay = await TimelineIssuesDisplay.Create(
                    query,
                    includeBuildColumn : true,
                    includeIssueTypeColumn : timelinesRequest.Type is null,
                    includeAttemptColumn : true);

                IncludeIssueTypeColumn = timelinesRequest.Type is null;
                PaginationDisplay      = new PaginationDisplay(
                    "/Search/Timelines",
                    new Dictionary <string, string>()
                {
                    { "bq", BuildQuery ?? "" },
                    { "tq", TimelineQuery ?? "" }
                },
                    PageNumber,
                    totalCount / PageSize);
                TotalCount = totalCount;
                return(Page());
            }
            catch (SqlException ex) when(ex.IsTimeoutViolation())
            {
                ErrorMessage = "Timeout fetching data from the server";
                return(Page());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGet()
        {
            if (!(Number is { } number))
            {
                return(Page());
            }

            var buildKey     = GetBuildKey(number);
            var project      = buildKey.Project;
            var organization = buildKey.Organization;
            var buildId      = TriageContextUtil.GetModelBuildId(buildKey);

            var modelBuild = await PopulateBuildInfo();

            await PopulateTimeline();
            await PopulateTests();

            return(Page());

            async Task <ModelBuild?> PopulateBuildInfo()
            {
                var modelBuild = await TriageContextUtil
                                 .GetModelBuildQuery(buildKey)
                                 .Include(x => x.ModelGitHubIssues)
                                 .FirstOrDefaultAsync();

                if (modelBuild is null)
                {
                    return(null);
                }

                BuildUri       = DevOpsUtil.GetBuildUri(organization, project, number);
                BuildResult    = modelBuild.BuildResult ?? BuildResult.None;
                Repository     = $"{modelBuild.GitHubOrganization}/{modelBuild.GitHubRepository}";
                RepositoryUri  = $"https://{modelBuild.GitHubOrganization}/{modelBuild.GitHubRepository}";
                DefinitionName = modelBuild.DefinitionName;
                TargetBranch   = modelBuild.GitHubTargetBranch;
                GitHubIssues.Clear();
                GitHubIssues.AddRange(modelBuild.ModelGitHubIssues.Select(x => x.GetGitHubIssueKey()));

                if (modelBuild.PullRequestNumber is { } prNumber)
                {
                    PullRequestKey = new GitHubPullRequestKey(
                        modelBuild.GitHubOrganization,
                        modelBuild.GitHubRepository,
                        prNumber);
                }

                return(modelBuild);
            }

            async Task PopulateTimeline()
            {
                var query = TriageContextUtil
                            .Context
                            .ModelTimelineIssues
                            .Where(x => x.ModelBuildId == buildId)
                            .Include(x => x.ModelBuild);

                TimelineIssuesDisplay = await TimelineIssuesDisplay.Create(
                    query,
                    includeBuildColumn : false,
                    includeIssueTypeColumn : true,
                    includeAttemptColumn : true);

                Attempts = TimelineIssuesDisplay.Issues.Count > 0
                    ? TimelineIssuesDisplay.Issues.Max(x => x.Attempt)
                    : 1;
            }

            async Task PopulateTests()
            {
                var query = TriageContextUtil
                            .Context
                            .ModelTestResults
                            .Where(x => x.ModelBuildId == buildId)
                            .Include(x => x.ModelTestRun)
                            .Include(x => x.ModelBuild);
                var modelTestResults = await query.ToListAsync();

                TestResultsDisplay = new TestResultsDisplay(modelTestResults)
                {
                    IncludeBuildColumn        = false,
                    IncludeBuildKindColumn    = false,
                    IncludeTestFullNameColumn = true,
                    IncludeTestFullNameLinks  = true,
                    IncludeErrorMessageColumn = true,
                };

                if (modelBuild is object)
                {
                    TestResultsDisplay.BuildsRequest = new SearchBuildsRequest()
                    {
                        Definition = modelBuild.DefinitionName,
                        Started    = new DateRequestValue(dayQuery: 7)
                    };
                }
            }
        }