mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
* Revert "Revert "Merge from vscode merge-base (#22769)" (#22779)"
This reverts commit 47a1745180.
* Fix notebook download task
* Remove done call from extensions-ci
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { UriHandler, Uri, window, Disposable, commands } from 'vscode';
|
|
import { dispose } from './util';
|
|
import * as querystring from 'querystring';
|
|
|
|
const schemes = new Set(['file', 'git', 'http', 'https', 'ssh']);
|
|
|
|
export class GitProtocolHandler implements UriHandler {
|
|
|
|
private disposables: Disposable[] = [];
|
|
|
|
constructor() {
|
|
this.disposables.push(window.registerUriHandler(this));
|
|
}
|
|
|
|
handleUri(uri: Uri): void {
|
|
switch (uri.path) {
|
|
case '/clone': this.clone(uri);
|
|
}
|
|
}
|
|
|
|
private clone(uri: Uri): void {
|
|
const data = querystring.parse(uri.query);
|
|
|
|
if (!data.url) {
|
|
console.warn('Failed to open URI:', uri);
|
|
return;
|
|
}
|
|
|
|
if (Array.isArray(data.url) && data.url.length === 0) {
|
|
console.warn('Failed to open URI:', uri);
|
|
return;
|
|
}
|
|
|
|
let cloneUri: Uri;
|
|
try {
|
|
let rawUri = Array.isArray(data.url) ? data.url[0] : data.url;
|
|
|
|
// Handle SSH Uri
|
|
// Ex: git@github.com:microsoft/vscode.git
|
|
rawUri = rawUri.replace(/^(git@[^\/:]+)(:)/i, 'ssh://$1/');
|
|
|
|
cloneUri = Uri.parse(rawUri, true);
|
|
|
|
// Validate against supported schemes
|
|
if (!schemes.has(cloneUri.scheme.toLowerCase())) {
|
|
throw new Error('Unsupported scheme.');
|
|
}
|
|
}
|
|
catch (ex) {
|
|
console.warn('Invalid URI:', uri);
|
|
return;
|
|
}
|
|
|
|
commands.executeCommand('git.clone', cloneUri.toString(true));
|
|
}
|
|
|
|
dispose(): void {
|
|
this.disposables = dispose(this.disposables);
|
|
}
|
|
}
|