private async Task ImportCommitAsync(ProdConTrackerDbContext db, Repository repo, Commit commit, HashSet <string> loadedBuilds) { // Search the tree for the files we care about var entry = commit.Tree[RepositoryPath]; // Dive through the tree's children looking for build.xmls foreach (var child in entry.Target.Peel <Tree>()) { await ProcessTreeAsync(db, child, prefix : string.Empty, commit, loadedBuilds); } }
private async Task ImportCommitsAsync(ProdConTrackerDbContext db, Repository repo) { // Local cache of builds that have been loaded in this pass. var loadedBuilds = new HashSet <string>(); foreach (var commit in repo.Commits) { // Import the current commit _logger.LogInformation("Scanning for builds in commit: {Commit}", commit.Id.Sha); await ImportCommitAsync(db, repo, commit, loadedBuilds); } }
private async Task ImportBuildManifestAsync(ProdConTrackerDbContext db, LibGit2Sharp.Blob blob, string branch, Commit commit, HashSet <string> loadedBuilds) { var orchBuild = BuildXmlLoader.Load(blob.GetContentText(), branch); // Check if the build already exists if (!loadedBuilds.Contains(orchBuild.OrchestratedBuildId) && !await db.OrchestratedBuilds.AnyAsync(b => b.OrchestratedBuildId == orchBuild.OrchestratedBuildId)) { _logger.LogInformation("Importing build {BuildId} ...", orchBuild.OrchestratedBuildId); db.OrchestratedBuilds.Add(orchBuild); foreach (var build in orchBuild.Builds) { db.Builds.Add(build); } _logger.LogInformation("Saving to database..."); await db.SaveChangesAsync(); } }
private async Task ProcessTreeAsync(ProdConTrackerDbContext db, TreeEntry entry, string prefix, Commit commit, HashSet <string> loadedBuilds) { var fullName = string.IsNullOrEmpty(prefix) ? entry.Name : $"{prefix}/{entry.Name}"; if (entry.TargetType == TreeEntryTargetType.Tree) { foreach (var child in entry.Target.Peel <Tree>()) { await ProcessTreeAsync(db, child, prefix : fullName, commit, loadedBuilds); } } else if (entry.TargetType == TreeEntryTargetType.Blob && entry.Name.Equals("build.xml")) { await ImportBuildManifestAsync(db, entry.Target.Peel <LibGit2Sharp.Blob>(), branch : prefix, commit, loadedBuilds); } else { _logger.LogDebug("Skipping {Type} entry {Name}", entry.TargetType, fullName); } }
public async Task <int> OnExecuteAsync() { // Initialize defaults RepositoryUrl = string.IsNullOrEmpty(RepositoryUrl) ? DefaultRepositoryUrl : RepositoryUrl; RepositoryPath = string.IsNullOrEmpty(RepositoryPath) ? DefaultRepositoryPath : RepositoryPath; if (string.IsNullOrEmpty(CosmosUrl)) { _logger.LogError("Missing required option: '--cosmos-url'."); return(1); } if (string.IsNullOrEmpty(CosmosKey)) { _logger.LogError("Missing required option: '--cosmos-key'."); return(1); } if (string.IsNullOrEmpty(CosmosDb)) { _logger.LogError("Missing required option: '--cosmos-db'."); return(1); } if (string.IsNullOrEmpty(WorkDirectory)) { WorkDirectory = Path.Combine(Path.GetTempPath(), $"TrackerGen_Work_{Guid.NewGuid().ToString("N")}"); } else { KeepWorkDirectory = true; } try { // First, clone the repos _logger.LogInformation("Cloning {RepositoryUrl} to {WorkDirectory}...", RepositoryUrl, WorkDirectory); var repoPath = Repository.Clone(RepositoryUrl, WorkDirectory); using (var repo = new Repository(repoPath)) { // Create EF context var options = new DbContextOptionsBuilder() .UseSqlServer() .Options using (var context = new ProdConTrackerDbContext()) { await context.Database.EnsureCreatedAsync(); // Open the catalog await ImportCommitsAsync(context, repo); } } } finally { if (!KeepWorkDirectory) { _logger.LogDebug("Cleaning {WorkDirectory}...", WorkDirectory); if (Directory.Exists(WorkDirectory)) { DeleteDirectory(WorkDirectory); } } } return(0); }