Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit e2ee51d

Browse files
Matthew Bentleyfelixfbecker
authored andcommitted
feat: add option to remap URLs before opening (#24)
This adds two options: sourcegraph.ignoreRemoteHostname: strips the hostname from a git-based remote. For example, `git@company.com:repo` becomes just `repo` if this is true sourcegraph.remoteUrlPrepend: a mapping from string -> string that allows simple remapping of remote names. If the remote hostname (user@host) matches the key, the value is prepended to the remote. For example, if this is `{"git@secondary.company.com": "two/"}, the repo `git@secondary.company.com:repo` becomes `two/repo` Fixes #8
1 parent a9f62a9 commit e2ee51d

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Keyboard Shortcuts:
2525
This extension contributes the following settings:
2626

2727
- `sourcegraph.url`: The Sourcegraph instance to use. Specify your on-premises Sourcegraph instance here, if applicable.
28+
- `sourcegraph.remoteUrlReplacements`: Object, where each `key` is replaced by `value` in the remote url.
2829

2930
## Questions & Feedback
3031

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sourcegraph",
33
"displayName": "Sourcegraph",
44
"description": "Sourcegraph for VS Code",
5-
"version": "1.0.12",
5+
"version": "1.0.16",
66
"publisher": "sourcegraph",
77
"license": "MIT",
88
"icon": "images/logo.png",
@@ -11,7 +11,7 @@
1111
"url": "https://github.com/sourcegraph/sourcegraph-vscode.git"
1212
},
1313
"engines": {
14-
"vscode": "^1.11.0"
14+
"vscode": "^1.37.0"
1515
},
1616
"categories": [
1717
"Other"
@@ -56,6 +56,13 @@
5656
],
5757
"default": "https://sourcegraph.com",
5858
"description": "The base URL of the Sourcegraph instance to use."
59+
},
60+
"sourcegraph.remoteUrlReplacements": {
61+
"type": [
62+
"object"
63+
],
64+
"default": {},
65+
"description": "For each item in this object, replace key with value in the remote url."
5966
}
6067
}
6168
}

src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ export function getSourcegraphUrl(): string {
99
}
1010
return url
1111
}
12+
13+
export function getRemoteUrlReplacements(): Record<string, string> {
14+
// has default value
15+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16+
const replacements = vscode.workspace
17+
.getConfiguration('sourcegraph')
18+
.get<Record<string, string>>('remoteUrlReplacements')!
19+
return replacements
20+
}

src/git.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import execa from 'execa'
22
import * as path from 'path'
33
import { log } from './log'
4+
import { getRemoteUrlReplacements } from './config'
45

56
/**
67
* Returns the names of all git remotes, e.g. ["origin", "foobar"]
@@ -15,7 +16,15 @@ async function gitRemotes(repoDir: string): Promise<string[]> {
1516
* e.g. `origin` -> `git@github.com:foo/bar`
1617
*/
1718
async function gitRemoteURL(repoDir: string, remoteName: string): Promise<string> {
18-
const { stdout } = await execa('git', ['remote', 'get-url', remoteName], { cwd: repoDir })
19+
let { stdout } = await execa('git', ['remote', 'get-url', remoteName], { cwd: repoDir })
20+
const replacementsList = getRemoteUrlReplacements()
21+
22+
for (const r in replacementsList) {
23+
if (typeof r === 'string') {
24+
stdout = stdout.replace(r, replacementsList[r])
25+
}
26+
}
27+
1928
return stdout
2029
}
2130

0 commit comments

Comments
 (0)