Procházet zdrojové kódy

Renames to RichRemoteProvider

main
Eric Amodio před 4 roky
rodič
revize
1d788dcccc
12 změnil soubory, kde provedl 43 přidání a 42 odebrání
  1. +1
    -1
      src/annotations/lineAnnotationController.ts
  2. +2
    -2
      src/avatars.ts
  3. +1
    -1
      src/commands/openPullRequestOnRemote.ts
  4. +17
    -17
      src/git/gitService.ts
  5. +1
    -1
      src/git/models/commit.ts
  6. +2
    -4
      src/git/models/remote.ts
  7. +3
    -3
      src/git/models/repository.ts
  8. +2
    -2
      src/git/remotes/factory.ts
  9. +2
    -2
      src/git/remotes/github.ts
  10. +9
    -6
      src/git/remotes/provider.ts
  11. +2
    -2
      src/hovers/hovers.ts
  12. +1
    -1
      src/statusbar/statusBarController.ts

+ 1
- 1
src/annotations/lineAnnotationController.ts Zobrazit soubor

@ -152,7 +152,7 @@ export class LineAnnotationController implements Disposable {
) {
if (lines.length === 0) return undefined;
const remote = await Container.git.getRemoteWithApiProvider(repoPath);
const remote = await Container.git.getRichRemoteProvider(repoPath);
if (remote?.provider == null) return undefined;
const refs = new Set<string>();

+ 2
- 2
src/avatars.ts Zobrazit soubor

@ -180,11 +180,11 @@ async function getAvatarUriFromRemoteProvider(
try {
let account;
// if (typeof repoPathOrCommit === 'string') {
// const remote = await Container.git.getRemoteWithApiProvider(repoPathOrCommit);
// const remote = await Container.git.getRichRemoteProvider(repoPathOrCommit);
// account = await remote?.provider.getAccountForEmail(email, { avatarSize: size });
// } else {
if (typeof repoPathOrCommit !== 'string') {
const remote = await Container.git.getRemoteWithApiProvider(repoPathOrCommit.repoPath);
const remote = await Container.git.getRichRemoteProvider(repoPathOrCommit.repoPath);
account = await remote?.provider.getAccountForCommit(repoPathOrCommit.ref, { avatarSize: size });
}
if (account == null) {

+ 1
- 1
src/commands/openPullRequestOnRemote.ts Zobrazit soubor

@ -50,7 +50,7 @@ export class OpenPullRequestOnRemoteCommand extends Command {
if (args?.pr == null) {
if (args?.repoPath == null || args?.ref == null) return;
const remote = await Container.git.getRemoteWithApiProvider(args.repoPath);
const remote = await Container.git.getRichRemoteProvider(args.repoPath);
if (remote?.provider == null) return;
const pr = await Container.git.getPullRequestForCommit(args.ref, remote.provider);

+ 17
- 17
src/git/gitService.ts Zobrazit soubor

@ -76,7 +76,7 @@ import { GitUri } from './gitUri';
import { LogCorrelationContext, Logger } from '../logger';
import { Messages } from '../messages';
import { GitReflogParser, GitShortLogParser } from './parsers/parsers';
import { RemoteProvider, RemoteProviderFactory, RemoteProviders, RemoteProviderWithApi } from './remotes/factory';
import { RemoteProvider, RemoteProviderFactory, RemoteProviders, RichRemoteProvider } from './remotes/factory';
import { fsExists, isWindows } from './shell';
import {
Arrays,
@ -129,7 +129,7 @@ export class GitService implements Disposable {
private _repositoriesLoadingPromise: Promise<void> | undefined;
private readonly _branchesCache = new Map<string, GitBranch[]>();
private readonly _remotesWithApiProviderCache = new Map<string, GitRemote<RemoteProviderWithApi> | null>();
private readonly _remotesWithApiProviderCache = new Map<string, GitRemote<RichRemoteProvider> | null>();
private readonly _tagsCache = new Map<string, GitTag[]>();
private readonly _trackedCache = new Map<string, boolean | Promise<boolean>>();
private readonly _userMapCache = new Map<string, { name?: string; email?: string } | null>();
@ -2667,18 +2667,18 @@ export class GitService implements Disposable {
): Promise<PullRequest | undefined>;
async getPullRequestForBranch(
branch: string,
provider: RemoteProviderWithApi,
provider: RichRemoteProvider,
options?: { avatarSize?: number; include?: PullRequestState[]; limit?: number; timeout?: number },
): Promise<PullRequest | undefined>;
@gate()
@debug<GitService['getPullRequestForBranch']>({
args: {
1: (remoteOrProvider: GitRemote | RemoteProviderWithApi) => remoteOrProvider.name,
1: (remoteOrProvider: GitRemote | RichRemoteProvider) => remoteOrProvider.name,
},
})
async getPullRequestForBranch(
branch: string,
remoteOrProvider: GitRemote | RemoteProviderWithApi,
remoteOrProvider: GitRemote | RichRemoteProvider,
{
timeout,
...options
@ -2719,18 +2719,18 @@ export class GitService implements Disposable {
): Promise<PullRequest | undefined>;
async getPullRequestForCommit(
ref: string,
provider: RemoteProviderWithApi,
provider: RichRemoteProvider,
options?: { timeout?: number },
): Promise<PullRequest | undefined>;
@gate()
@debug({
args: {
1: (remoteOrProvider: GitRemote | RemoteProviderWithApi) => remoteOrProvider.name,
1: (remoteOrProvider: GitRemote | RichRemoteProvider) => remoteOrProvider.name,
},
})
async getPullRequestForCommit(
ref: string,
remoteOrProvider: GitRemote | RemoteProviderWithApi,
remoteOrProvider: GitRemote | RichRemoteProvider,
{ timeout }: { timeout?: number } = {},
): Promise<PullRequest | undefined> {
if (GitRevision.isUncommitted(ref)) return undefined;
@ -2819,25 +2819,25 @@ export class GitService implements Disposable {
};
}
async getRemoteWithApiProvider(
async getRichRemoteProvider(
repoPath: string | undefined,
options?: { includeDisconnected?: boolean },
): Promise<GitRemote<RemoteProviderWithApi> | undefined>;
async getRemoteWithApiProvider(
): Promise<GitRemote<RichRemoteProvider> | undefined>;
async getRichRemoteProvider(
remotes: GitRemote[],
options?: { includeDisconnected?: boolean },
): Promise<GitRemote<RemoteProviderWithApi> | undefined>;
@gate<GitService['getRemoteWithApiProvider']>(
): Promise<GitRemote<RichRemoteProvider> | undefined>;
@gate<GitService['getRichRemoteProvider']>(
(remotesOrRepoPath, options) =>
`${typeof remotesOrRepoPath === 'string' ? remotesOrRepoPath : remotesOrRepoPath[0]?.repoPath}:${
options?.includeDisconnected ?? false
}`,
)
@log({ args: { 0: () => false } })
async getRemoteWithApiProvider(
async getRichRemoteProvider(
remotesOrRepoPath: GitRemote[] | string | undefined,
{ includeDisconnected }: { includeDisconnected?: boolean } = {},
): Promise<GitRemote<RemoteProviderWithApi> | undefined> {
): Promise<GitRemote<RichRemoteProvider> | undefined> {
if (remotesOrRepoPath == null) return undefined;
const cacheKey = `${includeDisconnected ? 'disconnected|' : ''}${
@ -2891,9 +2891,9 @@ export class GitService implements Disposable {
}
if (cacheKey != null) {
this._remotesWithApiProviderCache.set(cacheKey, remote as GitRemote<RemoteProviderWithApi>);
this._remotesWithApiProviderCache.set(cacheKey, remote as GitRemote<RichRemoteProvider>);
}
return remote as GitRemote<RemoteProviderWithApi>;
return remote as GitRemote<RichRemoteProvider>;
}
@log()

+ 1
- 1
src/git/models/commit.ts Zobrazit soubor

@ -144,7 +144,7 @@ export abstract class GitCommit implements GitRevisionReference {
@memoize()
async getAssociatedPullRequest(): Promise<PullRequest | undefined> {
const remote = await Container.git.getRemoteWithApiProvider(this.repoPath);
const remote = await Container.git.getRichRemoteProvider(this.repoPath);
if (remote?.provider == null) return undefined;
return Container.git.getPullRequestForCommit(this.ref, remote);

+ 2
- 4
src/git/models/remote.ts Zobrazit soubor

@ -1,16 +1,14 @@
'use strict';
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { RemoteProvider, RemoteProviderWithApi } from '../remotes/factory';
import { RemoteProvider, RichRemoteProvider } from '../remotes/factory';
export enum GitRemoteType {
Fetch = 'fetch',
Push = 'push',
}
export class GitRemote<
TProvider extends RemoteProvider | undefined = RemoteProvider | RemoteProviderWithApi | undefined
> {
export class GitRemote<TProvider extends RemoteProvider | undefined = RemoteProvider | RichRemoteProvider | undefined> {
static getHighlanderProviders(remotes: GitRemote<RemoteProvider>[]) {
if (remotes.length === 0) return undefined;

+ 3
- 3
src/git/models/repository.ts Zobrazit soubor

@ -22,7 +22,7 @@ import { GitUri } from '../gitUri';
import { Logger } from '../../logger';
import { Messages } from '../../messages';
import { GitBranchReference, GitReference, GitTagReference } from './models';
import { RemoteProviderFactory, RemoteProviders, RemoteProviderWithApi } from '../remotes/factory';
import { RemoteProviderFactory, RemoteProviders, RichRemoteProvider } from '../remotes/factory';
import { Arrays, debug, Functions, gate, Iterables, log, logName } from '../../system';
import { runGitCommandInTerminal } from '../../terminal';
@ -463,7 +463,7 @@ export class Repository implements Disposable {
this._remotesDisposable = Disposable.from(
...Iterables.filterMap(await remotes, r => {
if (!(r.provider instanceof RemoteProviderWithApi)) return undefined;
if (!RichRemoteProvider.is(r.provider)) return undefined;
return r.provider.onDidChange(() => this.fireChange(RepositoryChange.Remotes));
}),
@ -492,7 +492,7 @@ export class Repository implements Disposable {
async hasConnectedRemotes(): Promise<boolean> {
const remotes = await this.getRemotes();
const remote = await Container.git.getRemoteWithApiProvider(remotes);
const remote = await Container.git.getRichRemoteProvider(remotes);
return remote?.provider != null;
}

+ 2
- 2
src/git/remotes/factory.ts Zobrazit soubor

@ -7,9 +7,9 @@ import { CustomRemote } from './custom';
import { GitHubRemote } from './github';
import { GitLabRemote } from './gitlab';
import { Logger } from '../../logger';
import { RemoteProvider, RemoteProviderWithApi } from './provider';
import { RemoteProvider, RichRemoteProvider } from './provider';
export { RemoteProvider, RemoteProviderWithApi };
export { RemoteProvider, RichRemoteProvider };
export type RemoteProviders = [string | RegExp, (domain: string, path: string) => RemoteProvider][];
const defaultProviders: RemoteProviders = [

+ 2
- 2
src/git/remotes/github.ts Zobrazit soubor

@ -5,7 +5,7 @@ import { AutolinkReference } from '../../config';
import { Container } from '../../container';
import { GitHubPullRequest } from '../../github/github';
import { Account, GitRevision, IssueOrPullRequest, PullRequest, PullRequestState, Repository } from '../models/models';
import { RemoteProviderWithApi } from './provider';
import { RichRemoteProvider } from './provider';
const issueEnricher3rdParyRegex = /\b(\w+\\?-?\w+(?!\\?-)\/\w+\\?-?\w+(?!\\?-))\\?#([0-9]+)\b/g;
const fileRegex = /^\/([^/]+)\/([^/]+?)\/blob(.+)$/i;
@ -13,7 +13,7 @@ const rangeRegex = /^L(\d+)(?:-L(\d+))?$/;
const authProvider = Object.freeze({ id: 'github', scopes: ['repo'] });
export class GitHubRemote extends RemoteProviderWithApi {
export class GitHubRemote extends RichRemoteProvider {
protected get authProvider() {
return authProvider;
}

+ 9
- 6
src/git/remotes/provider.ts Zobrazit soubor

@ -88,6 +88,7 @@ export function getNameFromRemoteResource(resource: RemoteResource) {
}
export abstract class RemoteProvider {
readonly type: 'simple' | 'rich' = 'simple';
protected _name: string | undefined;
constructor(
@ -135,8 +136,8 @@ export abstract class RemoteProvider {
}
}
hasApi(): this is RemoteProviderWithApi {
return RemoteProviderWithApi.is(this);
hasApi(): this is RichRemoteProvider {
return RichRemoteProvider.is(this);
}
abstract getLocalInfoFromRemoteUri(
@ -247,9 +248,11 @@ export class ClientError extends Error {
// TODO@eamodio revisit how once authenticated, all remotes are always connected, even after a restart
export abstract class RemoteProviderWithApi extends RemoteProvider {
static is(provider: RemoteProvider | undefined): provider is RemoteProviderWithApi {
return provider instanceof RemoteProviderWithApi;
export abstract class RichRemoteProvider extends RemoteProvider {
readonly type: 'simple' | 'rich' = 'rich';
static is(provider: RemoteProvider | undefined): provider is RichRemoteProvider {
return provider?.type === 'rich';
}
private readonly _onDidChange = new EventEmitter<void>();
@ -337,7 +340,7 @@ export abstract class RemoteProviderWithApi extends RemoteProvider {
}
@gate()
@debug<RemoteProviderWithApi['isConnected']>({
@debug<RichRemoteProvider['isConnected']>({
exit: connected => `returned ${connected}`,
})
async isConnected(): Promise<boolean> {

+ 2
- 2
src/hovers/hovers.ts Zobrazit soubor

@ -243,7 +243,7 @@ export namespace Hovers {
return undefined;
}
const remote = await Container.git.getRemoteWithApiProvider(remotes);
const remote = await Container.git.getRichRemoteProvider(remotes);
if (remote?.provider == null) {
Logger.debug(cc, `completed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);
@ -322,7 +322,7 @@ export namespace Hovers {
return undefined;
}
const remote = await Container.git.getRemoteWithApiProvider(remotes, { includeDisconnected: true });
const remote = await Container.git.getRichRemoteProvider(remotes, { includeDisconnected: true });
if (remote?.provider == null) {
Logger.debug(cc, `completed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);

+ 1
- 1
src/statusbar/statusBarController.ts Zobrazit soubor

@ -217,7 +217,7 @@ export class StatusBarController implements Disposable {
}
private async getPullRequest(commit: GitBlameCommit, { timeout }: { timeout?: number } = {}) {
const remote = await Container.git.getRemoteWithApiProvider(commit.repoPath);
const remote = await Container.git.getRichRemoteProvider(commit.repoPath);
if (remote?.provider == null) return undefined;
const { provider } = remote;

Načítá se…
Zrušit
Uložit