Skip to content

Commit 8ddfd60

Browse files
authored
fix: parse and split remotes for organizations using username with ssh starts (#18)
1 parent 7ae9b68 commit 8ddfd60

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ to [Semantic Versioning][semver].
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Parse and split remotes for organizations using username with ssh starts.
13+
1014
### Maintenance
1115

1216
- Limit the permission set to the minimum required for all action workflow.

src/main.zig

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,33 @@ fn repo(remote: []const u8) ![]const u8 {
152152
if (std.mem.startsWith(u8, remote, "https://github.com/")) {
153153
return remote[19 .. remote.len - 4];
154154
}
155-
if (std.mem.startsWith(u8, remote, "git@github.com:")) {
156-
return remote[15 .. remote.len - 4];
155+
if (std.mem.containsAtLeast(u8, remote, 1, "@github.com:")) {
156+
var splits = std.mem.splitScalar(u8, remote, ':');
157+
_ = splits.first();
158+
const project = splits.next().?;
159+
return project[0 .. project.len - 4];
157160
}
158161
return error.GitProtocolMissing;
159162
}
160163

161-
test "repo http" {
164+
test "repo http default" {
162165
const remote = "https://github.com/zimeg/git-coverage.git";
163166
const project = try repo(remote);
164167
try std.testing.expectEqualStrings(project, "zimeg/git-coverage");
165168
}
166169

167-
test "repo ssh" {
170+
test "repo ssh user" {
168171
const remote = "git@github.com:zimeg/git-coverage.git";
169172
const project = try repo(remote);
170173
try std.testing.expectEqualStrings(project, "zimeg/git-coverage");
171174
}
172175

176+
test "repo ssh org" {
177+
const remote = "org-0123456@github.com:example/git-coverage.git";
178+
const project = try repo(remote);
179+
try std.testing.expectEqualStrings(project, "example/git-coverage");
180+
}
181+
173182
fn coverage(allocator: std.mem.Allocator, project: []const u8, branch: []const u8, path: []const u8) ![]const u8 {
174183
const slashes = std.mem.count(u8, path, "/");
175184
const encoding = try allocator.alloc(u8, path.len + slashes * 2);

0 commit comments

Comments
 (0)