Skip to content

Commit 9d65d66

Browse files
committed
fix truncation of first char of repository name
The existing URL parsing code truncated the first path component up to the 2nd character of the 2nd path component of a repository's name, like `orilla/mux` instead of `github.com/gorilla/mux`.
1 parent b6caea1 commit 9d65d66

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/extension.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,13 @@ export function activate(): void {
1717
return
1818
}
1919

20-
const u = new URL(editor.document.uri)
21-
const uri = {
22-
repositoryName: u.pathname.slice(2),
23-
revision: u.search.slice(1),
24-
filePath: u.hash.slice(1),
25-
}
20+
const uri = resolveURI(editor.document.uri)
2621

2722
const threads = await fetchDiscussionThreads({
2823
first: 10000,
29-
targetRepositoryName: uri.repositoryName,
30-
targetRepositoryPath: uri.filePath,
31-
relativeRev: uri.revision,
24+
targetRepositoryName: uri.repo,
25+
targetRepositoryPath: uri.path,
26+
relativeRev: uri.rev,
3227
})
3328

3429
const decorations: sourcegraph.TextDocumentDecoration[] = []
@@ -42,7 +37,7 @@ export function activate(): void {
4237
return
4338
}
4439
const target: SourcegraphGQL.IDiscussionThreadTargetRepo = thread.target
45-
if (target.relativePath !== uri.filePath) {
40+
if (target.relativePath !== uri.path) {
4641
// TODO(slimsag): shouldn't the discussions API return threads created in different files and moved here, too? lol :facepalm:
4742
return // comment has since moved to a different file.
4843
}

src/uri.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Resolve a URI of the forms git://github.com/owner/repo?rev#path and file:///path to an absolute reference, using
3+
* the given base (root) URI.
4+
*/
5+
export function resolveURI(uri: string): { repo: string; rev: string; path: string } {
6+
const url = new URL(uri)
7+
if (url.protocol === 'git:') {
8+
return {
9+
repo: (url.host + url.pathname).replace(/^\/*/, '').toLowerCase(),
10+
rev: url.search.slice(1).toLowerCase(),
11+
path: url.hash.slice(1),
12+
}
13+
}
14+
throw new Error(`unrecognized URI: ${JSON.stringify(uri)} (supported URI schemes: git)`)
15+
}

0 commit comments

Comments
 (0)