/// <summary> /// Diff each node in the graph against the latest build in /// the graph. /// </summary> /// <param name="remoteFactory"></param> /// <param name="logger"></param> /// <param name="nodeCache"></param> /// <param name="visitedRepoUriNodes"></param> /// <returns></returns> private static async Task DoLatestInGraphNodeDiffAsync( IRemoteFactory remoteFactory, ILogger logger, Dictionary <string, DependencyGraphNode> nodeCache, Dictionary <string, DependencyGraphNode> visitedRepoUriNodes) { logger.LogInformation("Running latest in graph node diff."); // Find the build of each repo in the graph, then // get the diff info from the latest foreach (string repo in visitedRepoUriNodes.Keys) { // Get all nodes with this value List <DependencyGraphNode> nodes = nodeCache.Values.Where(n => n.Repository == repo).ToList(); // If only one, determine latest if (nodes.Count > 1) { // Find latest DependencyGraphNode newestNode = null; Build newestBuild = null; foreach (DependencyGraphNode node in nodes) { if (newestNode == null) { newestNode = node; if (newestNode.ContributingBuilds.Any()) { newestBuild = newestNode.ContributingBuilds.OrderByDescending(b => b.DateProduced).First(); } } else if (node.ContributingBuilds.Any(b => b.DateProduced > newestBuild?.DateProduced)) { newestNode = node; newestBuild = newestNode.ContributingBuilds.OrderByDescending(b => b.DateProduced).First(); } } // Compare all other nodes to the latest foreach (DependencyGraphNode node in nodes) { IRemote repoRemote = await remoteFactory.GetRemoteAsync(node.Repository, logger); // If node == newestNode, returns no diff. node.DiffFrom = await repoRemote.GitDiffAsync(node.Repository, newestNode.Commit, node.Commit); } } else { DependencyGraphNode singleNode = nodes.Single(); singleNode.DiffFrom = GitDiff.NoDiff(singleNode.Commit); } } }
/// <summary> /// Diff two commits in a repository and return information about them. /// </summary> /// <param name="repoUri">Repository uri</param> /// <param name="baseVersion">Base version</param> /// <param name="targetVersion">Target version</param> /// <returns>Diff information</returns> public async Task <GitDiff> GitDiffAsync(string repoUri, string baseVersion, string targetVersion) { CheckForValidGitClient(); // If base and target are the same, return no diff if (baseVersion.Equals(targetVersion, StringComparison.OrdinalIgnoreCase)) { return(GitDiff.NoDiff(baseVersion)); } return(await _gitClient.GitDiffAsync(repoUri, baseVersion, targetVersion)); }