Skip to content

Commit 13cb8fd

Browse files
Merge pull request #57 from codecov/spalmurray/fix-https-remote
fix: https remotes in coverage feature
2 parents 91152d9 + 789987e commit 13cb8fd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/coverage/coverage.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,31 @@ export function activateCoverage(context: ExtensionContext) {
138138
)?.uri.path;
139139

140140
const gitConfig = Uri.file(`${pathToWorkspace}/.git/config`);
141-
const remote = await workspace.fs
141+
const configLines = workspace.fs
142142
.readFile(gitConfig)
143143
.then((buf) => buf.toString())
144-
.then((string) => string.split("\n"))
145-
.then((lines) => lines.find((line) => line.match(/git@.*:.*\/.*.git$/)))
146-
.then((line) => line?.replace(/.*:/, "").replace(".git", "").split("/"));
147-
if (!remote) return;
144+
.then((string) => string.split("\n"));
145+
// Try https remote auth first
146+
let remote = await configLines
147+
.then((lines) =>
148+
lines.find((line) => line.match(/https:\/\/.*\/.*\/.*.git$/))
149+
)
150+
.then((line) =>
151+
line
152+
?.replace(/.*https:\/\/[^\/]*\//, "")
153+
.replace(".git", "")
154+
.split("/")
155+
);
156+
if (!remote) {
157+
// if that doesn't work try looking for remotes using ssh auth
158+
remote = await configLines
159+
.then((lines) => lines.find((line) => line.match(/git@.*:.*\/.*.git$/)))
160+
.then((line) =>
161+
line?.replace(/.*:/, "").replace(".git", "").split("/")
162+
);
163+
}
164+
// Throw so we can see this in Sentry
165+
if (!remote) throw new Error("Could not get remote from .git directory");
148166
const [owner, repo] = remote;
149167

150168
const gitHead = Uri.file(`${pathToWorkspace}/.git/HEAD`);
@@ -193,7 +211,8 @@ export function activateCoverage(context: ExtensionContext) {
193211
error = error;
194212
});
195213

196-
if (error) return;
214+
// Throw so we can get these in Sentry
215+
if (error) throw error;
197216

198217
if (!coverage || !coverage.line_coverage) {
199218
// No coverage for this file/branch. Fall back to default branch coverage.

0 commit comments

Comments
 (0)