|
@ -1,5 +1,6 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
import { ExtensionContext, workspace } from 'vscode'; |
|
|
|
|
|
|
|
|
import { Objects } from '../../system'; |
|
|
|
|
|
import { Event, EventEmitter, ExtensionContext, workspace } from 'vscode'; |
|
|
import { BitbucketService } from './bitbucket'; |
|
|
import { BitbucketService } from './bitbucket'; |
|
|
import { BitbucketServerService } from './bitbucket-server'; |
|
|
import { BitbucketServerService } from './bitbucket-server'; |
|
|
import { CustomRemoteType, IConfig, IRemotesConfig } from '../../configuration'; |
|
|
import { CustomRemoteType, IConfig, IRemotesConfig } from '../../configuration'; |
|
@ -9,22 +10,9 @@ import { GitLabService } from './gitlab'; |
|
|
import { Logger } from '../../logger'; |
|
|
import { Logger } from '../../logger'; |
|
|
import { RemoteProvider } from './provider'; |
|
|
import { RemoteProvider } from './provider'; |
|
|
import { VisualStudioService } from './visualStudio'; |
|
|
import { VisualStudioService } from './visualStudio'; |
|
|
import { Objects } from '../../system'; |
|
|
|
|
|
|
|
|
|
|
|
export { RemoteProvider }; |
|
|
export { RemoteProvider }; |
|
|
|
|
|
|
|
|
const UrlRegex = /^(?:git:\/\/(.*?)\/|https:\/\/(.*?)\/|http:\/\/(.*?)\/|git@(.*):|ssh:\/\/(?:.*@)?(.*?)(?::.*?)?\/)(.*)$/; |
|
|
|
|
|
|
|
|
|
|
|
function getCustomProvider(type: CustomRemoteType) { |
|
|
|
|
|
switch (type) { |
|
|
|
|
|
case CustomRemoteType.Bitbucket: return (domain: string, path: string) => new BitbucketService(domain, path, true); |
|
|
|
|
|
case CustomRemoteType.BitbucketServer: return (domain: string, path: string) => new BitbucketServerService(domain, path, true); |
|
|
|
|
|
case CustomRemoteType.GitHub: return (domain: string, path: string) => new GitHubService(domain, path, true); |
|
|
|
|
|
case CustomRemoteType.GitLab: return (domain: string, path: string) => new GitLabService(domain, path, true); |
|
|
|
|
|
} |
|
|
|
|
|
return undefined; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const defaultProviderMap = new Map<string, (domain: string, path: string) => RemoteProvider>([ |
|
|
const defaultProviderMap = new Map<string, (domain: string, path: string) => RemoteProvider>([ |
|
|
['bitbucket.org', (domain: string, path: string) => new BitbucketService(domain, path)], |
|
|
['bitbucket.org', (domain: string, path: string) => new BitbucketService(domain, path)], |
|
|
['github.com', (domain: string, path: string) => new GitHubService(domain, path)], |
|
|
['github.com', (domain: string, path: string) => new GitHubService(domain, path)], |
|
@ -32,48 +20,29 @@ const defaultProviderMap = new Map Rem |
|
|
['visualstudio.com', (domain: string, path: string) => new VisualStudioService(domain, path)] |
|
|
['visualstudio.com', (domain: string, path: string) => new VisualStudioService(domain, path)] |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
let providerMap: Map<string, (domain: string, path: string) => RemoteProvider>; |
|
|
|
|
|
let remotesCfg: IRemotesConfig[]; |
|
|
|
|
|
|
|
|
|
|
|
function onConfigurationChanged() { |
|
|
|
|
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey); |
|
|
|
|
|
if (cfg === undefined) return; |
|
|
|
|
|
|
|
|
|
|
|
if (!Objects.areEquivalent(cfg.remotes, remotesCfg)) { |
|
|
|
|
|
providerMap = new Map(defaultProviderMap); |
|
|
|
|
|
|
|
|
export class RemoteProviderFactory { |
|
|
|
|
|
|
|
|
remotesCfg = cfg.remotes; |
|
|
|
|
|
if (remotesCfg != null && remotesCfg.length > 0) { |
|
|
|
|
|
for (const svc of remotesCfg) { |
|
|
|
|
|
const provider = getCustomProvider(svc.type); |
|
|
|
|
|
if (provider === undefined) continue; |
|
|
|
|
|
|
|
|
private static _providerMap: Map<string, (domain: string, path: string) => RemoteProvider>; |
|
|
|
|
|
private static _remotesCfg: IRemotesConfig[]; |
|
|
|
|
|
|
|
|
providerMap.set(svc.domain.toLowerCase(), provider); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private static _onDidChange = new EventEmitter<void>(); |
|
|
|
|
|
public static get onDidChange(): Event<void> { |
|
|
|
|
|
return this._onDidChange.event; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class RemoteProviderFactory { |
|
|
|
|
|
|
|
|
|
|
|
static configure(context: ExtensionContext) { |
|
|
static configure(context: ExtensionContext) { |
|
|
context.subscriptions.push(workspace.onDidChangeConfiguration(onConfigurationChanged)); |
|
|
|
|
|
onConfigurationChanged(); |
|
|
|
|
|
|
|
|
context.subscriptions.push(workspace.onDidChangeConfiguration(() => this.onConfigurationChanged())); |
|
|
|
|
|
this.onConfigurationChanged(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static getRemoteProvider(url: string): RemoteProvider | undefined { |
|
|
|
|
|
|
|
|
static getRemoteProvider(domain: string, path: string): RemoteProvider | undefined { |
|
|
try { |
|
|
try { |
|
|
const match = UrlRegex.exec(url); |
|
|
|
|
|
if (match == null) return undefined; |
|
|
|
|
|
|
|
|
|
|
|
const domain = match[1] || match[2] || match[3] || match[4] || match[5]; |
|
|
|
|
|
const path = match[6].replace(/\.git\/?$/, ''); |
|
|
|
|
|
|
|
|
|
|
|
const key = domain.toLowerCase().endsWith('visualstudio.com') |
|
|
|
|
|
? 'visualstudio.com' |
|
|
|
|
|
: domain; |
|
|
|
|
|
|
|
|
let key = domain.toLowerCase(); |
|
|
|
|
|
if (key.endsWith('visualstudio.com')) { |
|
|
|
|
|
key = 'visualstudio.com'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const creator = providerMap.get(key.toLowerCase()); |
|
|
|
|
|
|
|
|
const creator = this._providerMap.get(key); |
|
|
if (creator === undefined) return undefined; |
|
|
if (creator === undefined) return undefined; |
|
|
|
|
|
|
|
|
return creator(domain, path); |
|
|
return creator(domain, path); |
|
@ -83,4 +52,37 @@ export class RemoteProviderFactory { |
|
|
return undefined; |
|
|
return undefined; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static onConfigurationChanged(silent: boolean = false) { |
|
|
|
|
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey); |
|
|
|
|
|
if (cfg === undefined) return; |
|
|
|
|
|
|
|
|
|
|
|
if (!Objects.areEquivalent(cfg.remotes, this._remotesCfg)) { |
|
|
|
|
|
this._providerMap = new Map(defaultProviderMap); |
|
|
|
|
|
|
|
|
|
|
|
this._remotesCfg = cfg.remotes; |
|
|
|
|
|
if (this._remotesCfg != null && this._remotesCfg.length > 0) { |
|
|
|
|
|
for (const svc of this._remotesCfg) { |
|
|
|
|
|
const provider = this.getCustomProvider(svc.type); |
|
|
|
|
|
if (provider === undefined) continue; |
|
|
|
|
|
|
|
|
|
|
|
this._providerMap.set(svc.domain.toLowerCase(), provider); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!silent) { |
|
|
|
|
|
this._onDidChange.fire(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static getCustomProvider(type: CustomRemoteType) { |
|
|
|
|
|
switch (type) { |
|
|
|
|
|
case CustomRemoteType.Bitbucket: return (domain: string, path: string) => new BitbucketService(domain, path, true); |
|
|
|
|
|
case CustomRemoteType.BitbucketServer: return (domain: string, path: string) => new BitbucketServerService(domain, path, true); |
|
|
|
|
|
case CustomRemoteType.GitHub: return (domain: string, path: string) => new GitHubService(domain, path, true); |
|
|
|
|
|
case CustomRemoteType.GitLab: return (domain: string, path: string) => new GitLabService(domain, path, true); |
|
|
|
|
|
} |
|
|
|
|
|
return undefined; |
|
|
|
|
|
} |
|
|
} |
|
|
} |