Ejemplo n.º 1
0
        public async Task Execute(string token, string agenName, string owner, string repo)
        {
            using (var dbContext = new GitRepositoryDbContext())
            {
                var commitAuthors = await dbContext.Commits
                                    .FromSql(@"select c1.* from Commits as c1
                INNER JOIN (select NormalizedAuthorName,AuthorName,max(AuthorDateTime) as AuthorDateTime from Commits
                group by NormalizedAuthorName,AuthorName) as c2 on c1.AuthorDateTime=c2.AuthorDateTime
                and c1.NormalizedAuthorName=c2.NormalizedAuthorName
                and c1.AuthorName=c2.AuthorName")
                                    .ToArrayAsync().ConfigureAwait(false);

                _logger.LogInformation("{datetime}: fetching corresponding GitHub user of {count} git authors.", DateTime.Now, commitAuthors.Length);

                var github = new GithubDataFetcher(token, agenName, _logger);

                foreach (var commitAuthor in commitAuthors)
                {
                    var commit = await github.GetCommit(owner, repo, commitAuthor.Sha).ConfigureAwait(false);

                    // Github does not return the author for some of the old Commits
                    dbContext.Add(new GitHubGitUser
                    {
                        GitUsername           = commitAuthor.AuthorName,
                        GitHubUsername        = commit.Author?.Login,
                        GitNormalizedUsername = commitAuthor.NormalizedAuthorName
                    });
                }

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

                _logger.LogInformation("{datetime}: corresponding GitHub users have been saved successfully.", DateTime.Now);
            }
        }
Ejemplo n.º 2
0
        public async Task Execute(string periodType, int periodLength)
        {
            var commitPeriods = new List <CommitPeriod>();

            using (var dbContext = new GitRepositoryDbContext())
            {
                var commits = dbContext.Commits.OrderBy(m => m.AuthorDateTime).ToArray();

                _logger.LogInformation("{datetime}: trying to periodize all the {count} commits. Period Type: {type}, Period Length: {length}",
                                       DateTime.Now, commits.Count(), periodType, periodLength);

                var beginDatetime = commits.Min(m => m.AuthorDateTime);
                beginDatetime = new DateTime(beginDatetime.Year, beginDatetime.Month, 1);
                var endDatetime = commits.Max(m => m.AuthorDateTime);

                var periods            = GetPeriods(periodType, periodLength, beginDatetime, endDatetime);
                var currentPeriodIndex = 0;

                periods[currentPeriodIndex].FirstCommitSha = commits[0].Sha;
                for (int i = 0; i < commits.Length; i++)
                {
                    if (periods[currentPeriodIndex].ToDateTime < commits[i].AuthorDateTime)
                    {
                        var candidateCommits = commits.Where(q => !q.Ignore && q.AuthorDateTime <= commits[i - 1].AuthorDateTime);

                        if (candidateCommits.Count() > 0) // the problem happens (rarely) in the first period.
                        {
                            periods[currentPeriodIndex].LastCommitSha = candidateCommits.Last().Sha;
                        }
                        else
                        {
                            periods[currentPeriodIndex].LastCommitSha = periods[currentPeriodIndex].FirstCommitSha;
                        }

                        currentPeriodIndex++;

                        periods[currentPeriodIndex].FirstCommitSha = commits
                                                                     .First(q => !q.Ignore && q.AuthorDateTime >= commits[i].AuthorDateTime)
                                                                     .Sha;
                    }

                    commits[i].PeriodId = periods[currentPeriodIndex].Id;
                }

                periods[currentPeriodIndex].LastCommitSha = commits[commits.Length - 1].Sha;

                _logger.LogInformation("{datetime}: trying to save {count} periods.", DateTime.Now, periods.Count());
                dbContext.Periods.AddRange(periods);
                await dbContext.SaveChangesAsync().ConfigureAwait(false);

                _logger.LogInformation("{datetime}: periods has been saved successfully.", DateTime.Now);
            }
        }
Ejemplo n.º 3
0
        public async Task Execute(double coreDeveloperThreshold, string coreDeveloperCalculationType)
        {
            using (var dbContext = new GitRepositoryDbContext(false))
            {
                _logger.LogInformation("{datetime}: extracting developer statistics for each period.", DateTime.Now);

                var reviewersPeriodsDic       = dbContext.GetPeriodReviewerCounts();
                var reviewersParticipationDic = dbContext.GetReviewersParticipationDates();
                await ExtractDevelopersInformation(reviewersPeriodsDic, reviewersParticipationDic, dbContext).ConfigureAwait(false);
                await ExctractContributionsPerPeriod(coreDeveloperThreshold, coreDeveloperCalculationType, reviewersPeriodsDic, dbContext).ConfigureAwait(false);

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

                _logger.LogInformation("{datetime}: developer information has been extracted and saved.", DateTime.Now);
            }
        }
Ejemplo n.º 4
0
        public async Task Execute(string token, string agenName, string owner, string repo, string branch)
        {
            using (var dbContext = new GitRepositoryDbContext(true))
            {
                var loadedPullRequests = await dbContext.PullRequests.FromSql(@"select * from PullRequests WHERE Merged=1 and MergeCommitSha not in (select Sha from Commits)")
                                         .ToArrayAsync().ConfigureAwait(false);

                _logger.LogInformation("{datetime}: there are {count} pull requests with no corresponding merged commit", DateTime.Now, loadedPullRequests.Length);

                var githubExtractor = new GithubDataFetcher(token, agenName, _logger);
                await githubExtractor.MergeEvents(owner, repo, loadedPullRequests).ConfigureAwait(false);

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

                _logger.LogInformation("{datetime}: corresponding merged commits has been resolved and saved.", DateTime.Now);
            }
        }
Ejemplo n.º 5
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.º 6
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);
            }
        }