public async Task CreateAsync(RepositoryAnalysis repositoryAnalysis) { var parsedRepoUrl = ParseRepositoryUrl(); // maybe change the name of this var to reflect how it's different than the repositoryAnalysis.repsoitoryId? var repositoryId = $"{parsedRepoUrl.Host}|{parsedRepoUrl.Owner}|{parsedRepoUrl.Name}"; var repository = await repositoryManager.ReadAsync(repositoryId, repositoryAnalysis.AsOf).ConfigureAwait(false); DateTime?repositoryLastUpdatedOn = null; // If a last updated time for the repo was provided, use that to hopefully save an API call if (repositoryAnalysis.RepositoryLastUpdatedOn.HasValue) { repositoryLastUpdatedOn = repositoryAnalysis.RepositoryLastUpdatedOn.Value; } else { var repositorySummary = await repositorySourceManager.ReadRepositorySummaryAsync(parsedRepoUrl.Owner, parsedRepoUrl.Name).ConfigureAwait(false); repositoryLastUpdatedOn = repositorySummary.UpdatedAt; } if (repositoryAnalysis.ForceCompleteRefresh || repository == null || repositoryLastUpdatedOn > repository.CurrentState.RepositoryLastUpdatedOn) { // Do repository summary call to get the commit Id of the latest commit and the date that commit was pushed for the snapshot // populate the snapshot date with the corresponding manager calls (E.G. ScrapeDependenciesAsync) // Do full repository read to get all the current state stuff (including calls to get derived data like devops integrations) var sourceRepository = await repositorySourceManager.ReadRepositoryAsync(parsedRepoUrl.Owner, parsedRepoUrl.Name).ConfigureAwait(false); var repositoryCurrentState = new RepositoryCurrentState(); repositoryCurrentState.Id = repositoryId; repositoryCurrentState.Name = sourceRepository.Name; repositoryCurrentState.Owner = parsedRepoUrl.Owner; repositoryCurrentState.DefaultBranch = sourceRepository.DefaultBranchName; repositoryCurrentState.HasIssues = sourceRepository.IssueCount > 0; repositoryCurrentState.HasProjects = sourceRepository.ProjectCount > 0; repositoryCurrentState.HasPullRequests = sourceRepository.PullRequestCount > 0; repositoryCurrentState.RepositoryCreatedOn = sourceRepository.CreatedAt; repositoryCurrentState.RepositoryLastUpdatedOn = sourceRepository.PushedAt; repositoryCurrentState.Teams = sourceRepository.Teams; repositoryCurrentState.Topics = sourceRepository.TopicNames?.Select(name => new RepositoryTopic { Name = name }).ToList(); repositoryCurrentState.DevOpsIntegrations = await ScrapeDevOpsIntegrations(repositoryCurrentState.Name).ConfigureAwait(false); // Need to pick a branch for the snapshot stuff string branchName = null; if (sourceRepository.BranchNames.Contains("master")) { branchName = "master"; } else if (sourceRepository.BranchNames.Contains("development")) { branchName = "development"; } else if (!string.IsNullOrWhiteSpace(sourceRepository.DefaultBranchName)) { branchName = sourceRepository.DefaultBranchName; } RepositorySnapshot repositorySnapshot = null; repositorySnapshot = new RepositorySnapshot(); // Have to set the windows in the manager repositorySnapshot.RepositoryCurrentStateRepositoryId = repositoryCurrentState.Id; repositorySnapshot.TakenOn = DateTime.Now; repositorySnapshot.BranchUsed = branchName; if (branchName != null) { repositorySnapshot.Dependencies = await ScrapeDependenciesAsync(parsedRepoUrl.Owner, parsedRepoUrl.Name, branchName, repositoryAnalysis.AsOf).ConfigureAwait(false); repositorySnapshot.Files = await repositorySourceManager.ReadFilesAsync(parsedRepoUrl.Owner, parsedRepoUrl.Name, branchName, repositoryAnalysis.AsOf).ConfigureAwait(false); } else { repositorySnapshot.Dependencies = new List <RepositoryDependency>(); repositorySnapshot.Files = new List <RepositoryFile>(); } repositorySnapshot.TypesAndImplementations = await ScrapeRepositoryTypeAndImplementation( parsedRepoUrl.Name, repositorySnapshot.Files, repositorySnapshot.Dependencies, repositoryCurrentState.Topics?.Select(topic => topic.Name), new BacklogInfo { HasIssues = repositoryCurrentState.HasIssues ?? false }, repositoryAnalysis.AsOf).ConfigureAwait(false); var updatedRepository = new Repository { CurrentState = repositoryCurrentState, Snapshot = repositorySnapshot }; await repositoryManager.UpsertAsync(updatedRepository, repositoryAnalysis.AsOf).ConfigureAwait(false); } (string Owner, string Name, string Host) ParseRepositoryUrl() { var repositoryUri = new Uri(repositoryAnalysis.RepositoryId); var owner = repositoryUri.Segments[1].TrimEnd('/'); var name = repositoryUri.Segments[2].TrimEnd('/'); var host = repositoryUri.Host; return(owner, name, host); } }