public void Should_Set_Repository_CommitId_When_All_Projects_Built() { var buildConfig = new DotNetProjectBuildConfig { GitRepository = new GitRepository("volo", "dev", "") { DependingRepositories = new List <GitRepository>() { new GitRepository("abp", "dev", "") } } }; var changedProjects = new List <DotNetProjectInfo>() { new DotNetProjectInfo("volo", "project1.csproj", true) }; var builtProjects = new List <string>() { "project1.csproj" }; var lastCommitId = "1"; _gitRepositoryHelper.GetLastCommitId(buildConfig.GitRepository).Returns(lastCommitId); _gitRepositoryHelper.GetFriendlyName(buildConfig.GitRepository).Returns("volo"); var status = _buildStatusGenerator.Generate(buildConfig, changedProjects, builtProjects); status.CommitId.ShouldBe(lastCommitId); }
public GitRepositoryBuildStatus Generate( DotNetProjectBuildConfig buildConfig, List <DotNetProjectInfo> changedProjects, List <string> buildSucceededProjects) { var lastCommitId = _gitRepositoryHelper.GetLastCommitId(buildConfig.GitRepository); var repoFriendlyName = _gitRepositoryHelper.GetFriendlyName(buildConfig.GitRepository); var status = new GitRepositoryBuildStatus( buildConfig.GitRepository.Name, repoFriendlyName ); if (ShouldUpdateRepositoryCommitId(buildConfig, changedProjects, buildSucceededProjects)) { status.CommitId = lastCommitId; } status.SucceedProjects = changedProjects.Where(p => p.RepositoryName == buildConfig.GitRepository.Name && buildSucceededProjects.Contains(p.CsProjPath) ) .Select(e => new DotNetProjectBuildStatus { CsProjPath = e.CsProjPath, CommitId = lastCommitId }).ToList(); foreach (var dependingRepository in buildConfig.GitRepository.DependingRepositories) { GenerateBuildStatusInternal( buildConfig, dependingRepository, changedProjects, buildSucceededProjects, status ); } return(status); }
private void MarkChangedProjectsForBuild( GitRepository repository, GitRepositoryBuildStatus status, List <DotNetProjectInfo> allProjectList) { using (var repo = new Repository(string.Concat(repository.RootPath, @"\.git"))) { var firstCommit = status.CommitId.IsNullOrEmpty() ? null : repo.Lookup <Commit>(status.CommitId); var repoDifferences = repo.Diff.Compare <Patch>(firstCommit?.Tree, repo.Head.Tip.Tree); var fileExtensionPredicate = PredicateBuilder.New <PatchEntryChanges>(true); foreach (var changeDetectionFileExtension in _changeDetectionFileExtensions) { fileExtensionPredicate = fileExtensionPredicate.Or( e => e.Path.EndsWith(changeDetectionFileExtension) ); } var files = repoDifferences .Where(fileExtensionPredicate) .Where(e => e.Status != ChangeKind.Deleted) .Select(e => e) .ToList(); var affectedCsProjFiles = FindAffectedCsProjFiles(repository.RootPath, files); var lastCommitId = _gitRepositoryHelper.GetLastCommitId(repository); foreach (var file in affectedCsProjFiles) { var csProjPath = Path.Combine(repository.RootPath, file); if (status.SucceedProjects.Any(p => p.CsProjPath == csProjPath && p.CommitId == lastCommitId)) { continue; } // Filter ignored directories var isIgnored = repository.IgnoredDirectories.Any(ignoredDirectory => csProjPath.StartsWith(Path.Combine(repository.RootPath, ignoredDirectory))); if (isIgnored) { continue; } allProjectList.MarkForBuild(repository.Name, csProjPath); AddDependingProjectsToList(repository.Name, csProjPath, allProjectList); } } }