From 1d36b809ca8346148400f14d4a3d19c52f8c7f11 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 30 Sep 2018 00:41:15 -0400 Subject: [PATCH] Closes #501 - Adds support for Azure DevOps --- src/git/remotes/azure-devops.ts | 55 +++++++++++++++++++++++++++++++++++++ src/git/remotes/bitbucket-server.ts | 2 +- src/git/remotes/bitbucket.ts | 2 +- src/git/remotes/custom.ts | 2 +- src/git/remotes/factory.ts | 31 +++++++++++---------- src/git/remotes/github.ts | 2 +- src/git/remotes/gitlab.ts | 2 +- src/git/remotes/visualStudio.ts | 55 ------------------------------------- 8 files changed, 76 insertions(+), 75 deletions(-) create mode 100644 src/git/remotes/azure-devops.ts delete mode 100644 src/git/remotes/visualStudio.ts diff --git a/src/git/remotes/azure-devops.ts b/src/git/remotes/azure-devops.ts new file mode 100644 index 0000000..e3bba0d --- /dev/null +++ b/src/git/remotes/azure-devops.ts @@ -0,0 +1,55 @@ +'use strict'; +import { Range } from 'vscode'; +import { RemoteProvider } from './provider'; + +const issueEnricherRegEx = /(^|\s)(#([0-9]+))\b/gi; +const stripGitRegex = /\/_git\/?/i; + +export class AzureDevOpsRemote extends RemoteProvider { + constructor(domain: string, path: string, protocol?: string, name?: string) { + super(domain, path, protocol, name); + } + + get icon() { + return 'vsts'; + } + + get name() { + return 'Azure DevOps'; + } + + enrichMessage(message: string): string { + // Strip off any `_git` part from the repo url + const baseUrl = this.baseUrl.replace(stripGitRegex, '/'); + // Matches #123 + return message.replace(issueEnricherRegEx, `$1[$2](${baseUrl}/_workitems/edit/$3 "Open Work Item $2")`); + } + + protected getUrlForBranches(): string { + return `${this.baseUrl}/branches`; + } + + 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, range?: Range): string { + let line = ''; + if (range) { + if (range.start.line === range.end.line) { + line = `&line=${range.start.line}`; + } + else { + line = `&line=${range.start.line}&lineEnd=${range.end.line}`; + } + } + + if (sha) return `${this.baseUrl}/commit/${sha}/?_a=contents&path=%2F${fileName}${line}`; + if (branch) return `${this.baseUrl}/?path=%2F${fileName}&version=GB${branch}&_a=contents${line}`; + return `${this.baseUrl}?path=%2F${fileName}${line}`; + } +} diff --git a/src/git/remotes/bitbucket-server.ts b/src/git/remotes/bitbucket-server.ts index 7e159e1..8a72a12 100644 --- a/src/git/remotes/bitbucket-server.ts +++ b/src/git/remotes/bitbucket-server.ts @@ -5,7 +5,7 @@ import { RemoteProvider } from './provider'; const issueEnricherRegEx = /(^|\s)(issue #([0-9]+))\b/gi; const prEnricherRegEx = /(^|\s)(pull request #([0-9]+))\b/gi; -export class BitbucketServerService extends RemoteProvider { +export class BitbucketServerRemote extends RemoteProvider { constructor(domain: string, path: string, protocol?: string, name?: string, custom: boolean = false) { super(domain, path, protocol, name, custom); } diff --git a/src/git/remotes/bitbucket.ts b/src/git/remotes/bitbucket.ts index 5fef642..bb18dca 100644 --- a/src/git/remotes/bitbucket.ts +++ b/src/git/remotes/bitbucket.ts @@ -5,7 +5,7 @@ import { RemoteProvider } from './provider'; const issueEnricherRegEx = /(^|\s)(issue #([0-9]+))\b/gi; const prEnricherRegEx = /(^|\s)(pull request #([0-9]+))\b/gi; -export class BitbucketService extends RemoteProvider { +export class BitbucketRemote extends RemoteProvider { constructor(domain: string, path: string, protocol?: string, name?: string, custom: boolean = false) { super(domain, path, protocol, name, custom); } diff --git a/src/git/remotes/custom.ts b/src/git/remotes/custom.ts index 02781ba..ab915e1 100644 --- a/src/git/remotes/custom.ts +++ b/src/git/remotes/custom.ts @@ -4,7 +4,7 @@ import { RemotesUrlsConfig } from '../../configuration'; import { Strings } from '../../system'; import { RemoteProvider } from './provider'; -export class CustomService extends RemoteProvider { +export class CustomRemote extends RemoteProvider { private readonly urls: RemotesUrlsConfig; constructor(domain: string, path: string, urls: RemotesUrlsConfig, protocol?: string, name?: string) { diff --git a/src/git/remotes/factory.ts b/src/git/remotes/factory.ts index d830f50..883ba73 100644 --- a/src/git/remotes/factory.ts +++ b/src/git/remotes/factory.ts @@ -1,21 +1,22 @@ 'use strict'; import { CustomRemoteType, RemotesConfig } from '../../configuration'; import { Logger } from '../../logger'; -import { BitbucketService } from './bitbucket'; -import { BitbucketServerService } from './bitbucket-server'; -import { CustomService } from './custom'; -import { GitHubService } from './github'; -import { GitLabService } from './gitlab'; +import { AzureDevOpsRemote } from './azure-devops'; +import { BitbucketRemote } from './bitbucket'; +import { BitbucketServerRemote } from './bitbucket-server'; +import { CustomRemote } from './custom'; +import { GitHubRemote } from './github'; +import { GitLabRemote } from './gitlab'; import { RemoteProvider } from './provider'; -import { VisualStudioService } from './visualStudio'; export { RemoteProvider }; const defaultProviderMap = new Map 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)] + ['bitbucket.org', (domain: string, path: string) => new BitbucketRemote(domain, path)], + ['github.com', (domain: string, path: string) => new GitHubRemote(domain, path)], + ['gitlab.com', (domain: string, path: string) => new GitLabRemote(domain, path)], + ['visualstudio.com', (domain: string, path: string) => new AzureDevOpsRemote(domain, path)], + ['dev.azure.com', (domain: string, path: string) => new AzureDevOpsRemote(domain, path)] ]); export type RemoteProviderMap = Map RemoteProvider>; @@ -60,17 +61,17 @@ export class RemoteProviderFactory { switch (cfg.type) { case CustomRemoteType.Bitbucket: return (domain: string, path: string) => - new BitbucketService(domain, path, cfg.protocol, cfg.name, true); + new BitbucketRemote(domain, path, cfg.protocol, cfg.name, true); case CustomRemoteType.BitbucketServer: return (domain: string, path: string) => - new BitbucketServerService(domain, path, cfg.protocol, cfg.name, true); + new BitbucketServerRemote(domain, path, cfg.protocol, cfg.name, true); case CustomRemoteType.Custom: return (domain: string, path: string) => - new CustomService(domain, path, cfg.urls!, cfg.protocol, cfg.name); + new CustomRemote(domain, path, cfg.urls!, cfg.protocol, cfg.name); case CustomRemoteType.GitHub: - return (domain: string, path: string) => new GitHubService(domain, path, cfg.protocol, cfg.name, true); + return (domain: string, path: string) => new GitHubRemote(domain, path, cfg.protocol, cfg.name, true); case CustomRemoteType.GitLab: - return (domain: string, path: string) => new GitLabService(domain, path, cfg.protocol, cfg.name, true); + return (domain: string, path: string) => new GitLabRemote(domain, path, cfg.protocol, cfg.name, true); } return undefined; } diff --git a/src/git/remotes/github.ts b/src/git/remotes/github.ts index 4bf00fd..1673f2b 100644 --- a/src/git/remotes/github.ts +++ b/src/git/remotes/github.ts @@ -5,7 +5,7 @@ import { RemoteProvider } from './provider'; const issueEnricherRegEx = /(^|\s)((?:#|gh-)([0-9]+))\b/gi; const issueEnricher3rdParyRegEx = /\b((\w+-?\w+(?!-)\/\w+-?\w+(?!-))#([0-9]+))\b/g; -export class GitHubService extends RemoteProvider { +export class GitHubRemote extends RemoteProvider { constructor(domain: string, path: string, protocol?: string, name?: string, custom: boolean = false) { super(domain, path, protocol, name, custom); } diff --git a/src/git/remotes/gitlab.ts b/src/git/remotes/gitlab.ts index dc6658e..e424bfd 100644 --- a/src/git/remotes/gitlab.ts +++ b/src/git/remotes/gitlab.ts @@ -4,7 +4,7 @@ import { RemoteProvider } from './provider'; const issueEnricherRegEx = /(^|\s)(#([0-9]+))\b/gi; -export class GitLabService extends RemoteProvider { +export class GitLabRemote extends RemoteProvider { constructor(domain: string, path: string, protocol?: string, name?: string, custom: boolean = false) { super(domain, path, protocol, name, custom); } diff --git a/src/git/remotes/visualStudio.ts b/src/git/remotes/visualStudio.ts deleted file mode 100644 index 60fe7b6..0000000 --- a/src/git/remotes/visualStudio.ts +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; -import { Range } from 'vscode'; -import { RemoteProvider } from './provider'; - -const issueEnricherRegEx = /(^|\s)(#([0-9]+))\b/gi; -const stripGitRegex = /\/_git\/?/i; - -export class VisualStudioService extends RemoteProvider { - constructor(domain: string, path: string, protocol?: string, name?: string) { - super(domain, path, protocol, name); - } - - get icon() { - return 'vsts'; - } - - get name() { - return 'Visual Studio Team Services'; - } - - enrichMessage(message: string): string { - // Strip off any `_git` part from the repo url - const baseUrl = this.baseUrl.replace(stripGitRegex, '/'); - // Matches #123 - return message.replace(issueEnricherRegEx, `$1[$2](${baseUrl}/_workitems/edit/$3 "Open Work Item $2")`); - } - - protected getUrlForBranches(): string { - return `${this.baseUrl}/branches`; - } - - 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, range?: Range): string { - let line = ''; - if (range) { - if (range.start.line === range.end.line) { - line = `&line=${range.start.line}`; - } - else { - line = `&line=${range.start.line}&lineEnd=${range.end.line}`; - } - } - - if (sha) return `${this.baseUrl}/commit/${sha}/?_a=contents&path=%2F${fileName}${line}`; - if (branch) return `${this.baseUrl}/?path=%2F${fileName}&version=GB${branch}&_a=contents${line}`; - return `${this.baseUrl}?path=%2F${fileName}${line}`; - } -}