Skip to content

Commit

Permalink
Fix https remote in git config read
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmurray-codecov committed Dec 9, 2024
1 parent 0779d30 commit 74d9343
Showing 1 changed file with 26 additions and 5 deletions.
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

0 comments on commit 74d9343

Please sign in to comment.