Skip to content

Commit a9fed60

Browse files
authored
feat: fetch the changes of a branch when showing coverage with a specific flag (#12)
1 parent fc23bfd commit a9fed60

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ to [Semantic Versioning][semver].
1313
- Document more detailed usage with manual pages for even better reference.
1414
- Include installation instruction for moving a release download into path.
1515
- Pick an upstream project according to the saved git remotes using a flag.
16+
- Fetch the changes of a branch when showing coverage with a specific flag.
1617

1718
### Maintenance
1819

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $ git coverage # https://app.codecov.io/gh/zimeg/git-coverage
1515
Options are available for customization:
1616

1717
- `--help`: boolean. Print these usage details. Default: `false`
18+
- `--branch`: string. Fetch changes to inspect. Default: `main`
1819
- `--remote`: string. Pick an upstream project. Default: `origin`
1920

2021
## Installation

man/git-coverage.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The \fBgit-coverage\fP program opens test coverage results uploaded to \fBcodeco
1717
.
1818
.IP "-h, --help"
1919
Print these usage details.
20+
.IP "--branch"
21+
Fetch changes to inspect. Default: "main"
2022
.IP "--remote"
2123
Pick an upstream project. Default: "origin"
2224
.

src/main.zig

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ const std = @import("std");
22

33
const 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

Comments
 (0)