public async Task Traverse(Func <Data.Commit, Task> analyzeFunc) { var orderedCommits = ExtractCommitsFromBranch(); for (int i = 0; i < orderedCommits.Length; i++) { var commit = new Data.Commit() { Sha = orderedCommits[i].Sha, AuthorEmail = orderedCommits[i].Author.Email, AuthorName = orderedCommits[i].Author.Name, DateTime = orderedCommits[i].Author.When, Changes = LoadChangesOfCommit(orderedCommits[i]).ToArray().Select(q => new Data.CommitChange() { Path = q.Path, Status = GetFileHistoryType(q.Status), OldExists = q.OldExists, OldPath = q.OldPath }).ToArray(), SubscriptionId = _subscriptionId }; _commits.Add(commit); await analyzeFunc(commit); } }
private void LoadChangesOfCommit(Data.Commit commit, Dictionary <string, string> fileOidHolder, Dictionary <string, List <CommittedChange> > pathFilesDic) { var committedChanges = new List <CommittedChange>(); var gitCommit = commit.GitCommit; var compareOptions = new CompareOptions { Algorithm = DiffAlgorithm.Minimal, Similarity = new SimilarityOptions { RenameDetectionMode = RenameDetectionMode.Renames, } }; if (gitCommit.Parents.Count() <= 1) { committedChanges.AddRange(GetDiffOfTrees(_gitRepo, gitCommit.Parents.SingleOrDefault()?.Tree, gitCommit.Tree, compareOptions, fileOidHolder)); } else { committedChanges.AddRange(GetDiffOfMergedTrees(_gitRepo, gitCommit.Parents, gitCommit.Tree, compareOptions, fileOidHolder)); } ReorderChanges(commit, fileOidHolder, pathFilesDic, committedChanges); commit.CommittedChanges = committedChanges; }
private Data.Commit GetOneCommit(string repo, string sha) { string json = _service.GetOneCommit(repo, sha); var repoCommit = JsonConvert.DeserializeObject <CodeChurnLoader.Data.Github.Commit>(json); Data.Commit commit = Mapper.Map <Data.Commit>(repoCommit); return(commit); }
public void AutoMapper_Committer_NoUser() { var bitbucketCommit = new Commit { Author = new Author { Raw = "Stan <*****@*****.**>" } }; Data.Commit commit = Mapper.Map <Data.Commit>(bitbucketCommit); Assert.AreEqual("Stan", commit.Committer); }
public void AutoMapper_Committer_Regular() { var bitbucketCommit = new Commit { Author = new Author { Raw = "Stan <*****@*****.**>", User = new User { UserName = "******" } } }; Data.Commit commit = Mapper.Map <Data.Commit>(bitbucketCommit); Assert.AreEqual("StanB", commit.Committer); }
public void LoadBlobsAndTheirBlamesOfCommit( Data.Commit commit, string[] validExtensions, string[] excludedPaths, Dictionary <string, string> canonicalPathDic, bool extractBlames, string branchName = "master") { var commitsDic = ExtractCommitsFromBranch(branchName).ToDictionary(q => q.Sha); var blobsPath = GetBlobsPathFromCommitTree(commit.GitCommit.Tree, validExtensions, excludedPaths); var committedBlobs = new ConcurrentBag <CommittedBlob>(); Parallel.ForEach( blobsPath, new ParallelOptions() { MaxDegreeOfParallelism = 5 }, GetPowerShellInstance, (blobPath, _, powerShellInstance) => { var blobBlames = GetBlobBlamesOfCommit(powerShellInstance, commit.Sha, blobPath, canonicalPathDic, commitsDic, extractBlames); committedBlobs.Add(new CommittedBlob() { NumberOfLines = blobBlames.Sum(m => m.AuditedLines), Path = blobPath, CommitSha = commit.Sha, CanonicalPath = canonicalPathDic.GetValueOrDefault(blobPath), CommitBlobBlames = blobBlames }); if (committedBlobs.Count() % 500 == 0) { _logger.LogInformation("{datetime} : Blames extraction from {currentCount} files out of {total} completed.", DateTime.Now, committedBlobs.Count, blobsPath.Count); } return(powerShellInstance); }, (powerShellInstance) => powerShellInstance?.Dispose()); commit.Blobs = committedBlobs.ToList(); }
private void ReorderChanges(Data.Commit commit, Dictionary <string, string> fileOidHolder, Dictionary <string, List <CommittedChange> > pathFilesDic, List <CommittedChange> committedChanges) { foreach (var committedFile in committedChanges) { committedFile.CommitSha = commit.Sha; var canonicalPath = committedFile.CanonicalPath; // adding new changes to the dictionary if (!pathFilesDic.ContainsKey(canonicalPath)) { pathFilesDic[canonicalPath] = new List <CommittedChange>(); } pathFilesDic[canonicalPath].Add(committedFile); } // reordering changes to their new canonical address. // so, files with same path/oldpath will have a same canonical address foreach (var committedChange in committedChanges) { if (committedChange.Path == committedChange.OldPath) { continue; } var pathCanonical = fileOidHolder[committedChange.Path]; var oldPathCanonical = fileOidHolder[committedChange.OldPath]; if (pathCanonical != oldPathCanonical) { pathFilesDic[pathCanonical] = pathFilesDic[pathCanonical].Concat(pathFilesDic[oldPathCanonical]).ToList(); pathFilesDic.Remove(oldPathCanonical); fileOidHolder[oldPathCanonical] = pathCanonical; foreach (var item in pathFilesDic[pathCanonical]) { fileOidHolder[item.Path] = pathCanonical; fileOidHolder[item.OldPath] = pathCanonical; } } } }