public async Task <Dictionary <string, ICollection <string> > > Run() { // load the git repository var repoResult = GitRunner.FindRepository(Settings.WorkingDirectory); if (!repoResult.foundRepo) { Logger.LogError("Unable to find Git repository located in {0}. Shutting down.", Settings.WorkingDirectory); return(new Dictionary <string, ICollection <string> >()); } // validate the target branch if (!DiffHelper.HasBranch(repoResult.repo, Settings.TargetBranch)) { Logger.LogError("Current git repository doesn't have any branch named [{0}]. Shutting down.", Settings.TargetBranch); return(new Dictionary <string, ICollection <string> >()); } // start the cancellation timer. _cts.CancelAfter(Settings.TimeoutDuration); var listAllFilesCmd = new ListAffectedFilesCmd(Logger, _cts.Token, Settings.TargetBranch); var filterAllFolders = new FilterAffectedFoldersCmd(Logger, _cts.Token); return(await filterAllFolders.Process(listAllFilesCmd.Process(Task.FromResult(repoResult.repo)))); }
protected override void ExecuteTask() { var currentDirectory = Directory.GetCurrentDirectory(); try { Directory.SetCurrentDirectory(WorkingDir); var settings = new SettingsBuilder().Build(); var service = new TrelloServiceBuilder(settings).Build(); var board = new GetBoardByName(service).Execute(settings.Username, Board); var cards = new GetCards(service).Execute(board, List); var gitRunner = new GitRunner(new CommandRunner(), settings.GitCommand); RunMerge(gitRunner, cards); } catch (Exception exception) { throw new BuildException(exception.Message, Location); } finally { Directory.SetCurrentDirectory(currentDirectory); } }
protected override async Task <Dictionary <string, SlnFile> > ProcessImpl( Task <Dictionary <string, SlnFile> > previousTask) { var fileDictObj = await previousTask; var fileDict = (Dictionary <string, SlnFile>)fileDictObj; var repoResult = GitRunner.FindRepository(_workingDirectory); if (!repoResult.foundRepo) { Logger.LogError("Unable to find Git repository located in {0}. Shutting down.", _workingDirectory); return(new Dictionary <string, SlnFile>()); } // validate the target branch if (!DiffHelper.HasBranch(repoResult.repo, _targetGitBranch)) { Logger.LogError("Current git repository doesn't have any branch named [{0}]. Shutting down.", _targetGitBranch); return(new Dictionary <string, SlnFile>()); } var repo = repoResult.repo; var affectedFiles = DiffHelper.ChangedFiles(repo, _targetGitBranch).ToList(); var projectFolders = fileDict.Where(x => x.Value.FileType == FileType.Project).ToDictionary(x => Path.GetDirectoryName(x.Key), v => Tuple.Create(v.Key, v.Value)); // filter out any files that aren't affected by the diff var newDict = new Dictionary <string, SlnFile>(); foreach (var file in affectedFiles) { Logger.LogDebug("Affected file: {0}", file); // this file is in the solution if (fileDict.ContainsKey(file)) { newDict[file] = fileDict[file]; } else { // special case - not all of the affected files were in the solution. // Check to see if these affected files are in the same folder as any of the projects var directoryName = Path.GetDirectoryName(file); if (TryFindSubFolder(projectFolders.Keys, directoryName, out var projectFolder)) { var project = projectFolders[projectFolder].Item2; var projectPath = projectFolders[projectFolder].Item1; Logger.LogInformation("Adding project {0} to the set of affected files because non-code file {1}, " + "found inside same directory [{2}], was modified.", projectPath, file, directoryName); newDict[projectPath] = project; } } } // special case - not all of the affected files were in the solution. // Check to see if these affected files are in the same folder as any of the projects return(newDict); }
private IRemoveBranch GetRemoveBranchCommand(GitRunner gitRunner) { if (Destination == "local") { return(new RemoveLocalBranch(gitRunner)); } return(new RemoveRemoteBranch(gitRunner)); }
private void MergeCard(GitRunner gitRunner, string card) { if (gitRunner.MergeBranch(card)) { return; } Log(Level.Warning, "Merge failed. Please resolve manually and then press enter to continue"); Console.ReadLine(); }
public void IsMessageCommited() { var message = Guid.NewGuid().ToString(); var runner = new GitRunner(_storage, Env.RepoUrl); runner.SendMessage(message); Assert.Contains(runner.ReadMessages(), s => s.Contains(message)); }
public void Should_detect_Repository() { var results = GitRunner.FindRepository(Repository.BasePath); results.foundRepo.Should().BeTrue(); // note: due to what I believe is native interop here, the Repository.Info.WorkingDirectory // string appears to have an extra null terminator at the end results.repo.Info.WorkingDirectory.Should().Contain(Repository.BasePath.Trim()); }
public void IsWorkingDirectorySet() { // https://.../RepoName => RepoName var repoUrl = Env.RepoUrl; var expectedDirName = repoUrl.Substring(repoUrl.LastIndexOf('/') + 1); var expectedDirPath = Path.Combine(_storage.RootPath, expectedDirName); var runner = new GitRunner(_storage, repoUrl); Assert.Equal(expectedDirPath, runner.WorkingDirectory); }
protected override void RunTool() { this.standardOutput.Clear(); var tool = new GitRunner(this.FileSystem, this.Environment, this.ProcessRunner, this.Tools); var output = tool.RunCommand(this.Settings); if (output != null) { this.standardOutput.AddRange(output); } }
private void RunMerge(GitRunner gitRunner, List <Card> cards) { var tempFile = string.Empty; try { tempFile = Path.GetTempFileName(); if (!gitRunner.GetRemoteCards(tempFile)) { throw new Exception("Failed to retrieve list of remote branches"); } var fileInfo = new FileInfo(tempFile); if (fileInfo.Length == 0) { Log(Level.Info, "No commits."); return; } var lines = File.ReadAllLines(tempFile); var allBranches = new List <string>(); var branchMap = new Dictionary <string, string>(); foreach (var line in lines) { var tokens = line.Split(new [] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (!tokens.Any()) { continue; } var cardName = tokens.Last(); var card = cards.SingleOrDefault(x => x.CardName == cardName); if (card == null) { continue; } Log(Level.Info, card.CardName + " / MERGE: " + card.Name); MergeCard(gitRunner, line.Trim()); } } finally { if (!string.IsNullOrWhiteSpace(tempFile)) { File.Delete(tempFile); } } }
private void RemoveMerged(GitRunner gitRunner) { var mergedCards = new GetMergedCards(gitRunner, Prefix).Execute(Destination); var removeBranch = GetRemoveBranchCommand(gitRunner); foreach (var mergedCard in mergedCards) { try { Log(Level.Info, "Removing " + Destination + " branch: " + mergedCard); removeBranch.Execute(mergedCard); } catch (Exception exception) { Log(Level.Error, exception.Message, Location); } } }
protected override void ExecuteTask() { var currentDirectory = Directory.GetCurrentDirectory(); try { Directory.SetCurrentDirectory(WorkingDir); var settings = new SettingsBuilder().Build(); var gitRunner = new GitRunner(new CommandRunner(), settings.GitCommand); RemoveMerged(gitRunner); } catch (Exception exception) { throw new BuildException(exception.Message, Location); } finally { Directory.SetCurrentDirectory(currentDirectory); } }
protected override async Task <Dictionary <string, SlnFile> > ProcessImpl( Task <Dictionary <string, SlnFile> > previousTask) { var fileDictObj = await previousTask; var fileDict = (Dictionary <string, SlnFile>)fileDictObj; var repoResult = GitRunner.FindRepository(_workingDirectory); if (!repoResult.foundRepo) { Logger.LogError("Unable to find Git repository located in {0}. Shutting down.", _workingDirectory); return(new Dictionary <string, SlnFile>()); } // validate the target branch if (!DiffHelper.HasBranch(repoResult.repo, _targetGitBranch)) { Logger.LogError("Current git repository doesn't have any branch named [{0}]. Shutting down.", _targetGitBranch); return(new Dictionary <string, SlnFile>()); } var repo = repoResult.repo; var affectedFiles = DiffHelper.ChangedFiles(repo, _targetGitBranch); // filter out any files that aren't affected by the diff var newDict = new Dictionary <string, SlnFile>(); foreach (var file in affectedFiles) { Logger.LogDebug("Affected file: {0}", file); // this file is in the solution if (fileDict.ContainsKey(file)) { newDict[file] = fileDict[file]; } } return(newDict); }
public RemoveRemoteBranch(GitRunner gitRunner) { _gitRunner = gitRunner; }
public RemoveLocalBranch(GitRunner gitRunner) { _gitRunner = gitRunner; }
public GetMergedCards(GitRunner gitRunner, string prefix) { _gitRunner = gitRunner; _prefix = prefix; }
private static void EnsureSources() { var thisProject = DirRef.ProjectDir(); var temp = thisProject.Up.Up.Dir("Temp"); if (!temp.Exists) { throw new InvalidOperationException(); } var repository = temp.Dir("JSONTestSuite"); GitRunner.Ensure("https://github.com/nst/JSONTestSuite.git", repository); repository = temp.Dir("ponyc"); GitRunner.Ensure("https://github.com/ponylang/ponyc.git", repository); repository = temp.Dir("pony-source"); repository.Ensure(); string[] sources = new string[] { "https://github.com/ponylang/ponyup.git", "https://github.com/ponylang/corral.git", "https://github.com/ponylang/pony-stable.git", "https://github.com/ponylang/appdirs.git", "https://github.com/ponylang/net_ssl.git", "https://github.com/ponylang/http.git", "https://github.com/ponylang/reactive-streams.git", "https://github.com/WallarooLabs/pony-kafka.git", "https://github.com/dougmacdoug/ponylang-linal.git", "https://github.com/WallarooLabs/wallaroo.git", "https://github.com/jemc/pony-zmq.git", "https://github.com/Theodus/jennet.git", "https://github.com/jtfmumm/novitiate.git", "https://github.com/mfelsche/ponycheck.git", "https://github.com/jemc/jylis.git", "https://github.com/oraoto/pony-websocket.git", "https://github.com/jemc/ponycc.git", "https://github.com/jemc/pony-crdt.git", "https://github.com/SeanTAllen/pony-msgpack.git", "https://github.com/sylvanc/pony-lecture.git", "https://github.com/jemc/pony-sodium.git", "https://github.com/jemc/pony-capnp.git", "https://github.com/kulibali/kiuatan.git", "https://github.com/lisael/pony-postgres.git", "https://github.com/mfelsche/ponyfmt.git", "https://github.com/joncfoo/pony-sqlite.git", "https://github.com/autodidaddict/ponymud.git", "https://github.com/ponylang/changelog-tool.git", "https://github.com/jemc/pony-pegasus.git", "https://github.com/jemc/pony-llvm.git", "https://github.com/krig/tinyhorse.git", "https://github.com/sylvanc/peg.git", "https://github.com/EpicEric/pony-mqtt.git", "https://github.com/jemc/pony-rope.git", "https://github.com/BrianOtto/pony-gui.git", "https://github.com/jemc/pony-jason.git", "https://github.com/BrianOtto/pony-win32.git", "https://github.com/jkleiser/toy-forth-in-pony.git", "https://github.com/emilbayes/pony-endianness.git", "https://github.com/sgebbie/pony-graphs.git", "https://github.com/lisael/pied.git", "https://github.com/ponylang/regex.git", "https://github.com/mfelsche/pony-maybe.git", "https://github.com/sgebbie/pony-statsd.git", "https://github.com/jemc/pony-unsafe.git", "https://github.com/lisael/pony-bitarray.git", "https://github.com/lisael/pony-bm.git", "https://github.com/slayful/sagittarius.git", "https://github.com/ponylang/glob.git", "https://github.com/jtfmumm/pony-logic.git", "https://github.com/sgebbie/pony-tty.git", "https://github.com/jtfmumm/pony-queue.git", "https://github.com/mfelsche/pony-kv.git", "https://github.com/elmattic/pony-toml.git", "https://github.com/krig/pony-sform.git", "https://github.com/jemc/pony-dict.git", "https://github.com/cquinn/ponycli.git", "https://github.com/niclash/pink2web.git", "https://github.com/andrenth/pony-uuid.git", "https://github.com/kulibali/kiuatan-calculator.git", "https://github.com/Theodus/pony-stats.git", "https://github.com/jtfmumm/microkanren-pony.git", "https://github.com/ergl/sss.git", "https://github.com/SeanTAllen/lori.git", }; foreach (var url in sources) { var name = Path.GetFileNameWithoutExtension(url); GitRunner.Ensure(url, repository.Dir(name)); } }
private static async Task <int> RunIncrementalist(SlnOptions options) { var logger = new ConsoleLogger("Incrementalist", (s, level) => level >= (options.Verbose ? LogLevel.Debug : LogLevel.Information), false); try { var pwd = options.WorkingDirectory ?? Directory.GetCurrentDirectory(); var insideRepo = Repository.IsValid(pwd); if (!insideRepo) { logger.LogError("Current path {0} is not located inside any known Git repository.", pwd); return(-2); } var repoFolder = Repository.Discover(pwd); var workingFolder = Directory.GetParent(repoFolder).Parent; var repoResult = GitRunner.FindRepository(workingFolder.FullName); if (!repoResult.foundRepo) { Console.WriteLine("Unable to find Git repository located in {0}. Shutting down.", workingFolder.FullName); return(-3); } // validate the target branch if (!DiffHelper.HasBranch(repoResult.repo, options.GitBranch)) { // workaround common CI server issues and check to see if this same branch is located // under "origin/{branchname}" options.GitBranch = $"origin/{options.GitBranch}"; if (!DiffHelper.HasBranch(repoResult.repo, options.GitBranch)) { Console.WriteLine("Current git repository doesn't have any branch named [{0}]. Shutting down.", options.GitBranch); Console.WriteLine("[Debug] Here are all of the currently known branches in this repository"); foreach (var b in repoResult.repo.Branches) { Console.WriteLine(b.FriendlyName); } return(-4); } } if (!string.IsNullOrEmpty(repoFolder)) { if (options.ListFolders) { await AnalyzeFolderDiff(options, workingFolder, logger); } else { await AnaylzeSolutionDIff(options, workingFolder, logger); } } return(0); } catch (Exception ex) { logger.LogError(ex, "Error encountered during execution of Incrementalist."); return(-1); } }
public void IsRepoDirCreated() { var runner = new GitRunner(_storage, Env.RepoUrl); Assert.True(Directory.Exists(runner.WorkingDirectory)); }