public override void Log(ILogMessage message) { switch (message.Level) { case LogLevel.Verbose: _logger.Verbose(message.Message); break; case LogLevel.Debug: _logger.Verbose(message.Message); break; case LogLevel.Information: _logger.Verbose(message.Message); break; case LogLevel.Minimal: _logger.Info(message.Message); break; case LogLevel.Warning: _logger.Info(message.Message); break; case LogLevel.Error: _logger.Error(message.Message); break; default: throw new ArgumentOutOfRangeException(); } }
public async Task Invoke(FileInfo file, NuGetSources sources) { _logger.Info($"Nuget restore on {file.DirectoryName} {file.Name}"); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _logger.Info("Cannot run NuGet.exe file restore as OS Platform is not Windows"); return; } var nuget = NuGetPath.FindExecutable(); if (string.IsNullOrWhiteSpace(nuget)) { _logger.Info("Cannot find NuGet exe for solution restore"); return; } var sourcesCommandLine = sources.CommandLine("-Source"); var arguments = $"restore {file.Name} {sourcesCommandLine}"; _logger.Verbose($"{nuget} {arguments}"); var processOutput = await _externalProcess.Run(file.DirectoryName, nuget, arguments, ensureSuccess : false); if (processOutput.Success) { _logger.Verbose($"Nuget restore on {file.Name} complete"); } else { _logger.Verbose($"Nuget restore failed on {file.DirectoryName} {file.Name}:\n{processOutput.Output}\n{processOutput.ErrorOutput}"); } }
public IEnumerable <PackageUpdateSet> Sort(IReadOnlyCollection <PackageUpdateSet> input) { if (input.Count < 2) { return(input); } _data = input .Select(p => MakeNode(p, input)) .ToList(); if (!_data.Any(i => i.Dependencies.Any())) { _logger.Verbose("No dependencies between packages being updated, no need to sort on this"); return(input); } foreach (var item in _data) { if (item.Mark == Mark.None) { Visit(item); } } if (_cycleFound) { return(input); } ReportSort(input.ToList(), _sortedList); return(_sortedList); }
public async Task <string> GetCurrentUser() { var user = await _client.User.Current(); var userLogin = user?.Login; _logger.Verbose($"Read github user '{userLogin}'"); return(userLogin); }
public NuGetSources ReadNugetSources(IFolder workingFolder) { var settings = Settings.LoadDefaultSettings(workingFolder.FullPath); foreach (var file in settings.Priority) { _logger.Verbose($"Reading file {Path.Combine(file.Root, file.FileName)} for package sources"); } var enabledSources = SettingsUtility.GetEnabledSources(settings).ToList(); return(ReadFromFile(enabledSources)); }
public void TryDelete() { _logger.Verbose($"Attempting delete of folder {_root.FullName}"); try { DeleteDirectoryInternal(_root.FullName); _logger.Verbose($"Deleted folder {_root.FullName}"); } catch (Exception ex) { _logger.Verbose($"Folder delete failed: {ex.GetType().Name} {ex.Message}"); } }
public void Report(string name, List <PackageUpdateSet> updates) { using (var writer = MakeOutputStream(name)) { WriteHeading(writer); _logger.Verbose($"writing {updates.Count} lines to report"); foreach (var update in updates) { WriteLine(writer, update); } writer.Close(); } }
public async Task <int> Run(SettingsContainer settings) { var github = _githubCreator.Create(settings); var repositoryDiscovery = _repositoryDiscoveryCreator.Create(settings); var repositoryEngine = _repositoryEngineCreator.Create(settings); _logger.Verbose($"{Now()}: Started"); _folderFactory.DeleteExistingTempDirs(); var githubUser = await github.GetCurrentUser(); var gitCreds = new UsernamePasswordCredentials { Username = githubUser.Login, Password = settings.GithubAuthSettings.Token }; var userIdentity = GetUserIdentity(githubUser); var repositories = await repositoryDiscovery.GetRepositories(); var reposUpdated = 0; foreach (var repository in repositories) { if (reposUpdated >= settings.UserSettings.MaxRepositoriesChanged) { _logger.Verbose($"Reached max of {reposUpdated} repositories changed"); break; } var updatesInThisRepo = await repositoryEngine.Run(repository, gitCreds, userIdentity); if (updatesInThisRepo > 0) { reposUpdated++; } } if (reposUpdated > 1) { _logger.Verbose($"{reposUpdated} repositories were updated"); } _logger.Verbose($"Done at {Now()}"); return(reposUpdated); }
public void Report(PackageLookupResult lookupResult) { var highestVersion = lookupResult.Major?.Identity?.Version; if (highestVersion == null) { return; } var allowing = lookupResult.AllowedChange == VersionChange.Major ? string.Empty : $" Allowing {lookupResult.AllowedChange} version updates."; var highestMatchVersion = lookupResult.Selected()?.Identity?.Version; var packageId = lookupResult.Major.Identity.Id; if (highestMatchVersion == null) { _logger.Info($"Package {packageId} version {highestVersion} is available but is not allowed.{allowing}"); return; } if (highestVersion > highestMatchVersion) { _logger.Info($"Selected update of package {packageId} to version {highestMatchVersion}, but version {highestVersion} is also available.{allowing}"); } else { _logger.Verbose($"Selected update of package {packageId} to highest version, {highestMatchVersion}.{allowing}"); } }
public void Report(string name, IReadOnlyCollection <PackageUpdateSet> updates) { using (var writer = _reportStreamSource.GetStream(name)) { _logger.Verbose($"writing {updates.Count} lines to report"); WriteHeading(writer); foreach (var update in updates) { WriteLine(writer, update); } writer.Close(); _logger.Verbose("Report written"); } }
public async Task Invoke(PackageInProject currentPackage, NuGetVersion newVersion, PackageSource packageSource, NuGetSources allSources) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _logger.Info("Cannot run NuGet.exe package update as OS Platform is not Windows"); return; } var dirName = currentPackage.Path.Info.DirectoryName; var nuget = NuGetPath.FindExecutable(); if (string.IsNullOrWhiteSpace(nuget)) { _logger.Info("Cannot find NuGet exe for package update"); return; } var sources = allSources.CommandLine("-Source"); var arguments = $"update packages.config -Id {currentPackage.Id} -Version {newVersion} {sources}"; _logger.Verbose(arguments); await _externalProcess.Run(dirName, nuget, arguments, true); }
public async Task <bool> ContainsDotNetProjects(RepositorySettings repository) { var request = new SearchCodeRequest("\"packages.config\" OR \".csproj\" OR \".fsproj\" OR \".vbproj\"") { Repos = new RepositoryCollection { { repository.RepositoryOwner, repository.RepositoryName } }, In = new [] { CodeInQualifier.Path }, PerPage = 1 }; try { var result = await _githubClient.Search(request); if (result.TotalCount <= 0) { _logger.Verbose( $"Repository {repository.RepositoryOwner}/{repository.RepositoryName} contains no .NET code on the default branch, skipping."); return(false); } } catch (Exception ex) { _logger.Error("GitHub Repository search failed.", ex); } return(true); }
public async Task UpdatePackageInProjects( IGitDriver git, PackageUpdateSet updateSet, RepositoryData repository) { try { _logger.Terse(UpdatesLogger.OldVersionsToBeUpdated(updateSet)); git.Checkout(repository.DefaultBranch); // branch var branchName = BranchNamer.MakeName(updateSet); _logger.Verbose($"Using branch name: '{branchName}'"); git.CheckoutNewBranch(branchName); await UpdateAllCurrentUsages(updateSet); var commitMessage = CommitWording.MakeCommitMessage(updateSet); git.Commit(commitMessage); git.Push("nukeeper_push", branchName); var prTitle = CommitWording.MakePullRequestTitle(updateSet); await MakeGitHubPullRequest(updateSet, repository, prTitle, branchName); git.Checkout(repository.DefaultBranch); } catch (Exception ex) { _logger.Error("Update failed", ex); } }
private async Task UpdateNuspec(FileStream fileContents, NuGetVersion newVersion, PackageInProject currentPackage) { var xml = XDocument.Load(fileContents); var packagesNode = xml.Element("package")?.Element("metadata")?.Element("dependencies"); if (packagesNode == null) { return; } var packageNodeList = packagesNode.Elements() .Where(x => x.Name == "dependency" && x.Attributes("id") .Any(a => a.Value == currentPackage.Id)); foreach (var dependencyToUpdate in packageNodeList) { _logger.Verbose($"Updating nuspec depenencies: {currentPackage.Id} in path {currentPackage.Path.FullName}"); dependencyToUpdate.Attribute("version").Value = newVersion.ToString(); } fileContents.Seek(0, SeekOrigin.Begin); await xml.SaveAsync(fileContents, SaveOptions.None, CancellationToken.None); }
public async Task ApplyAnUpdate( IReadOnlyCollection <PackageUpdateSet> updates, NuGetSources sources) { if (!updates.Any()) { return; } var filtered = await _selection .Filter(updates, p => Task.FromResult(true)); if (!filtered.Any()) { _logger.Verbose("All updates were filtered out"); return; } var candidate = filtered.First(); var reporter = new ConsoleReporter(); _logger.Terse("Updating " + reporter.Describe(candidate)); await _updateRunner.Update(candidate, sources); }
public StreamWriter GetStream(string namePrefix) { var fileName = namePrefix + "_nukeeeper_report.csv"; _logger.Verbose($"writing report to file at '{fileName}'"); var output = new FileStream(fileName, FileMode.Create); return(new StreamWriter(output)); }
public async Task Invoke(NuGetVersion newVersion, string packageSource, PackageInProject currentPackage) { var dirName = currentPackage.Path.Info.DirectoryName; var nuget = NuGetPath.FindExecutable(); var sources = GetSourcesCommandLine(_sources); var arguments = $"update packages.config -Id {currentPackage.Id} -Version {newVersion} {sources}"; _logger.Verbose(arguments); await _externalProcess.Run(dirName, nuget, arguments, true); }
public async Task Invoke(FileInfo file) { _logger.Info($"Nuget restore on {file.DirectoryName} {file.Name}"); var nuget = NuGetPath.FindExecutable(); var sources = GetSourcesCommandLine(_sources); var updateCommand = $"cd {file.DirectoryName} & {nuget} restore {file.Name} {sources}"; _logger.Verbose(updateCommand); var processOutput = await _externalProcess.Run(updateCommand, ensureSuccess : false); if (processOutput.Success) { _logger.Verbose($"Nuget restore on {file.Name} complete"); } else { _logger.Verbose($"Restore failed on {file.DirectoryName} {file.Name}:\n{processOutput.Output}\n{processOutput.ErrorOutput}"); } }
public async Task Invoke(NuGetVersion newVersion, string packageSource, PackageInProject currentPackage) { var dirName = currentPackage.Path.Info.DirectoryName; var sources = GetSourcesCommandLine(_sources); var updateCommand = $"cd {dirName}" + $" & dotnet restore {sources}" + $" & dotnet remove package {currentPackage.Id}" + $" & dotnet add package {currentPackage.Id} -v {newVersion} -s {packageSource}"; _logger.Verbose(updateCommand); await _externalProcess.Run(updateCommand, true); }
private async Task <IReadOnlyCollection <PackageUpdateSet> > ApplyFilters( IReadOnlyCollection <PackageUpdateSet> all, Func <PackageUpdateSet, Task <bool> > remoteCheck) { var filteredLocally = all .Where(MatchesIncludeExclude) .Where(MatchesMinAge) .ToList(); if (filteredLocally.Count < all.Count) { _logger.Verbose($"Filtered by rules from {all.Count} to {filteredLocally.Count}"); } var remoteFiltered = await ApplyRemoteFilter(filteredLocally, remoteCheck); if (remoteFiltered.Count < filteredLocally.Count) { _logger.Verbose($"Filtered by remote branch check branch from {filteredLocally.Count} to {remoteFiltered.Count}"); } return(remoteFiltered); }
private async Task <IEnumerable <RepositorySettings> > FromOrganisation(string organisationName) { var allOrgRepos = await _github.GetRepositoriesForOrganisation(organisationName); var usableRepos = allOrgRepos .Where(r => r.Permissions.Pull) .ToList(); if (allOrgRepos.Count > usableRepos.Count) { _logger.Verbose($"Can pull from {usableRepos.Count} repos out of {allOrgRepos.Count}"); } return(usableRepos.Select(r => new RepositorySettings(r))); }
public async Task Run(IGitDriver git, RepositoryData repository) { GitInit(git, repository); var updates = await _updateFinder.FindPackageUpdateSets(git.WorkingFolder); _logger.Verbose($"Report mode is {_settings.ReportMode}"); switch (_settings.ReportMode) { case ReportMode.Off: break; case ReportMode.On: // report and continue _availableUpdatesReporter.Report(repository.Pull.Name, updates); break; case ReportMode.ReportOnly: // report and exit _availableUpdatesReporter.Report(repository.Pull.Name, updates); _logger.Info("Exiting after reports only"); return; default: throw new Exception($"Unknown report mode: '{_settings.ReportMode}'"); } if (updates.Count == 0) { _logger.Terse("No potential updates found. Well done. Exiting."); return; } var targetUpdates = await _updateSelection.SelectTargets(repository.Push, updates); if (updates.Count == 0) { _logger.Terse("No updates can be applied. Exiting."); return; } await _solutionsRestore.Restore(git.WorkingFolder); await UpdateAllTargets(git, repository, targetUpdates); _logger.Info($"Done {targetUpdates.Count} Updates"); }
public NuGetSources Read(IFolder workingFolder, NuGetSources overrideValues) { if (overrideValues != null) { return(overrideValues); } var fromConfigFile = _reader.ReadNugetSources(workingFolder); if (fromConfigFile != null) { return(fromConfigFile); } _logger.Verbose("Using default global NuGet feed"); return(NuGetSources.GlobalFeed); }
public void Clone(Uri pullEndpoint) { _logger.Info($"Git clone {pullEndpoint} to {WorkingFolder.FullPath}"); Repository.Clone(pullEndpoint.ToString(), WorkingFolder.FullPath, new CloneOptions { CredentialsProvider = UsernamePasswordCredentials, OnTransferProgress = OnTransferProgress }); _logger.Verbose("Git clone complete"); }
public async Task <ForkData> FindPushFork(string userName, ForkData fallbackFork) { _logger.Verbose($"FindPushFork. Fork Mode is {_forkMode}"); switch (_forkMode) { case ForkMode.PreferFork: return(await FindUserForkOrUpstream(userName, fallbackFork)); case ForkMode.PreferSingleRepository: return(await FindUpstreamRepoOrUserFork(userName, fallbackFork)); case ForkMode.SingleRepositoryOnly: return(await FindUpstreamRepoOnly(fallbackFork)); default: throw new Exception($"Unknown fork mode: {_forkMode}"); } }
public async Task Invoke(PackageInProject currentPackage, NuGetVersion newVersion, PackageSource packageSource, NuGetSources allSources) { var projectPath = currentPackage.Path.Info.DirectoryName; var projectFileName = currentPackage.Path.Info.Name; var sourceUrl = packageSource.SourceUri.ToString(); var sources = allSources.CommandLine("-s"); _logger.Verbose($"dotnet update package {currentPackage.Id} in path {projectPath} {projectFileName} from source {sourceUrl}"); await _externalProcess.Run(projectPath, "dotnet", $"restore {projectFileName} {sources}", true); if (currentPackage.Path.PackageReferenceType == PackageReferenceType.ProjectFileOldStyle) { await _externalProcess.Run(projectPath, "dotnet", $"remove {projectFileName} package {currentPackage.Id}", true); } await _externalProcess.Run(projectPath, "dotnet", $"add {projectFileName} package {currentPackage.Id} -v {newVersion} -s {sourceUrl}", true); }
public async Task <int> Run(IGitDriver git, RepositoryData repository) { GitInit(git, repository); var sources = _nugetSourcesReader.Read(git.WorkingFolder, _settings.NuGetSources); var updates = await _updateFinder.FindPackageUpdateSets( git.WorkingFolder, sources, _settings.AllowedChange); _logger.Verbose($"Report mode is {_settings.ReportMode}"); switch (_settings.ReportMode) { case ReportMode.Off: break; case ReportMode.On: // report and continue _availableUpdatesReporter.Report(repository.Pull.Name, updates); break; case ReportMode.ReportOnly: // report and exit _availableUpdatesReporter.Report(repository.Pull.Name, updates); _logger.Info("Exiting after reports only"); return(0); default: throw new Exception($"Unknown report mode: '{_settings.ReportMode}'"); } if (updates.Count == 0) { _logger.Terse("No potential updates found. Well done. Exiting."); return(0); } var targetUpdates = await _updateSelection.SelectTargets(repository.Push, updates); return(await DoTargetUpdates(git, repository, targetUpdates, sources)); }
public async Task <bool> MakeUpdatePullRequest( IGitDriver git, PackageUpdateSet updateSet, NuGetSources sources, RepositoryData repository) { try { _logger.Terse(UpdatesLogger.OldVersionsToBeUpdated(updateSet)); git.Checkout(repository.DefaultBranch); // branch var branchName = BranchNamer.MakeName(updateSet); _logger.Verbose($"Using branch name: '{branchName}'"); git.CheckoutNewBranch(branchName); await _updateRunner.Update(updateSet, sources); var commitMessage = CommitWording.MakeCommitMessage(updateSet); git.Commit(commitMessage); git.Push("nukeeper_push", branchName); var prTitle = CommitWording.MakePullRequestTitle(updateSet); await MakeGitHubPullRequest(updateSet, repository, prTitle, branchName); git.Checkout(repository.DefaultBranch); return(true); } catch (Exception ex) { _logger.Error("Update failed", ex); return(false); } }
public void LogDebug(string data) => _logger.Verbose(data);