Ver a proveniência

Fixes #120 - Adds custom remotes support

main
Eric Amodio há 7 anos
ascendente
cometimento
92b57580b8
4 ficheiros alterados com 96 adições e 7 eliminações
  1. +28
    -0
      package.json
  2. +21
    -2
      src/configuration.ts
  3. +2
    -0
      src/extension.ts
  4. +45
    -5
      src/git/remotes/factory.ts

+ 28
- 0
package.json Ver ficheiro

@ -447,6 +447,34 @@
],
"description": "Specifies the starting view (mode) of the `GitLens` custom view\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer"
},
"gitlens.remotes": {
"type": "array",
"default": null,
"items": {
"type": "object",
"required": [
"type",
"domain"
],
"properties": {
"type": {
"type": "string",
"enum": [
"Bitbucket",
"GitHub",
"GitLab"
],
"description": "Specifies the type of the custom remote service\n `Bitbucket`, `GitHub`, or `GitLab`"
},
"domain": {
"type": "string",
"description": "Specifies the domain name of the custom remote service"
}
}
},
"uniqueItems": true,
"description": "Specifies the custom remote services (code-hosting)"
},
"gitlens.statusBar.enabled": {
"type": "boolean",
"default": true,

+ 21
- 2
src/configuration.ts Ver ficheiro

@ -7,7 +7,8 @@ import { OutputLevel } from './logger';
export { ExtensionKey } from './constants';
export type CodeLensCommand = 'gitlens.toggleFileBlame' |
export type CodeLensCommand =
'gitlens.toggleFileBlame' |
'gitlens.showBlameHistory' |
'gitlens.showFileHistory' |
'gitlens.diffWithPrevious' |
@ -41,7 +42,18 @@ export const LineHighlightLocations = {
OverviewRuler: 'overviewRuler' as LineHighlightLocations
};
export type StatusBarCommand = 'gitlens.toggleFileBlame' |
export type CustomRemoteType =
'Bitbucket' |
'GitHub' |
'GitLab';
export const CustomRemoteType = {
Bitbucket: 'Bitbucket' as CustomRemoteType,
GitHub: 'GitHub' as CustomRemoteType,
GitLab: 'GitLab' as CustomRemoteType
};
export type StatusBarCommand =
'gitlens.toggleFileBlame' |
'gitlens.showBlameHistory' |
'gitlens.showFileHistory' |
'gitlens.toggleCodeLens' |
@ -119,6 +131,11 @@ export interface ICodeLensLanguageLocation {
customSymbols?: string[];
}
export interface IRemotesConfig {
type: CustomRemoteType;
domain: string;
}
export interface IThemeConfig {
annotations: {
file: {
@ -307,6 +324,8 @@ export interface IConfig {
// dateFormat: string | null;
};
remotes: IRemotesConfig[];
statusBar: {
enabled: boolean;
alignment: 'left' | 'right';

+ 2
- 0
src/extension.ts Ver ficheiro

@ -19,6 +19,7 @@ import { CodeLensLocations, IConfig, LineHighlightLocations } from './configurat
import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensionId, setCommandContext, WorkspaceState } from './constants';
import { CodeLensController } from './codeLensController';
import { CurrentLineController, LineAnnotationType } from './currentLineController';
import { RemoteProviderFactory } from './git/remotes/factory';
import { GitContentProvider } from './gitContentProvider';
import { GitExplorer } from './views/gitExplorer';
import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
@ -33,6 +34,7 @@ export async function activate(context: ExtensionContext) {
Logger.configure(context);
Messages.configure(context);
Telemetry.configure(ApplicationInsightsKey);
RemoteProviderFactory.configure(context);
const gitlens = extensions.getExtension(QualifiedExtensionId)!;
const gitlensVersion = gitlens.packageJSON.version;

+ 45
- 5
src/git/remotes/factory.ts Ver ficheiro

@ -1,24 +1,64 @@
'use strict';
import { RemoteProvider } from './provider';
import { ExtensionContext, workspace } from 'vscode';
import { BitbucketService } from './bitbucket';
import { CustomRemoteType, IConfig, IRemotesConfig } from '../../configuration';
import { ExtensionKey } from '../../constants';
import { GitHubService } from './github';
import { GitLabService } from './gitlab';
import { VisualStudioService } from './visualStudio';
import { Logger } from '../../logger';
import { RemoteProvider } from './provider';
import { VisualStudioService } from './visualStudio';
import { Objects } from '../../system';
export { RemoteProvider };
const providerMap = new Map<string, (domain: string, path: string) => RemoteProvider>([
const UrlRegex = /^(?:git:\/\/(.*?)\/|https:\/\/(.*?)\/|http:\/\/(.*?)\/|git@(.*):|ssh:\/\/(?:.*@)?(.*?)(?::.*?)?\/)(.*)$/;
function getProviderKey(type: CustomRemoteType) {
switch (type) {
case CustomRemoteType.Bitbucket: return 'bitbucket.org';
case CustomRemoteType.GitHub: return 'github.com';
case CustomRemoteType.GitLab: return 'gitlab.com';
}
return undefined;
}
const defaultProviderMap = new Map<string, (domain: string, path: string) => RemoteProvider>([
['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:\/\/(?:.*@)?(.*?)(?::.*?)?\/)(.*)$/;
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);
remotesCfg = cfg.remotes;
if (remotesCfg != null && remotesCfg.length > 0) {
for (const svc of remotesCfg) {
const key = getProviderKey(svc.type);
if (key === undefined) continue;
providerMap.set(svc.domain.toLowerCase(), providerMap.get(key)!);
}
}
}
}
export class RemoteProviderFactory {
static configure(context: ExtensionContext) {
context.subscriptions.push(workspace.onDidChangeConfiguration(onConfigurationChanged));
onConfigurationChanged();
}
static getRemoteProvider(url: string): RemoteProvider | undefined {
try {
const match = UrlRegex.exec(url);
@ -32,7 +72,7 @@ export class RemoteProviderFactory {
: domain;
const creator = providerMap.get(key.toLowerCase());
if (!creator) return undefined;
if (creator === undefined) return undefined;
return creator(domain, path);
}

Carregando…
Cancelar
Guardar