mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Adds GitLab remote link support
Adds Bitbucket remote link support Adds Visual Studio Team Services remote link support
This commit is contained in:
27
src/git/remotes/bitbucket.ts
Normal file
27
src/git/remotes/bitbucket.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
import { RemoteProvider } from './provider';
|
||||||
|
|
||||||
|
export class BitbucketService extends RemoteProvider {
|
||||||
|
|
||||||
|
constructor(public domain: string, public path: string) {
|
||||||
|
super(domain, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return 'Bitbucket';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getUrlForBranch(branch: string): string {
|
||||||
|
return `${this.baseUrl}/commits/branch/${branch}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getUrlForCommit(sha: string): string {
|
||||||
|
return `${this.baseUrl}/commits/${sha}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getUrlForFile(fileName: string, branch?: string, sha?: string): string {
|
||||||
|
if (sha) return `${this.baseUrl}/src/${sha}/${fileName}`;
|
||||||
|
if (branch) return `${this.baseUrl}/src/${branch}/${fileName}`;
|
||||||
|
return `${this.baseUrl}?path=${fileName}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { RemoteProvider } from './provider';
|
import { RemoteProvider } from './provider';
|
||||||
|
import { BitbucketService } from './bitbucket';
|
||||||
import { GitHubService } from './github';
|
import { GitHubService } from './github';
|
||||||
|
import { GitLabService } from './gitlab';
|
||||||
|
import { VisualStudioService } from './visualStudio';
|
||||||
import { Logger } from '../../logger';
|
import { Logger } from '../../logger';
|
||||||
|
|
||||||
export { RemoteProvider };
|
export { RemoteProvider };
|
||||||
|
|
||||||
const providerMap = new Map<string, (domain: string, path: string) => RemoteProvider>([
|
const providerMap = new Map<string, (domain: string, path: string) => RemoteProvider>([
|
||||||
['github.com', (domain: string, path: string) => new GitHubService(domain, path)]
|
['bitbucket.org', (domain: string, path: string) => new BitbucketService(domain, path)],
|
||||||
|
['github.com', (domain: string, path: string) => new GitHubService(domain, path)],
|
||||||
|
['gitlab.com', (domain: string, path: string) => new GitLabService(domain, path)],
|
||||||
|
['visualstudio.com', (domain: string, path: string) => new VisualStudioService(domain, path)]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const UrlRegex = /^(?:git:\/\/(.*?)\/|https:\/\/(.*?)\/|http:\/\/(.*?)\/|git@(.*):\/\/|ssh:\/\/git@(.*?)\/)(.*)$/;
|
const UrlRegex = /^(?:git:\/\/(.*?)\/|https:\/\/(.*?)\/|http:\/\/(.*?)\/|git@(.*):\/\/|ssh:\/\/git@(.*?)\/)(.*)$/;
|
||||||
@@ -19,7 +25,11 @@ export class RemoteProviderFactory {
|
|||||||
const domain = match[1] || match[2] || match[3] || match[4] || match[5];
|
const domain = match[1] || match[2] || match[3] || match[4] || match[5];
|
||||||
const path = match[6].replace(/\.git/, '');
|
const path = match[6].replace(/\.git/, '');
|
||||||
|
|
||||||
const creator = providerMap.get(domain);
|
const key = domain.toLowerCase().endsWith('visualstudio.com')
|
||||||
|
? 'visualstudio.com'
|
||||||
|
: domain;
|
||||||
|
|
||||||
|
const creator = providerMap.get(key.toLowerCase());
|
||||||
if (!creator) return undefined;
|
if (!creator) return undefined;
|
||||||
|
|
||||||
return creator(domain, path);
|
return creator(domain, path);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class GitHubService extends RemoteProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getUrlForBranch(branch: string): string {
|
protected getUrlForBranch(branch: string): string {
|
||||||
return `${this.baseUrl}/tree/${branch}`;
|
return `${this.baseUrl}/commits/${branch}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getUrlForCommit(sha: string): string {
|
protected getUrlForCommit(sha: string): string {
|
||||||
|
|||||||
13
src/git/remotes/gitlab.ts
Normal file
13
src/git/remotes/gitlab.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
'use strict';
|
||||||
|
import { GitHubService } from './github';
|
||||||
|
|
||||||
|
export class GitLabService extends GitHubService {
|
||||||
|
|
||||||
|
constructor(public domain: string, public path: string) {
|
||||||
|
super(domain, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return 'GitLab';
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/git/remotes/visualStudio.ts
Normal file
27
src/git/remotes/visualStudio.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
import { RemoteProvider } from './provider';
|
||||||
|
|
||||||
|
export class VisualStudioService extends RemoteProvider {
|
||||||
|
|
||||||
|
constructor(public domain: string, public path: string) {
|
||||||
|
super(domain, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return 'Visual Studio Team Services';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getUrlForBranch(branch: string): string {
|
||||||
|
return `${this.baseUrl}/?version=GB${branch}&_a=history`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getUrlForCommit(sha: string): string {
|
||||||
|
return `${this.baseUrl}/commit/${sha}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getUrlForFile(fileName: string, branch?: string, sha?: string): string {
|
||||||
|
if (sha) return `${this.baseUrl}/commit/${sha}/?_a=contents&path=%2F${fileName}`;
|
||||||
|
if (branch) return `${this.baseUrl}/?path=%2F${fileName}&version=GB${branch}&_a=contents`;
|
||||||
|
return `${this.baseUrl}?path=%2F${fileName}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user