Skip to content

Commit

Permalink
Merge pull request #57 from codecov/spalmurray/fix-https-remote
Browse files Browse the repository at this point in the history
fix: https remotes in coverage feature
  • Loading branch information
spalmurray-codecov authored Dec 9, 2024
2 parents 91152d9 + 789987e commit 13cb8fd
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/coverage/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,31 @@ export function activateCoverage(context: ExtensionContext) {
)?.uri.path;

const gitConfig = Uri.file(`${pathToWorkspace}/.git/config`);
const remote = await workspace.fs
const configLines = 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((string) => string.split("\n"));
// Try https remote auth first
let remote = await configLines
.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 configLines
.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 +211,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

0 comments on commit 13cb8fd

Please sign in to comment.