Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from larzw/develop
Browse files Browse the repository at this point in the history
Basic support for uploading a coverage report via Git and AppVeyor.
  • Loading branch information
larzw authored Feb 21, 2017
2 parents e466270 + c58638d commit 6092790
Show file tree
Hide file tree
Showing 21 changed files with 135 additions and 273 deletions.
7 changes: 0 additions & 7 deletions source/codecov/codecov/Coverage/IReport.cs

This file was deleted.

26 changes: 15 additions & 11 deletions source/codecov/codecov/Coverage/Report.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using System;
using System.Collections.Generic;

namespace codecov.Coverage
{
public class Report : IReport
public static class Report
{
public string Coverage { get; }
private const string Footer = "<<<<<< EOF";

public Report(string file)
private const string Header = "<<<<<< network";

public static string CreateReport(IEnumerable<string> files)
{
Coverage = Read(file);
var report = $"{Header}\n";
foreach (var file in files)
{
report += $"{Read(file)}\n{Footer}\n";
}

return report;
}

private static string Read(string file)
Expand All @@ -18,12 +27,7 @@ private static string Read(string file)
throw new ArgumentException(nameof(file));
}

return Map(System.IO.File.ReadAllText(file));
}

private static string Map(string report)
{
return $"<<<<<< network\n{report}\n<<<<<< EOF";
return System.IO.File.ReadAllText(file);
}
}
}
}
29 changes: 29 additions & 0 deletions source/codecov/codecov/Coverage/Uploder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Net;
using codecov.Program;
using codecov.Services.Utils;

namespace codecov.Coverage
{
public static class Uploder
{
public static void Upload(Options options, string report, IService service)
{
var url = $"https://codecov.io/upload/v4?{service.CreateQuery(options)}";

//Post: Ping
var post = new WebClient();
post.Headers.Add("Content-Type: text/plain");
var response = post.UploadString(url, "POST", string.Empty);
Console.WriteLine(response);

// Put: Upload report.
url = response.Trim().Split('\n')[1];
var put = new WebClient();
put.Headers.Add("Content-Type: text/plain");
put.Headers.Add("x-amz-acl: public-read");
put.Headers.Add("x-amz-storage-class: REDUCED_REDUNDANCY");
put.UploadString(url, "PUT", report);
}
}
}
13 changes: 0 additions & 13 deletions source/codecov/codecov/Options.cs

This file was deleted.

33 changes: 0 additions & 33 deletions source/codecov/codecov/Program.cs

This file was deleted.

16 changes: 16 additions & 0 deletions source/codecov/codecov/Program/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CommandLine;

namespace codecov.Program
{
public class Options
{
[Option('d', "dump", HelpText = "Don't upload and dump to stdin.")]
public string Dump { get; set; }

[OptionArray('f', "file", Required = true, HelpText = "Target file(s) to upload.")]
public string[] File { get; set; }

[Option('t', "token", HelpText = "Set the private repository token.")]
public string Token { get; set; }
}
}
18 changes: 18 additions & 0 deletions source/codecov/codecov/Program/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using codecov.Coverage;
using codecov.Services.Utils;

namespace codecov.Program
{
internal static class Program
{
private static void Main(string[] args)
{
var options = new Options();
CommandLine.Parser.Default.ParseArgumentsStrict(args, options);

var service = ServiceFactory.CreateService;
var report = Report.CreateReport(options.File);
Uploder.Upload(options, report, service);
}
}
}
2 changes: 1 addition & 1 deletion source/codecov/codecov/Services/AppVeyor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace codecov.Services
{
internal class AppVeyor : Url, IDetect
internal class AppVeyor : Query, IService
{
public AppVeyor()
{
Expand Down
2 changes: 1 addition & 1 deletion source/codecov/codecov/Services/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace codecov.Services
{
internal class Git : Url, IDetect
internal class Git : Query, IService
{
public Git()
{
Expand Down
2 changes: 1 addition & 1 deletion source/codecov/codecov/Services/Hg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace codecov.Services
{
internal class Hg : Url, IDetect
internal class Hg : Query, IService
{
public Hg()
{
Expand Down
16 changes: 0 additions & 16 deletions source/codecov/codecov/Services/Utils/EnumDescription.cs

This file was deleted.

7 changes: 0 additions & 7 deletions source/codecov/codecov/Services/Utils/IDetect.cs

This file was deleted.

8 changes: 6 additions & 2 deletions source/codecov/codecov/Services/Utils/IService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace codecov.Services.Utils
using codecov.Program;

namespace codecov.Services.Utils
{
public interface IService
{
IUrl Find { get; }
bool Detect { get; }

string CreateQuery(Options options);
}
}
8 changes: 0 additions & 8 deletions source/codecov/codecov/Services/Utils/IUrl.cs

This file was deleted.

31 changes: 31 additions & 0 deletions source/codecov/codecov/Services/Utils/Query.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using codecov.Program;

namespace codecov.Services.Utils
{
public class Query
{
protected IDictionary<string, string> QueryParameters { get; } =
new Dictionary<string, string>
{
{"branch", string.Empty},
{"commit", string.Empty},
{"build", string.Empty},
{"build_url", string.Empty},
{"tag", string.Empty},
{"slug", string.Empty},
{"yaml", string.Empty},
{"service", string.Empty},
{"flags", string.Empty},
{"pr", string.Empty},
{"job", string.Empty}
};

public string CreateQuery(Options options)
{
var query = string.Join("&", QueryParameters.Select(x => $"{x.Key}={x.Value ?? string.Empty}"));
return $"package=exe-beta&token={options.Token}&{query}";
}
}
}
37 changes: 0 additions & 37 deletions source/codecov/codecov/Services/Utils/QueryParameter.cs

This file was deleted.

17 changes: 0 additions & 17 deletions source/codecov/codecov/Services/Utils/Service.cs

This file was deleted.

12 changes: 12 additions & 0 deletions source/codecov/codecov/Services/Utils/ServiceFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Linq;

namespace codecov.Services.Utils
{
public static class ServiceFactory
{
private static readonly IEnumerable<IService> Services = new IService[] { new AppVeyor(), new Git() };

public static IService CreateService => Services.FirstOrDefault(x => x.Detect);
}
}
30 changes: 0 additions & 30 deletions source/codecov/codecov/Services/Utils/Url.cs

This file was deleted.

Loading

0 comments on commit 6092790

Please sign in to comment.