Ejemplo n.º 1
0
        internal Task Execute(LossSimulationOption lossSimulationOption)
        {
            _dbContext = new GitRepositoryDbContext(false);

            var lossSimulation = CreateLossSimulation(lossSimulationOption);

            var timeMachine = CreateTimeMachine(lossSimulation);

            var knowledgeDistributioneMap = timeMachine.FlyInTime();

            var leavers = GetLeavers(lossSimulation);

            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                SavePullRequestReviewes(knowledgeDistributioneMap, lossSimulation);
                _logger.LogInformation("{datetime}: RecommendedPullRequestReviewes are saved successfully.", DateTime.Now);
                SaveOwnershipDistribution(knowledgeDistributioneMap, lossSimulation, leavers);
                _logger.LogInformation("{datetime}: Ownership Distribution is saved Successfully.", DateTime.Now);

                SavePullRequestSimulatedRecommendationResults(knowledgeDistributioneMap, lossSimulation);
                _logger.LogInformation("{datetime}: Pull Requests Recommendation Results are saved Successfully.", DateTime.Now);

                SaveOpenReviews(knowledgeDistributioneMap, lossSimulation);
                _logger.LogInformation("{datetime}: Developer OpenReviews are saved successfully.", DateTime.Now);

                transaction.Commit();
                _logger.LogInformation("{datetime}: Transaction is committed.", DateTime.Now);
            }

            _logger.LogInformation("{datetime}: trying to save results into database", DateTime.Now);
            _dbContext.SaveChanges();

            lossSimulation.EndDateTime             = DateTime.Now;
            _dbContext.Entry(lossSimulation).State = EntityState.Modified;

            _dbContext.SaveChanges();
            _logger.LogInformation("{datetime}: results have been saved", DateTime.Now);
            _dbContext.Dispose();

            return(Task.CompletedTask);
        }
        public async Task Execute(ExtractBlameForEachPeriodOption options)
        {
            var dbContext = new GitRepositoryDbContext();

            var extractedCommits = await dbContext.CommitBlobBlames.Select(m => m.CommitSha).Distinct().ToArrayAsync().ConfigureAwait(false);

            var periods = await GetPeriods(options, dbContext, extractedCommits).ConfigureAwait(false);

            var canonicalDic = dbContext.GetCanonicalPaths();

            var gitRepository  = new GitRepository(options.RepositoryPath, _logger);
            var orderedCommits = gitRepository.ExtractCommitsFromBranch(options.GitBranch).ToDictionary(q => q.Sha);

            dbContext.Dispose();

            _logger.LogInformation("{datetime}: extracting blames for {count} periods.", DateTime.Now, periods.Count());

            foreach (var period in periods)
            {
                await ExtractBlamesofCommit(orderedCommits[period.LastCommitSha], canonicalDic, options.Extensions, options.ExcludedBlamePaths, gitRepository, options.GitBranch, options.ExtractBlames).ConfigureAwait(false);
            }
        }