Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: https remotes in coverage feature #57

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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
31 changes: 26 additions & 5 deletions src/coverage/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,33 @@ export function activateCoverage(context: ExtensionContext) {
)?.uri.path;

const gitConfig = Uri.file(`${pathToWorkspace}/.git/config`);
const remote = await workspace.fs
// Try https remote auth first
let remote = await workspace.fs
.readFile(gitConfig)
.then((buf) => buf.toString())
.then((string) => string.split("\n"))
.then((lines) => lines.find((line) => line.match(/git@.*:.*\/.*.git$/)))
.then((line) => line?.replace(/.*:/, "").replace(".git", "").split("/"));
if (!remote) return;
.then((lines) =>
lines.find((line) => line.match(/https:\/\/.*\/.*\/.*.git$/))
)
.then((line) =>
line
?.replace(/.*https:\/\/[^\/]*\//, "")
.replace(".git", "")
.split("/")
);
if (!remote) {
// if that doesn't work try looking for remotes using ssh auth
remote = await workspace.fs
.readFile(gitConfig)
.then((buf) => buf.toString())
.then((string) => string.split("\n"))
.then((lines) => lines.find((line) => line.match(/git@.*:.*\/.*.git$/)))
.then((line) =>
line?.replace(/.*:/, "").replace(".git", "").split("/")
);
}
// Throw so we can see this in Sentry
if (!remote) throw new Error("Could not get remote from .git directory");
const [owner, repo] = remote;

const gitHead = Uri.file(`${pathToWorkspace}/.git/HEAD`);
Expand Down Expand Up @@ -193,7 +213,8 @@ export function activateCoverage(context: ExtensionContext) {
error = error;
});

if (error) return;
// Throw so we can get these in Sentry
if (error) throw error;

if (!coverage || !coverage.line_coverage) {
// No coverage for this file/branch. Fall back to default branch coverage.
Expand Down
Loading