Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ to [Semantic Versioning][semver].
- Document more detailed usage with manual pages for even better reference.
- Include installation instruction for moving a release download into path.
- Pick an upstream project according to the saved git remotes using a flag.
- Fetch the changes of a branch when showing coverage with a specific flag.

### Maintenance

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $ git coverage # https://app.codecov.io/gh/zimeg/git-coverage
Options are available for customization:

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

## Installation
Expand Down
2 changes: 2 additions & 0 deletions man/git-coverage.1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The \fBgit-coverage\fP program opens test coverage results uploaded to \fBcodeco
.
.IP "-h, --help"
Print these usage details.
.IP "--branch"
Fetch changes to inspect. Default: "main"
.IP "--remote"
Pick an upstream project. Default: "origin"
.
Expand Down
26 changes: 19 additions & 7 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const std = @import("std");

const Flags = struct {
help: bool,
branch: []const u8,
remote: []const u8,

pub fn init(allocator: std.mem.Allocator) !Flags {
var flags = Flags{
.help = false,
.branch = "main",
.remote = "origin",
};
var args = try std.process.argsWithAllocator(allocator);
Expand All @@ -17,6 +19,8 @@ const Flags = struct {
if (std.mem.eql(u8, arg, "-h") or std.mem.eql(u8, arg, "--help")) {
flags.help = true;
break;
} else if (std.mem.eql(u8, arg, "--branch")) {
flags.branch = try parse(&args);
} else if (std.mem.eql(u8, arg, "--remote")) {
flags.remote = try parse(&args);
} else {
Expand Down Expand Up @@ -53,6 +57,7 @@ pub fn main() !void {
\\Open test coverage uploaded to codecov in a web browser.
\\
\\ --help boolean print these usage details (default: false)
\\ --branch string fetch changes to inspect (default: "main")
\\ --remote string pick an upstream project (default: "origin")
\\
, .{});
Expand All @@ -67,7 +72,7 @@ pub fn main() !void {
}
const remote = try origin(proc.stdout, flags.remote);
const project = try repo(remote);
const url = try coverage(allocator, project);
const url = try coverage(allocator, project, flags.branch);
_ = std.process.Child.run(.{
.allocator = allocator,
.argv = &[_][]const u8{ "open", url },
Expand Down Expand Up @@ -160,17 +165,24 @@ test "repo ssh" {
try std.testing.expectEqualStrings(project, "zimeg/git-coverage");
}

fn coverage(allocator: std.mem.Allocator, project: []const u8) ![]const u8 {
fn coverage(allocator: std.mem.Allocator, project: []const u8, branch: []const u8) ![]const u8 {
return std.fmt.allocPrint(
allocator,
"https://app.codecov.io/gh/{s}",
.{project},
"https://app.codecov.io/gh/{s}/tree/{s}",
.{ project, branch },
);
}

test "coverage project" {
test "coverage project main" {
const project = "zimeg/git-coverage";
const url = try coverage(std.testing.allocator, project);
const url = try coverage(std.testing.allocator, project, "main");
defer std.testing.allocator.free(url);
try std.testing.expectEqualStrings(url, "https://app.codecov.io/gh/zimeg/git-coverage");
try std.testing.expectEqualStrings(url, "https://app.codecov.io/gh/zimeg/git-coverage/tree/main");
}

test "coverage project dev" {
const project = "zimeg/git-coverage";
const url = try coverage(std.testing.allocator, project, "dev");
defer std.testing.allocator.free(url);
try std.testing.expectEqualStrings(url, "https://app.codecov.io/gh/zimeg/git-coverage/tree/dev");
}