Browse Source

Closes #1336 - avoids auth prompts

main
Eric Amodio 3 years ago
parent
commit
fec2466436
7 changed files with 16 additions and 109 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -10
      package.json
  3. +0
    -1
      src/commands.ts
  4. +0
    -1
      src/commands/common.ts
  5. +0
    -17
      src/commands/resetRemoteConnectionAuthorization.ts
  6. +3
    -2
      src/constants.ts
  7. +11
    -78
      src/git/remotes/provider.ts

+ 1
- 0
CHANGELOG.md View File

@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [1336](https://github.com/eamodio/vscode-gitlens/issues/1336) - Need to allow GitLens to connect to GitHub in every Codespace (requires VS Code v1.54-insiders or later)
- Fixes [1363](https://github.com/eamodio/vscode-gitlens/issues/1363) - Error 'Unable to open compare', when git setting log.showsignature is active
- Fixes [1368](https://github.com/eamodio/vscode-gitlens/issues/1368) - Suppress message "GitLens was unable to find Git"
- Fixes typo in README — thanks to [PR #1374](https://github.com/eamodio/vscode-gitlens/pull/1374) by David Rees ([@studgeek](https://github.com/studgeek))

+ 1
- 10
package.json View File

@ -18,7 +18,7 @@
"url": "https://github.com/eamodio/vscode-gitlens.git"
},
"engines": {
"vscode": "^1.53.0"
"vscode": "^1.54.0-insiders"
},
"main": "./dist/gitlens",
"icon": "images/gitlens-icon.png",
@ -3357,11 +3357,6 @@
}
},
{
"command": "gitlens.resetRemoteConnectionAuthorization",
"title": "Reset Remote Connection Authorization",
"category": "GitLens"
},
{
"command": "gitlens.copyCurrentBranch",
"title": "Copy Current Branch Name",
"category": "GitLens",
@ -5218,10 +5213,6 @@
"when": "config.gitlens.integrations.enabled && gitlens:hasRichRemotes && gitlens:hasConnectedRemotes"
},
{
"command": "gitlens.resetRemoteConnectionAuthorization",
"when": "config.gitlens.integrations.enabled && gitlens:hasRichRemotes"
},
{
"command": "gitlens.copyCurrentBranch",
"when": "gitlens:enabled"
},

+ 0
- 1
src/commands.ts View File

@ -40,7 +40,6 @@ export * from './commands/rebaseEditor';
export * from './commands/refreshHover';
export * from './commands/remoteProviders';
export * from './commands/repositories';
export * from './commands/resetRemoteConnectionAuthorization';
export * from './commands/resetSuppressedWarnings';
export * from './commands/setViewsLayout';
export * from './commands/searchCommits';

+ 0
- 1
src/commands/common.ts View File

@ -101,7 +101,6 @@ export enum Commands {
GitCommands = 'gitlens.gitCommands',
QuickOpenFileHistory = 'gitlens.quickOpenFileHistory',
RefreshHover = 'gitlens.refreshHover',
ResetRemoteConnectionAuthorization = 'gitlens.resetRemoteConnectionAuthorization',
ResetSuppressedWarnings = 'gitlens.resetSuppressedWarnings',
RevealCommitInView = 'gitlens.revealCommitInView',
SearchCommits = 'gitlens.showCommitSearch',

+ 0
- 17
src/commands/resetRemoteConnectionAuthorization.ts View File

@ -1,17 +0,0 @@
'use strict';
import { Container } from '../container';
import { command, Command, Commands } from './common';
@command()
export class ResetRemoteConnectionAuthorizationCommand extends Command {
constructor() {
super(Commands.ResetRemoteConnectionAuthorization);
}
async execute() {
for (const repo of await Container.git.getRepositories()) {
const remote = await Container.git.getRichRemoteProvider(repo.path, { includeDisconnected: true });
await remote?.provider?.resetRemoteConnectionAuthorization();
}
}
}

+ 3
- 2
src/constants.ts View File

@ -150,10 +150,11 @@ export enum GlyphChars {
}
export enum SyncedState {
DisallowConnectionPrefix = 'gitlens:disallow:connection:',
UpdatesViewVisible = 'gitlens:views:updates:visible',
Version = 'gitlens:synced:version',
WelcomeViewVisible = 'gitlens:views:welcome:visible',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
}
export enum GlobalState {
@ -235,7 +236,6 @@ export enum WorkspaceState {
BranchComparisons = 'gitlens:branch:comparisons',
ConnectedPrefix = 'gitlens:connected:',
DefaultRemote = 'gitlens:remote:default',
DisallowConnectionPrefix = 'gitlens:disallow:connection:',
GitCommandPaletteUsage = 'gitlens:gitComandPalette:usage',
StarredBranches = 'gitlens:starred:branches',
StarredRepositories = 'gitlens:starred:repositories',
@ -243,5 +243,6 @@ export enum WorkspaceState {
ViewsSearchAndCompareKeepResults = 'gitlens:views:searchAndCompare:keepResults',
ViewsSearchAndComparePinnedItems = 'gitlens:views:searchAndCompare:pinned',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
Deprecated_PinnedComparisons = 'gitlens:pinned:comparisons',
}

+ 11
- 78
src/git/remotes/provider.ts View File

@ -6,16 +6,13 @@ import {
env,
Event,
EventEmitter,
MessageItem,
Range,
Uri,
window,
} from 'vscode';
import { DynamicAutolinkReference } from '../../annotations/autolinks';
import { AutolinkReference } from '../../config';
import { SyncedState, WorkspaceState } from '../../constants';
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { setKeysForSync } from '../../extension';
import { Logger } from '../../logger';
import {
Account,
@ -286,14 +283,6 @@ export abstract class RichRemoteProvider extends RemoteProvider {
return `${WorkspaceState.ConnectedPrefix}${this.key}`;
}
private get disallowSyncedGlobalConnectionKey() {
return `${SyncedState.DisallowConnectionPrefix}${this.key}`;
}
private get disallowWorkspaceConnectionKey() {
return `${WorkspaceState.DisallowConnectionPrefix}${this.key}`;
}
get maybeConnected(): boolean | undefined {
if (this._session === undefined) return undefined;
@ -310,7 +299,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
private onAuthenticationSessionsChanged(e: AuthenticationSessionsChangeEvent) {
if (e.provider.id === this.authProvider.id) {
this.disconnect();
void this.ensureSession(false);
}
}
@ -333,8 +322,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
this._session = null;
if (disconnected) {
void Container.context.workspaceState.update(this.connectedKey, undefined);
void Container.context.workspaceState.update(this.disallowWorkspaceConnectionKey, true);
void Container.context.workspaceState.update(this.connectedKey, false);
this._onDidChange.fire();
if (!silent) {
@ -343,15 +331,6 @@ export abstract class RichRemoteProvider extends RemoteProvider {
}
}
@log()
async resetRemoteConnectionAuthorization() {
await Promise.all([
Container.context.workspaceState.update(this.connectedKey, undefined),
Container.context.workspaceState.update(this.disallowWorkspaceConnectionKey, undefined),
Container.context.globalState.update(this.disallowSyncedGlobalConnectionKey, undefined),
]);
}
@gate()
@debug<RichRemoteProvider['isConnected']>({
exit: connected => `returned ${connected}`,
@ -544,15 +523,8 @@ export abstract class RichRemoteProvider extends RemoteProvider {
if (!Container.config.integrations.enabled) return undefined;
if (createIfNeeded) {
await Promise.all([
Container.context.workspaceState.update(this.connectedKey, undefined),
Container.context.workspaceState.update(this.disallowWorkspaceConnectionKey, undefined),
]);
} else if (
!Container.context.workspaceState.get<boolean>(this.connectedKey) &&
(Container.context.globalState.get<boolean>(this.disallowSyncedGlobalConnectionKey) ||
Container.context.workspaceState.get<boolean>(this.disallowWorkspaceConnectionKey))
) {
await Container.context.workspaceState.update(this.connectedKey, undefined);
} else if (Container.context.workspaceState.get<boolean>(this.connectedKey) === false) {
return undefined;
}
@ -562,15 +534,9 @@ export abstract class RichRemoteProvider extends RemoteProvider {
createIfNone: createIfNeeded,
});
} catch (ex) {
await Promise.all([
Container.context.workspaceState.update(this.connectedKey, undefined),
Container.context.workspaceState.update(this.disallowWorkspaceConnectionKey, true),
]);
await Container.context.workspaceState.update(this.connectedKey, undefined);
if (ex instanceof Error && ex.message.includes('User did not consent')) {
if (!createIfNeeded) {
void this.promptToAllow(true);
}
return undefined;
}
@ -578,55 +544,22 @@ export abstract class RichRemoteProvider extends RemoteProvider {
}
if (session === undefined && !createIfNeeded) {
await Promise.all([
Container.context.workspaceState.update(this.connectedKey, undefined),
Container.context.workspaceState.update(this.disallowWorkspaceConnectionKey, true),
]);
void this.promptToAllow();
await Container.context.workspaceState.update(this.connectedKey, undefined);
}
this._session = session ?? null;
this.invalidClientExceptionCount = 0;
if (session != null) {
await Promise.all([
Container.context.workspaceState.update(this.connectedKey, true),
Container.context.workspaceState.update(this.disallowWorkspaceConnectionKey, undefined),
]);
if (createIfNeeded) {
this._onDidChange.fire();
_onDidChangeAuthentication.fire({ reason: 'connected', key: this.key });
}
await Container.context.workspaceState.update(this.connectedKey, true);
this._onDidChange.fire();
_onDidChangeAuthentication.fire({ reason: 'connected', key: this.key });
}
return session ?? undefined;
}
@gate()
private async promptToAllow(retry: boolean = false) {
const allow: MessageItem = { title: 'Allow' };
const deny: MessageItem = { title: 'Deny' };
const denyEverywhere: MessageItem = { title: 'Deny Everywhere' };
const result = await window.showInformationMessage(
retry
? `By allowing GitLens to connect to ${this.name}, it can provide a rich integration with pull requests, issues, avatars, and more.\n\nIf you choose 'Allow', you will again be prompted to authenticate with ${this.name}.`
: `Allow GitLens to connect to ${this.name} to provide a rich integration with pull requests, issues, avatars, and more.\n\nIf you choose 'Allow', you will be prompted to authenticate with ${this.name}.`,
allow,
deny,
denyEverywhere,
);
if (result === allow) {
void this.connect();
} else if (result === denyEverywhere) {
setKeysForSync(this.disallowSyncedGlobalConnectionKey);
await Container.context.globalState.update(this.disallowSyncedGlobalConnectionKey, true);
}
}
@debug()
private handleClientException() {
this.invalidClientExceptionCount++;

Loading…
Cancel
Save