예제 #1
0
 T getBranchChanged <T>(TreeChanges changes, BranchInfo branchInfo) where T : BranchModification, new() =>
 new T
 {
     Branch = branchInfo,
     Added  = changes.Added.Select(a => new ItemAdded
     {
         Key      = a.Path,
         GetValue = () => getBlobValue(a.Oid)
     }).ToList(),
     Modified = changes.Modified.Select(m => new ItemModified
     {
         Key         = m.Path,
         GetValue    = () => getBlobValue(m.Oid),
         GetOldValue = () => getBlobValue(m.OldOid)
     }).ToList(),
     Renamed = changes.Renamed.Select(r => new ItemRenamed
     {
         Key         = r.Path,
         GetValue    = () => getBlobValue(r.Oid),
         GetOldValue = () => getBlobValue(r.OldOid),
         OldKey      = r.OldPath
     }).ToList(),
     Deleted = changes.Deleted.Select(d => new ItemDeleted {
         Key = d.Path, GetValue = () => getBlobValue(d.OldOid)
     }).ToList()
 };
예제 #2
0
 async Task raiseBranchDeleted(BranchInfo branchInfo)
 {
     try
     {
         _logger.Info($"Detected deletion of branch {branchInfo.Name}");
         await _branchRemoved(new BranchRemoved { Branch = branchInfo });
     }
     catch (Exception ex)
     {
         _logger.Error(ex, $"Error while checking deleted branch {branchInfo.Name}");
         throw;
     }
 }
예제 #3
0
        async Task raiseBranchAdded(BranchInfo branch)
        {
            try
            {
                _logger.Info($"Detected a new branch {branch.Name}");
                var currentCommit  = _repo.Lookup <Commit>(branch.Commit);
                var previousCommit = _repo.Branches["master"].Tip;

                var result = _repo.Diff.Compare <TreeChanges>(previousCommit.Tree, currentCommit.Tree);
                _logger.Info($"Finished diff, found {result.Added.Count()} added items, {result.Deleted.Count()} deleted items, {result.Renamed.Count()} renamed items and {result.Modified.Count()} modified items");

                var eventInfo = getBranchChanged <BranchAdded>(result, branch);
                eventInfo.BaseBranch = "master";
                await _branchAdded(eventInfo);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error while checking new branch {branch}");
                throw;
            }
        }
예제 #4
0
        async Task raiseBranchChanged(BranchDictionary previousBranches, BranchInfo branch)
        {
            try
            {
                var previousCommit = _repo.Lookup <Commit>(previousBranches[branch.Name].Commit);
                var currentCommit  = _repo.Lookup <Commit>(branch.Commit);
                _logger.Trace($"Found differences on branch {branch.Name}, starting diff between {previousCommit.Sha} and {currentCommit.Sha}");
                var result = _repo.Diff.Compare <TreeChanges>(previousCommit.Tree, currentCommit.Tree);
                _logger.Info($"Finished diff on branch {branch.Name}, found {result.Added.Count()} added items, {result.Deleted.Count()} deleted items, {result.Renamed.Count()} renamed items and {result.Modified.Count()} modified items");

                var eventInfo = getBranchChanged <BranchChanged>(result, branch);
                eventInfo.PreviousCommit = previousCommit.Sha;

                await _branchChanged(eventInfo);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Error while checking for changes on branch {branch}. Previous commit is {previousBranches[branch.Name].Commit}, Current commit is {branch.Commit}");
                throw;
            }
        }