@@ -2,11 +2,13 @@ const std = @import("std");
22
33const Flags = struct {
44 help : bool ,
5+ branch : []const u8 ,
56 remote : []const u8 ,
67
78 pub fn init (allocator : std.mem.Allocator ) ! Flags {
89 var flags = Flags {
910 .help = false ,
11+ .branch = "main" ,
1012 .remote = "origin" ,
1113 };
1214 var args = try std .process .argsWithAllocator (allocator );
@@ -17,6 +19,8 @@ const Flags = struct {
1719 if (std .mem .eql (u8 , arg , "-h" ) or std .mem .eql (u8 , arg , "--help" )) {
1820 flags .help = true ;
1921 break ;
22+ } else if (std .mem .eql (u8 , arg , "--branch" )) {
23+ flags .branch = try parse (& args );
2024 } else if (std .mem .eql (u8 , arg , "--remote" )) {
2125 flags .remote = try parse (& args );
2226 } else {
@@ -53,6 +57,7 @@ pub fn main() !void {
5357 \\Open test coverage uploaded to codecov in a web browser.
5458 \\
5559 \\ --help boolean print these usage details (default: false)
60+ \\ --branch string fetch changes to inspect (default: "main")
5661 \\ --remote string pick an upstream project (default: "origin")
5762 \\
5863 , .{});
@@ -67,7 +72,7 @@ pub fn main() !void {
6772 }
6873 const remote = try origin (proc .stdout , flags .remote );
6974 const project = try repo (remote );
70- const url = try coverage (allocator , project );
75+ const url = try coverage (allocator , project , flags . branch );
7176 _ = std .process .Child .run (.{
7277 .allocator = allocator ,
7378 .argv = &[_ ][]const u8 { "open" , url },
@@ -160,17 +165,24 @@ test "repo ssh" {
160165 try std .testing .expectEqualStrings (project , "zimeg/git-coverage" );
161166}
162167
163- fn coverage (allocator : std.mem.Allocator , project : []const u8 ) ! []const u8 {
168+ fn coverage (allocator : std.mem.Allocator , project : []const u8 , branch : [] const u8 ) ! []const u8 {
164169 return std .fmt .allocPrint (
165170 allocator ,
166- "https://app.codecov.io/gh/{s}" ,
167- .{project },
171+ "https://app.codecov.io/gh/{s}/tree/{s} " ,
172+ .{ project , branch },
168173 );
169174}
170175
171- test "coverage project" {
176+ test "coverage project main " {
172177 const project = "zimeg/git-coverage" ;
173- const url = try coverage (std .testing .allocator , project );
178+ const url = try coverage (std .testing .allocator , project , "main" );
174179 defer std .testing .allocator .free (url );
175- try std .testing .expectEqualStrings (url , "https://app.codecov.io/gh/zimeg/git-coverage" );
180+ try std .testing .expectEqualStrings (url , "https://app.codecov.io/gh/zimeg/git-coverage/tree/main" );
181+ }
182+
183+ test "coverage project dev" {
184+ const project = "zimeg/git-coverage" ;
185+ const url = try coverage (std .testing .allocator , project , "dev" );
186+ defer std .testing .allocator .free (url );
187+ try std .testing .expectEqualStrings (url , "https://app.codecov.io/gh/zimeg/git-coverage/tree/dev" );
176188}
0 commit comments