Uses current branch when opening remote file

Adds current branch name to quick pick description
This commit is contained in:
Eric Amodio
2017-03-24 13:32:32 -04:00
parent e906bfcb9e
commit e859f697ec
7 changed files with 60 additions and 45 deletions

View File

@@ -19,8 +19,9 @@ export class GitHubService extends RemoteProvider {
return `${this.baseUrl}/commit/${sha}`;
}
protected getUrlForFile(fileName: string, sha?: string): string {
protected getUrlForFile(fileName: string, branch?: string, sha?: string): string {
if (sha) return `${this.baseUrl}/blob/${sha}/${fileName}`;
if (branch) return `${this.baseUrl}/blob/${branch}/${fileName}`;
return `${this.baseUrl}?path=${fileName}`;
}
}

View File

@@ -2,7 +2,7 @@
import { commands, Uri } from 'vscode';
import { BuiltInCommands } from '../../constants';
export type RemoteProviderOpenType = 'branch' | 'commit' | 'file';
export type RemoteOpenType = 'branch' | 'commit' | 'file' | 'working-file';
export abstract class RemoteProvider {
@@ -16,7 +16,7 @@ export abstract class RemoteProvider {
protected abstract getUrlForBranch(branch: string): string;
protected abstract getUrlForCommit(sha: string): string;
protected abstract getUrlForFile(fileName: string, sha?: string): string;
protected abstract getUrlForFile(fileName: string, branch: string, sha?: string): string;
private async _openUrl(url: string): Promise<{}> {
return url && commands.executeCommand(BuiltInCommands.Open, Uri.parse(url));
@@ -24,13 +24,17 @@ export abstract class RemoteProvider {
open(type: 'branch', branch: string): Promise<{}>;
open(type: 'commit', sha: string): Promise<{}>;
open(type: 'file', fileName: string, sha?: string): Promise<{}>;
open(type: RemoteProviderOpenType, ...args: string[]): Promise<{}>;
open(type: RemoteProviderOpenType, branchOrShaOrFileName: string, sha?: string): Promise<{}> {
open(type: 'file', fileName: string, branch?: string, sha?: string): Promise<{}>;
open(type: RemoteOpenType, ...args: string[]): Promise<{}>;
open(type: RemoteOpenType, branchOrShaOrFileName: string, fileBranch?: string, fileSha?: string): Promise<{}> {
switch (type) {
case 'branch': return this.openBranch(branchOrShaOrFileName);
case 'commit': return this.openCommit(branchOrShaOrFileName);
case 'file': return this.openFile(branchOrShaOrFileName, sha);
case 'branch':
return this.openBranch(branchOrShaOrFileName);
case 'commit':
return this.openCommit(branchOrShaOrFileName);
case 'file':
case 'working-file':
return this.openFile(branchOrShaOrFileName, fileBranch, fileSha);
}
}
@@ -42,7 +46,7 @@ export abstract class RemoteProvider {
return this._openUrl(this.getUrlForCommit(sha));
}
openFile(fileName: string, sha?: string) {
return this._openUrl(this.getUrlForFile(fileName, sha));
openFile(fileName: string, branch?: string, sha?: string) {
return this._openUrl(this.getUrlForFile(fileName, branch, sha));
}
}