Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Keyboard Shortcuts:
This extension contributes the following settings:

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

## Questions & Feedback

Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sourcegraph",
"displayName": "Sourcegraph",
"description": "Sourcegraph for VS Code",
"version": "1.0.12",
"version": "1.0.16",
"publisher": "sourcegraph",
"license": "MIT",
"icon": "images/logo.png",
Expand All @@ -11,7 +11,7 @@
"url": "https://github.com/sourcegraph/sourcegraph-vscode.git"
},
"engines": {
"vscode": "^1.11.0"
"vscode": "^1.37.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -56,6 +56,13 @@
],
"default": "https://sourcegraph.com",
"description": "The base URL of the Sourcegraph instance to use."
},
"sourcegraph.remoteUrlReplacements": {
"type": [
"object"
],
"default": {},
"description": "For each item in this object, replace key with value in the remote url."
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ export function getSourcegraphUrl(): string {
}
return url
}

export function getRemoteUrlReplacements(): Record<string, string> {
// has default value
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const replacements = vscode.workspace
.getConfiguration('sourcegraph')
.get<Record<string, string>>('remoteUrlReplacements')!
return replacements
}
11 changes: 10 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import execa from 'execa'
import * as path from 'path'
import { log } from './log'
import { getRemoteUrlReplacements } from './config'

/**
* Returns the names of all git remotes, e.g. ["origin", "foobar"]
Expand All @@ -15,7 +16,15 @@ async function gitRemotes(repoDir: string): Promise<string[]> {
* e.g. `origin` -> `git@github.com:foo/bar`
*/
async function gitRemoteURL(repoDir: string, remoteName: string): Promise<string> {
const { stdout } = await execa('git', ['remote', 'get-url', remoteName], { cwd: repoDir })
let { stdout } = await execa('git', ['remote', 'get-url', remoteName], { cwd: repoDir })
const replacementsList = getRemoteUrlReplacements()

for (const r in replacementsList) {
if (typeof r === 'string') {
stdout = stdout.replace(r, replacementsList[r])
}
}

return stdout
}

Expand Down