Skip to content

Commit

Permalink
Add supporting source tag
Browse files Browse the repository at this point in the history
  • Loading branch information
krolol committed Dec 2, 2019
1 parent 7f3f934 commit b1706d7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ class CoberturaConverter
private const string _pathToLine = "lines/line";
private const string _pathToSource = "coverage/sources/source";

public static JSONCoverage ConvertFromCobertura(string pathToCoverageFile)
public static JSONCoverage ConvertFromCobertura(string pathToCoverageFile, string repoRoot)
{
JSONCoverage jsonCoverage = new JSONCoverage();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(pathToCoverageFile);
XmlNode sourceNode = xmlDocument.SelectSingleNode(_pathToSource);
string source = string.Equals(sourceNode.Value, null) ? string.Empty : sourceNode.Value;
string source = xmlDocument.SelectSingleNode(_pathToSource).InnerText;
repoRoot = string.Equals(repoRoot, null) ? string.Empty : repoRoot;
foreach (XmlNode xmlNode in xmlDocument.SelectNodes(_pathToClass))
{
Console.WriteLine(Path.Combine(source, xmlNode.Attributes["filename"].Value));
string fileName = Help.GetRelativeFilePath(Path.Combine(source, xmlNode.Attributes["filename"].Value));
{
string fileName = Help.GetRelativeFilePath(Path.Combine(source, xmlNode.Attributes["filename"].Value), repoRoot);
FileCoverage fileCoverage = new FileCoverage(fileName);
var a = xmlNode.SelectNodes(_pathToLine).Count;
foreach (XmlNode node in xmlNode.SelectNodes(_pathToLine))
Expand Down
27 changes: 19 additions & 8 deletions CoverageUploader/CoverageUploader/Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ namespace CoverageUploader
{
class Help
{
public static string GetRelativeFilePath(string path)
{
string rootFolder = path;
do
{
rootFolder = Directory.GetParent(rootFolder).FullName;
} while (!Repository.IsValid(rootFolder));
return Path.GetRelativePath(rootFolder, path).Replace("\\","/");
public static string GetRelativeFilePath(string path, string repoRoot)
{
string rootFolder = string.IsNullOrEmpty(repoRoot) ? path : repoRoot;
while (!Repository.IsValid(rootFolder))
{
rootFolder = Directory.GetParent(rootFolder).FullName;
}
if (!string.IsNullOrEmpty(repoRoot)) {
DirectoryInfo relativeFullPath = Directory.GetParent(path);
string fileName = Path.GetFileName(path);
string relativePath = string.Empty;
while (!File.Exists(path))
{
relativePath = Path.Combine(Path.Combine(relativeFullPath.Name), relativePath);
path = Path.Combine(rootFolder, Path.Combine(relativePath, fileName));
relativeFullPath = Directory.GetParent(relativeFullPath.FullName);
}
}
return Path.GetRelativePath(rootFolder, path).Replace("\\", "/");
}
}
}
24 changes: 13 additions & 11 deletions CoverageUploader/CoverageUploader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,19 @@ public class Arguments
public string BitbucketURL { get; set; }
[Option('f', "coverage.file", Required = true, HelpText = "Path to coverage file")]
public string CoverageFile { get; set; }
[Option('r', "repository.root", Required = false, HelpText = "Path to repository root folder")]
public string RepositoryRoot { get; set; }

}
class Program
{
static int Main(string[] args)
{
Parser.Default.ParseArguments<Arguments>(args)
.WithParsed(arguments => RunArguments(arguments));
return -1;
}

private static int RunArguments(Arguments arguments)
{
try
{
JSONCoverage jsonCoverage = CoberturaConverter.ConvertFromCobertura(arguments.CoverageFile);
var client = new Client(arguments.BitbucketURL, arguments.Username, arguments.Password);
var responseMessage = client.PostCoverageAsync(arguments.CommidID, jsonCoverage.ConvertToJson());
Console.WriteLine(responseMessage.Result.ToString());
args = new string[] { "-u", "5", "-p", "2", "-c", "3", "-b", "4", "-f", "D:\\ServerUnitTests.xml" };
Parser.Default.ParseArguments<Arguments>(args)
.WithParsed(arguments => RunArguments(arguments));
return 0;
}
catch(Exception e)
Expand All @@ -49,5 +43,13 @@ private static int RunArguments(Arguments arguments)
return -1;
}
}

private static void RunArguments(Arguments arguments)
{
JSONCoverage jsonCoverage = CoberturaConverter.ConvertFromCobertura(arguments.CoverageFile, arguments.RepositoryRoot);
var client = new Client(arguments.BitbucketURL, arguments.Username, arguments.Password);
var responseMessage = client.PostCoverageAsync(arguments.CommidID, jsonCoverage.ConvertToJson());
Console.WriteLine(responseMessage.Result.ToString());
}
}
}

0 comments on commit b1706d7

Please sign in to comment.