From 789987ee23b6282ed6aa429ee2606e2c01a0196d Mon Sep 17 00:00:00 2001 From: Spencer Murray Date: Mon, 9 Dec 2024 18:06:48 -0500 Subject: [PATCH] Refactor out common file reading code for git config --- src/coverage/coverage.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/coverage/coverage.ts b/src/coverage/coverage.ts index 7e1b279..7caa4e8 100644 --- a/src/coverage/coverage.ts +++ b/src/coverage/coverage.ts @@ -138,11 +138,12 @@ export function activateCoverage(context: ExtensionContext) { )?.uri.path; const gitConfig = Uri.file(`${pathToWorkspace}/.git/config`); - // Try https remote auth first - let remote = await workspace.fs + const configLines = workspace.fs .readFile(gitConfig) .then((buf) => buf.toString()) - .then((string) => string.split("\n")) + .then((string) => string.split("\n")); + // Try https remote auth first + let remote = await configLines .then((lines) => lines.find((line) => line.match(/https:\/\/.*\/.*\/.*.git$/)) ) @@ -154,10 +155,7 @@ export function activateCoverage(context: ExtensionContext) { ); 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")) + remote = await configLines .then((lines) => lines.find((line) => line.match(/git@.*:.*\/.*.git$/))) .then((line) => line?.replace(/.*:/, "").replace(".git", "").split("/")