Skip to content

Commit

Permalink
Refactor out common file reading code for git config
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmurray-codecov committed Dec 9, 2024
1 parent 74d9343 commit 789987e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/coverage/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$/))
)
Expand All @@ -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("/")
Expand Down

0 comments on commit 789987e

Please sign in to comment.