Example #1
0
        private PullRequestContext GetPullRequestContext(PullRequest pullRequest, KnowledgeDistributionMap knowledgeMap)
        {
            var pullRequestFiles = PullRequestFilesDic.GetValueOrDefault(pullRequest.Number, new List <PullRequestFile>()).ToArray();

            var period = GetPeriodOfPullRequest(pullRequest);

            var availableDevelopers = GetAvailableDevelopersOfPeriod(pullRequest)
                                      .ToArray();

            var prSubmitter = UsernameRepository.GetByGitHubLogin(pullRequest.UserLogin);

            var pullRequestKnowledgeableDevelopers = GetPullRequestKnowledgeables(pullRequestFiles, knowledgeMap, period);

            var actualReviewers = GetKnowledgeOfActualReviewers(PullRequestReviewersDic.GetValueOrDefault(pullRequest.Number) ?? new List <string>(0), pullRequestKnowledgeableDevelopers);

            return(new PullRequestContext()
            {
                SelectedReviewersType = _selectedReviewersType,
                PRSubmitterNormalizedName = prSubmitter?.NormalizedName,
                ActualReviewers = actualReviewers.ToArray(),
                PullRequestFiles = pullRequestFiles,
                AvailableDevelopers = availableDevelopers,
                PullRequest = pullRequest,
                KnowledgeMap = knowledgeMap,
                CanononicalPathMapper = CanononicalPathMapper,
                PullRequestPeriod = period,
                Periods = this.PeriodsDic,
                Developers = new ReadOnlyDictionary <string, Developer>(DevelopersDic),
                Blames = BlameBasedKnowledgeMap.GetSnapshopOfPeriod(period.Id),
                PullRequestKnowledgeables = pullRequestKnowledgeableDevelopers
            });
        }
Example #2
0
        private void UpdateReviewBasedKnowledgeMap(PullRequest pullRequest)
        {
            var reviewers = PullRequestSimulatedRecommendationDic[pullRequest.Number].SelectedReviewers
                            .Where(q => !_megaDevelopersSet.Contains(q)).Select(reviewerName => DevelopersDic[reviewerName]);
            var period = GetPeriodOfPullRequest(pullRequest);

            // some of the pull requests have no modified files strangely
            // for example, https://github.com/dotnet/coreclr/pull/13534
            foreach (var file in PullRequestFilesDic.GetValueOrDefault(pullRequest.Number, _emptyPullRequestFiles))
            {
                var canonicalPath = CanononicalPathMapper.GetValueOrDefault(file.FileName);
                ReviewBasedKnowledgeMap.Add(canonicalPath, reviewers, pullRequest, period);
            }
        }
Example #3
0
        private void AddProposedChangesToPrSubmitterKnowledge(PullRequest pullRequest)
        {
            // we assume the PR submitter is the dev who has modified the files
            // however it's not the case always. for example https://github.com/dotnet/coreclr/pull/1
            // we assume all the proposed file changes are committed and owned by the main pull request's author
            // which may not be correct in rare scenarios

            if (pullRequest == null)
            {
                return;
            }

            var submitter = UsernameRepository.GetByGitHubLogin(pullRequest.UserLogin);

            // we have ignored mega developers
            if (submitter == null || _megaDevelopersSet.Contains(submitter.NormalizedName))
            {
                return;
            }

            // some of the pull requests have no modified files
            // https://github.com/dotnet/coreclr/pull/13534
            var pullRequestFiles = PullRequestFilesDic.GetValueOrDefault(pullRequest.Number, new List <PullRequestFile>());

            var prSubmitter = submitter.NormalizedName;

            var period = GetPeriodOfPullRequest(pullRequest);

            foreach (var file in pullRequestFiles)
            {
                var canonicalPath = CanononicalPathMapper.GetValueOrDefault(file.FileName);
                AssignKnowledgeToDeveloper(new Commit {
                    NormalizedAuthorName = prSubmitter, PeriodId = period.Id, Sha = pullRequest.MergeCommitSha, AuthorDateTime = pullRequest.MergedAtDateTime.Value
                }, file.ChangeKind, prSubmitter, period, canonicalPath);
            }
        }