public void DetectManifestsUsingProtobuf() { var checkoutLocation = Path.Combine(Path.GetTempPath(), "repositories"); var checkoutDirectory = new DirectoryInfo(checkoutLocation); if (checkoutDirectory.Exists) { checkoutDirectory.Delete(true); } checkoutDirectory.Create(); // clone https://github.com/protocolbuffers/protobuf to a temp location Invoke.Command("git", "clone https://github.com/protocolbuffers/protobuf", checkoutLocation); var repositoryLocation = Path.Combine(checkoutLocation, "protobuf"); var reader = new AgentReader("freshli-agent-java"); var actualManifests = reader.DetectManifests(repositoryLocation); var expectedManifests = new List <string>() { "java/pom.xml", "java/protoc/pom.xml", "protoc-artifacts/pom.xml", "ruby/pom.xml" }; Assert.Equal(expectedManifests, actualManifests); // delete cloned files checkoutDirectory.Delete(true); }
private static void RunValidatingPackageUrls(string agentFileAndPath, string argument) { var processManifestOutput = Invoke.Command(agentFileAndPath, argument, ".").TrimEnd('\n'); if (processManifestOutput.Contains('\n')) { foreach (var output in processManifestOutput.Split("\n")) { Console.WriteLine(@"Received the following package urls: " + output); } } else { Console.WriteLine(@"Received the following package urls: " + processManifestOutput); } }
private static void RunDetectManfiest(string agentFileAndPath, string argument, string url, string directory, DateTime startDate) { var detectManifestOutput = Invoke.Command(agentFileAndPath, argument + $" {url}", "."); if (detectManifestOutput.ToLower().Contains("gemfile")) { foreach (var manifestFile in detectManifestOutput.Split("\t")) { if (manifestFile.ToLower().Contains("gemfile")) { RunProcessManifest(agentFileAndPath, "process-manifests", url, directory, manifestFile.Trim(), startDate); } } } }
public void RunAgentsVerify(string agentFileAndPath, string argument, string cacheDir, string languageName) { var startTime = DateTime.Now; languageName = string.IsNullOrEmpty(languageName) ? Path.DirectorySeparatorChar + "repositories" : Path.DirectorySeparatorChar + languageName; var validatingRepositoriesUrl = Invoke.Command(agentFileAndPath, argument, ".").TrimEnd('\n', '\r'); if (validatingRepositoriesUrl.Contains('\n')) { foreach (var url in validatingRepositoriesUrl.Split("\n")) { try { var pos = url.LastIndexOf(Path.DirectorySeparatorChar) + 1; Invoke.Command("git", $"clone {url} {cacheDir}{Path.DirectorySeparatorChar}{languageName}{Path.DirectorySeparatorChar}{url.Trim().Substring(pos, url.Length - pos)}", cacheDir); RunDetectManfiest(agentFileAndPath, "detect-manifests", url, cacheDir, startTime); } catch (Exception e) { Console.Error.WriteLine(e.Message); } } } else { try { var pos = validatingRepositoriesUrl.LastIndexOf(Path.DirectorySeparatorChar) + 1; Invoke.Command("git", $"clone {validatingRepositoriesUrl} {cacheDir}{Path.DirectorySeparatorChar}{languageName}{Path.DirectorySeparatorChar}{validatingRepositoriesUrl.Trim().Substring(pos, validatingRepositoriesUrl.Length - pos)}", cacheDir); RunDetectManfiest(agentFileAndPath, "detect-manifests", validatingRepositoriesUrl, cacheDir + languageName, startTime); } catch (Exception e) { Console.Error.WriteLine(e.Message); } } }
private static void RunProcessManifest(string agentFileAndPath, string argument, string url, string workingDirectory, string detectManifestFiles, DateTime startDate) { var processManifestOutput = Invoke.Command(agentFileAndPath, argument + " " + detectManifestFiles + " " + DateTimeOffset.Now.ToString("s") + "Z", workingDirectory); var processDetectManifestFiles = DetectManifestFileCount(detectManifestFiles); var processManifestFiles = VerifyFiles(processManifestOutput); try { var pos = url.LastIndexOf(Path.DirectorySeparatorChar) + 1; var gitStatus = Invoke.Command("git", "status", workingDirectory + Path.DirectorySeparatorChar + url.Trim().Substring(pos, url.Length - pos)); if (!gitStatus.Contains("working tree clean")) { Console.Error.Write("The following are residual modifications from the cloned repository: " + url + " "); Console.Error.Write(gitStatus); } } catch (Exception e) { Console.Error.WriteLine("Failed to validate for residual modifications due to the following: " + e); } if (processDetectManifestFiles.Count != processManifestFiles.Count) { Console.Error.Write("Number of detected manifest files and process files are not equal."); } else { var timeDifference = DateTime.Now - startDate; Console.WriteLine(@"Repository tested: " + url); Console.WriteLine(@"Total time to execute agent verify: " + timeDifference); RunValidatingPackageUrls(agentFileAndPath, "validating-package-urls"); } }