Ejemplo n.º 1
0
        public async Task Execute(string token, string agenName, string owner, string repo, string branch)
        {
            using (var dbContext = new GitRepositoryDbContext(true))
            {
                dbContext.Database.ExecuteSqlCommand($"TRUNCATE TABLE PullRequests");
                var githubExtractor = new GithubDataFetcher(token, agenName, _logger);
                var pullRequests    = await githubExtractor.FetchAllPullRequests(owner, repo).ConfigureAwait(false);

                _logger.LogInformation("{datetime}: trying to save {count} pull requests.", DateTime.Now, pullRequests.Length);
                foreach (PullRequest pullrequest in pullRequests)
                {
                    var startdate = pullrequest.CreatedAtDateTime;
                    var enddate   = pullrequest.ClosedAtDateTime;
                    var overlap   = pullRequests.Where(a => a.ClosedAtDateTime > startdate && a.CreatedAtDateTime < enddate && a.Number != pullrequest.Number).ToList();
                    foreach (PullRequest item in overlap)
                    {
                        if (item.Number < pullrequest.Number)
                        {
                            pullrequest.OverlapPullRequest = string.Concat(pullrequest.OverlapPullRequest, item.Number.ToString() + ",");
                        }
                    }
                }
                dbContext.AddRange(pullRequests);
                dbContext.SaveChanges();
                _logger.LogInformation("{datetime}: pull requests has been saved successfully.", DateTime.Now);
            }
        }
