mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 01:25:42 -05:00
Adds bitbucket server support
This commit is contained in:
47
src/git/remotes/bitbucket-server.ts
Normal file
47
src/git/remotes/bitbucket-server.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
import { Range } from 'vscode';
|
||||
import { RemoteProvider } from './provider';
|
||||
|
||||
export class BitbucketServerService extends RemoteProvider {
|
||||
|
||||
constructor(public domain: string, public path: string, public custom: boolean = false) {
|
||||
super(domain, path);
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.formatName('Bitbucket Server');
|
||||
}
|
||||
|
||||
protected get baseUrl() {
|
||||
const [project, repo] = super.splitPath();
|
||||
return `https://${this.domain}/projects/${project}/repos/${repo}`;
|
||||
}
|
||||
|
||||
protected getUrlForBranches(): string {
|
||||
return `${this.baseUrl}/branches`;
|
||||
}
|
||||
|
||||
protected getUrlForBranch(branch: string): string {
|
||||
return `${this.baseUrl}/commits?until=${branch}`;
|
||||
}
|
||||
|
||||
protected getUrlForCommit(sha: string): string {
|
||||
return `${this.baseUrl}/commits/${sha}`;
|
||||
}
|
||||
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
|
||||
let line = '';
|
||||
if (range) {
|
||||
if (range.start.line === range.end.line) {
|
||||
line = `#${range.start.line}`;
|
||||
}
|
||||
else {
|
||||
line = `#${range.start.line}-${range.end.line}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (sha) return `${this.baseUrl}/browse/${fileName}?at=${sha}${line}`;
|
||||
if (branch) return `${this.baseUrl}/browse/${fileName}?at=${branch}${line}`;
|
||||
return `${this.baseUrl}/browse/${fileName}${line}`;
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ import { RemoteProvider } from './provider';
|
||||
|
||||
export class BitbucketService extends RemoteProvider {
|
||||
|
||||
constructor(public domain: string, public path: string) {
|
||||
constructor(public domain: string, public path: string, public custom: boolean = false) {
|
||||
super(domain, path);
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'Bitbucket';
|
||||
return this.formatName('Bitbucket');
|
||||
}
|
||||
|
||||
protected getUrlForBranches(): string {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
import { ExtensionContext, workspace } from 'vscode';
|
||||
import { BitbucketService } from './bitbucket';
|
||||
import { BitbucketServerService } from './bitbucket-server';
|
||||
import { CustomRemoteType, IConfig, IRemotesConfig } from '../../configuration';
|
||||
import { ExtensionKey } from '../../constants';
|
||||
import { GitHubService } from './github';
|
||||
@@ -14,11 +15,12 @@ export { RemoteProvider };
|
||||
|
||||
const UrlRegex = /^(?:git:\/\/(.*?)\/|https:\/\/(.*?)\/|http:\/\/(.*?)\/|git@(.*):|ssh:\/\/(?:.*@)?(.*?)(?::.*?)?\/)(.*)$/;
|
||||
|
||||
function getProviderKey(type: CustomRemoteType) {
|
||||
function getCustomProvider(type: CustomRemoteType) {
|
||||
switch (type) {
|
||||
case CustomRemoteType.Bitbucket: return 'bitbucket.org';
|
||||
case CustomRemoteType.GitHub: return 'github.com';
|
||||
case CustomRemoteType.GitLab: return 'gitlab.com';
|
||||
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;
|
||||
}
|
||||
@@ -43,10 +45,10 @@ function onConfigurationChanged() {
|
||||
remotesCfg = cfg.remotes;
|
||||
if (remotesCfg != null && remotesCfg.length > 0) {
|
||||
for (const svc of remotesCfg) {
|
||||
const key = getProviderKey(svc.type);
|
||||
if (key === undefined) continue;
|
||||
const provider = getCustomProvider(svc.type);
|
||||
if (provider === undefined) continue;
|
||||
|
||||
providerMap.set(svc.domain.toLowerCase(), providerMap.get(key)!);
|
||||
providerMap.set(svc.domain.toLowerCase(), provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import { RemoteProvider } from './provider';
|
||||
|
||||
export class GitHubService extends RemoteProvider {
|
||||
|
||||
constructor(public domain: string, public path: string) {
|
||||
constructor(public domain: string, public path: string, public custom: boolean = false) {
|
||||
super(domain, path);
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'GitHub';
|
||||
return this.formatName('GitHub');
|
||||
}
|
||||
|
||||
protected getUrlForBranches(): string {
|
||||
|
||||
@@ -3,11 +3,11 @@ import { GitHubService } from './github';
|
||||
|
||||
export class GitLabService extends GitHubService {
|
||||
|
||||
constructor(public domain: string, public path: string) {
|
||||
constructor(public domain: string, public path: string, public custom: boolean = false) {
|
||||
super(domain, path);
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'GitLab';
|
||||
return this.formatName('GitLab');
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export function getNameFromRemoteResource(resource: RemoteResource) {
|
||||
|
||||
export abstract class RemoteProvider {
|
||||
|
||||
constructor(public domain: string, public path: string) { }
|
||||
constructor(public domain: string, public path: string, public custom: boolean = false) { }
|
||||
|
||||
abstract get name(): string;
|
||||
|
||||
@@ -34,6 +34,15 @@ export abstract class RemoteProvider {
|
||||
return `https://${this.domain}/${this.path}`;
|
||||
}
|
||||
|
||||
protected formatName(name: string) {
|
||||
return `${name}${this.custom ? ` (${this.domain})` : ''}`;
|
||||
}
|
||||
|
||||
protected splitPath(): [string, string] {
|
||||
const index = this.path.indexOf('/');
|
||||
return [ this.path.substring(0, index), this.path.substring(index + 1) ];
|
||||
}
|
||||
|
||||
protected abstract getUrlForBranches(): string;
|
||||
protected abstract getUrlForBranch(branch: string): string;
|
||||
protected abstract getUrlForCommit(sha: string): string;
|
||||
|
||||
Reference in New Issue
Block a user