private static void ConvertCloverXMLtoJSON(XDocument xdoc, CoverallsModelcs coverallsModelcs) { foreach (XElement projects in (xdoc.Nodes().First() as XElement).Nodes()) { foreach (XElement file in projects.Nodes()) { if (file.Name == "file") { var sourceFileModel = new SourceFileModel(); sourceFileModel.Name = file.Attribute("name").Value; var coverage = new PhpList(); foreach (XElement line in file.Nodes()) { if (line.Name == "line") coverage[Convert.ToInt32(line.Attribute("num").Value)] = Convert.ToInt32(line.Attribute("count").Value); else { coverage.Normalize(Convert.ToInt32(line.Attribute("loc").Value)); } } sourceFileModel.SourceDigest = GetMd5(sourceFileModel.Name); sourceFileModel.Name = ToRelativePath(sourceFileModel.Name); sourceFileModel.Coverage = coverage; coverallsModelcs.SourceFiles.Add(sourceFileModel); } } } }
private static void Main(string[] args) { if (args.Length < 2 || args.Length > 4) { DrawHeader(); return; } var coverallsModelcs = new CoverallsModelcs(); coverallsModelcs.RepoToken = Environment.GetEnvironmentVariable(COVERALLS_REPO_TOKEN); if (string.IsNullOrEmpty(coverallsModelcs.RepoToken)) { Log.ErrorWriteLine($"Environment variable '{COVERALLS_REPO_TOKEN}' is empty"); } gitRootFolder = Path.GetFullPath(args[0]); if (!Directory.Exists(gitRootFolder)) { Log.ErrorWriteLine("Path to git root folder doesn't exist."); } var xmlPath = Path.GetFullPath(args[1]); if (!File.Exists(xmlPath)) { Log.ErrorWriteLine($"File {xmlPath} not found."); } if (args.Length >= 3 && !string.IsNullOrEmpty(args[2])) { coverallsModelcs.ServiceName = args[2]; } var gitInfo = new GitInfo(gitRootFolder); coverallsModelcs.Git.Head = gitInfo.GetLastCommitInfo(); coverallsModelcs.Git.Branch = args.Length >= 4 && !string.IsNullOrEmpty(args[3]) ? args[3] : gitInfo.GetCurrentBranchName(); coverallsModelcs.ServiceBranch = coverallsModelcs.Git.Branch; var xdoc = XDocument.Load(xmlPath); ConvertCloverXMLtoJSON(xdoc, coverallsModelcs); var bytes = coverallsModelcs.ToJson(); HttpUploadFile("https://coveralls.io/api/v1/jobs", bytes); }