Exemplo n.º 1
0
        public async Task OnPullRequestMergedAsync(
            DevOpsServer server,
            TriageContextUtil triageContextUtil,
            GitHubPullRequestKey prKey,
            string project,
            CancellationToken cancellationToken = default)
        {
            // Pull requests can trigger builds in multiple definitions. Need to calculate the merged PR build
            // for each of them
            var allBuilds = await server.ListPullRequestBuildsAsync(prKey, project).ConfigureAwait(false);

            foreach (var group in allBuilds.GroupBy(x => x.Definition.Id))
            {
                var mergedBuild = group
                                  .Where(x => x.Status == BuildStatus.Completed && x.Result != BuildResult.Canceled)
                                  .OrderByDescending(x => x.Id)
                                  .FirstOrDefault();
                if (mergedBuild is object)
                {
                    var modelBuild = await triageContextUtil.EnsureBuildAsync(mergedBuild.GetBuildResultInfo()).ConfigureAwait(false);

                    modelBuild.IsMergedPullRequest = true;
                    await triageContextUtil.Context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 2
0
        public async IAsyncEnumerable <(PullRequest PullReuqest, Build Build)> EnumerateMergedPullRequestBuilds(
            DevOpsServer server,
            GitHubBuildInfo gitHubInfo,
            string project,
            int[]?definitions)
        {
            await foreach (var pullRequest in EnumerateClosedPullRequests(gitHubInfo.Organization, gitHubInfo.Repository).ConfigureAwait(false))
            {
                var   prKey = new GitHubPullRequestKey(gitHubInfo.Organization, gitHubInfo.Repository, pullRequest.Number);
                Build?build = null;
                try
                {
                    var builds = (await server.ListPullRequestBuildsAsync(prKey, project, definitions).ConfigureAwait(false))
                                 .OrderByDescending(b => b.BuildNumber)
                                 .Where(x => x.Status == BuildStatus.Completed && x.Result != BuildResult.Canceled)
                                 .ToList();
                    if (builds.Count > 0)
                    {
                        build = builds[0];
                    }
                }
                catch (Exception)
                {
                    // Error enumerating builds, continue to the next one
                }

                if (build is object)
                {
                    yield return(pullRequest, build);
                }
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGet()
        {
            if (string.IsNullOrEmpty(Query))
            {
                Query = new SearchBuildsRequest()
                {
                    Repository = "runtime"
                }.GetQueryString();
                return(Page());
            }

            const int pageSize = 50;
            var       options  = new SearchBuildsRequest();

            options.ParseQueryString(Query);
            IQueryable <ModelBuild> query = TriageContextUtil.Context.ModelBuilds
                                            .Include(x => x.ModelBuildDefinition);
            var results = await options.Filter(query)
                          .Where(x => x.PullRequestNumber != null && x.IsMergedPullRequest)
                          .OrderByDescending(x => x.BuildNumber)
                          .Skip(PageNumber * pageSize)
                          .Take(pageSize)
                          .ToListAsync();

            var builds = results
                         .Select(b =>
            {
                var prNumber = b.PullRequestNumber !.Value;
                return(new MergedBuildInfo()
                {
                    Repository = b.GitHubRepository,
                    PullRequestUri = GitHubPullRequestKey.GetPullRequestUri(b.GitHubOrganization, b.GitHubRepository, prNumber),
                    PullRequestNumber = prNumber,
                    BuildUri = b.GetBuildResultInfo().BuildUri,
                    BuildNumber = b.BuildNumber,
                    DefinitionUri = b.ModelBuildDefinition.GetDefinitionKey().DefinitionUri,
                    DefinitionName = b.ModelBuildDefinition.DefinitionName,
                    Result = b.BuildResult !.Value,
                });
            })
Exemplo n.º 4
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)
                    };
                }
            }
        }