From 74d93430d8ba6096f51862e6d25570a708653f68 Mon Sep 17 00:00:00 2001 From: Spencer Murray Date: Mon, 9 Dec 2024 17:48:35 -0500 Subject: [PATCH] Fix https remote in git config read --- src/coverage/coverage.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/coverage/coverage.ts b/src/coverage/coverage.ts index 2464f62..7e1b279 100644 --- a/src/coverage/coverage.ts +++ b/src/coverage/coverage.ts @@ -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`); @@ -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.