Ejemplo n.º 2
0
        public async Task Execute(string token, string agenName, string owner, string repo)
        {
            using (var dbContext = new GitRepositoryDbContext())
            {
                var loadedIssues    = dbContext.Issue.ToArray();
                var githubExtractor = new GithubDataFetcher(token, agenName, _logger);
                var issueEvents     = await githubExtractor.GetIssueEvents(owner, repo, loadedIssues).ConfigureAwait(false);

                dbContext.AddRange(issueEvents);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public async Task Execute(string token, string agenName, string owner, string repo, string[] labels, string state = "All")
        {
            using (var dbContext = new GitRepositoryDbContext())
            {
                dbContext.Database.ExecuteSqlCommand($"TRUNCATE TABLE Issue");
                var githubExtractor = new GithubDataFetcher(token, agenName, _logger);
                var issues          = await githubExtractor.GetIssues(owner, repo, labels, state).ConfigureAwait(false);

                dbContext.AddRange(issues);
                dbContext.SaveChanges();
            }
        }
        public async Task Execute(string token, string agenName, string owner, string repo, string branch)
        {
            using (var dbContext = new GitRepositoryDbContext(true))
            {
                dbContext.Database.ExecuteSqlCommand($"TRUNCATE TABLE PullRequests");
                var githubExtractor = new GithubDataFetcher(token, agenName, _logger);
                var pullRequests    = await githubExtractor.FetchAllPullRequests(owner, repo).ConfigureAwait(false);

                _logger.LogInformation("{datetime}: trying to save {count} pull requests.", DateTime.Now, pullRequests.Length);
                dbContext.AddRange(pullRequests);
                dbContext.SaveChanges();
                _logger.LogInformation("{datetime}: pull requests has been saved successfully.", DateTime.Now);
            }
        }
Ejemplo n.º 5
0
        private void SaveLeaversAndFilesAtRisk(LossSimulation lossSimulation, KnowledgeDistributionMap knowledgeDistributioneMap, Dictionary <long, IEnumerable <SimulatedLeaver> > leavers)
        {
            var bulkEntities = new List <SimulatedAbondonedFile>();

            foreach (var period in _periods)
            {
                _logger.LogInformation("{datetime}: computing knowledge loss for period {pid}.", DateTime.Now, period.Id);

                var availableDevelopers = GetAvailableDevelopersOfPeriod(period);

                _dbContext.AddRange(leavers[period.Id]);

                var abandonedFiles = GetAbandonedFiles(period, leavers[period.Id], availableDevelopers, knowledgeDistributioneMap, lossSimulation);
                bulkEntities.AddRange(abandonedFiles);

                _logger.LogInformation("{datetime}: computing knowledge loss for period {pid} is done.", DateTime.Now, period.Id);
            }

            _dbContext.BulkInsert(bulkEntities);
        }
Ejemplo n.º 6
0
        public async Task Execute(string token, string agentName)
        {
            using (var dbContext = new GitRepositoryDbContext())
            {
                dbContext.Database.ExecuteSqlCommand($"TRUNCATE TABLE Users");
                var unknownUsers = dbContext.Users
                                   .FromSql(@"Select UserLogin,null AS Name, NULL as Email from (
                            select distinct(UserLogin) AS UserLogin from PullRequests  WHERE UserLogin IS NOT null
                            union   
                            select distinct(UserLogin) AS UserLogin from PullRequestReviewers  WHERE UserLogin IS NOT null
                            union   
                            select distinct(UserLogin) from PullRequestReviewerComments WHERE UserLogin IS NOT null) AS Temp")
                                   .ToArray();

                var githubExtractor = new GithubDataFetcher(token, agentName, _logger);
                await githubExtractor.GetUsers(unknownUsers).ConfigureAwait(false);

                dbContext.AddRange(unknownUsers);
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Ejemplo n.º 7
0
        public async Task Execute()
        {
            using (var dbContext = new GitRepositoryDbContext(false))
            {
                var normalizedDevelopers = new List <AliasedDeveloperName>();

                var authorsPlace = new Dictionary <string, string>();

                var authors = dbContext.Commits
                              .Select(m => new { m.AuthorEmail, m.AuthorName })
                              .Distinct()
                              .ToArray();

                _logger.LogInformation("{datetime}: there are {count} authors submitted all the commits.", DateTime.Now, authors.Count());

                foreach (var author in authors)
                {
                    var normalizedEmail = author.AuthorEmail
                                          .Replace(" ", string.Empty)
                                          .Replace(".", string.Empty)
                                          .Replace("[", string.Empty)
                                          .Replace("]", string.Empty)
                                          .Replace("_", string.Empty)
                                          .Replace("-", string.Empty)
                                          .Replace("(", string.Empty)
                                          .Replace(")", string.Empty)
                                          .ToLower()
                                          .Trim()
                                          .RemoveDiacritics();

                    var normalizedName = author.AuthorName
                                         .Replace(" ", string.Empty)
                                         .Replace(".", string.Empty)
                                         .Replace("[", string.Empty)
                                         .Replace("]", string.Empty)
                                         .Replace("_", string.Empty)
                                         .Replace("-", string.Empty)
                                         .Replace("(", string.Empty)
                                         .Replace(")", string.Empty)
                                         .Trim()
                                         .ToLower()
                                         .RemoveDiacritics();

                    if (authorsPlace.ContainsKey(normalizedName))
                    {
                        var uniqueId = authorsPlace[normalizedName];

                        if (authorsPlace.ContainsKey(normalizedEmail) &&
                            authorsPlace[normalizedEmail] != uniqueId)
                        {
                            /* it supports following edge case:
                             * Occurence 1 ehsan,[email protected]
                             * Occurence 2 ali,[email protected]
                             * Occurence 3 ehsan,[email protected]
                             */

                            var oldUniqueId = authorsPlace[normalizedEmail];

                            foreach (var dev in normalizedDevelopers.Where(q => q.NormalizedName == oldUniqueId))
                            {
                                dev.NormalizedName = uniqueId;
                            }
                        }

                        authorsPlace[normalizedEmail] = uniqueId;
                    }
                    else if (authorsPlace.ContainsKey(normalizedEmail))
                    {
                        authorsPlace[normalizedName] = authorsPlace[normalizedEmail];
                    }
                    else
                    {
                        authorsPlace[normalizedName]  = normalizedName;
                        authorsPlace[normalizedEmail] = normalizedName;
                    }

                    normalizedDevelopers.Add(new AliasedDeveloperName()
                    {
                        Email          = author.AuthorEmail,
                        Name           = author.AuthorName,
                        NormalizedName = authorsPlace[normalizedName]
                    });
                }

                var damerauDistanceAlgorithm = new Damerau();
                normalizedDevelopers = normalizedDevelopers.OrderBy(q => q.NormalizedName)
                                       .ToList();

                for (var i = 0; i < normalizedDevelopers.Count - 1; i++)
                {
                    var firstDev  = normalizedDevelopers[i];
                    var secondDev = normalizedDevelopers[i + 1];
                    var distance  = damerauDistanceAlgorithm.Distance(firstDev.NormalizedName, secondDev.NormalizedName);

                    if (distance == 1)
                    {
                        secondDev.NormalizedName = firstDev.NormalizedName;
                    }
                }

                _logger.LogInformation("{datetime}: after normalization, there are {count} unique authors have been found.",
                                       DateTime.Now, normalizedDevelopers.Select(q => q.NormalizedName).Distinct().Count());

                dbContext.AddRange(normalizedDevelopers);
                await dbContext.SaveChangesAsync().ConfigureAwait(false);

                _logger.LogInformation("{datetime}: aliased results have been saves successfully.", DateTime.Now);
            }
        }