Skip to content

Commit 7667cdd

Browse files
authored
GitHub - add setting to disable avatar resolution (#238270)
1 parent 4b4cd6b commit 7667cdd

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

extensions/github/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@
195195
],
196196
"default": "https",
197197
"description": "%config.gitProtocol%"
198+
},
199+
"github.showAvatar": {
200+
"type": "boolean",
201+
"scope": "resource",
202+
"default": true,
203+
"description": "%config.showAvatar%"
198204
}
199205
}
200206
}

extensions/github/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"config.branchProtection": "Controls whether to query repository rules for GitHub repositories",
99
"config.gitAuthentication": "Controls whether to enable automatic GitHub authentication for git commands within VS Code.",
1010
"config.gitProtocol": "Controls which protocol is used to clone a GitHub repository",
11+
"config.showAvatar": "Controls whether to show the GitHub avatar of the commit author in various hovers (ex: Git blame, Timeline, Source Control Graph, etc.)",
1112
"welcome.publishFolder": {
1213
"message": "You can directly publish this folder to a GitHub repository. Once published, you'll have access to source control features powered by Git and GitHub.\n[$(github) Publish to GitHub](command:github.publish)",
1314
"comment": [

extensions/github/src/historyItemDetailsProvider.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { authentication, Command, l10n, LogOutputChannel } from 'vscode';
6+
import { authentication, Command, l10n, LogOutputChannel, workspace } from 'vscode';
77
import { Commit, Repository as GitHubRepository, Maybe } from '@octokit/graphql-schema';
88
import { API, AvatarQuery, AvatarQueryCommit, Repository, SourceControlHistoryItemDetailsProvider } from './typings/git';
99
import { DisposableStore, getRepositoryDefaultRemote, getRepositoryDefaultRemoteUrl, getRepositoryFromUrl, groupBy, sequentialize } from './util';
@@ -78,7 +78,7 @@ function compareAvatarQuery(a: AvatarQueryCommit, b: AvatarQueryCommit): number
7878
}
7979

8080
export class GitHubSourceControlHistoryItemDetailsProvider implements SourceControlHistoryItemDetailsProvider {
81-
private _enabled = true;
81+
private _isUserAuthenticated = true;
8282
private readonly _store = new Map<string, GitHubRepositoryStore>();
8383
private readonly _disposables = new DisposableStore();
8484

@@ -87,16 +87,27 @@ export class GitHubSourceControlHistoryItemDetailsProvider implements SourceCont
8787

8888
this._disposables.add(authentication.onDidChangeSessions(e => {
8989
if (e.provider.id === 'github') {
90-
this._enabled = true;
90+
this._isUserAuthenticated = true;
9191
}
9292
}));
93+
94+
this._disposables.add(workspace.onDidChangeConfiguration(e => {
95+
if (!e.affectsConfiguration('github.showAvatar')) {
96+
return;
97+
}
98+
99+
this._store.clear();
100+
}));
93101
}
94102

95103
async provideAvatar(repository: Repository, query: AvatarQuery): Promise<Map<string, string | undefined> | undefined> {
96104
this._logger.trace(`[GitHubSourceControlHistoryItemDetailsProvider][provideAvatar] Avatar resolution for ${query.commits.length} commit(s) in ${repository.rootUri.fsPath}.`);
97105

98-
if (!this._enabled) {
99-
this._logger.trace(`[GitHubSourceControlHistoryItemDetailsProvider][provideAvatar] Avatar resolution is disabled.`);
106+
const config = workspace.getConfiguration('github', repository.rootUri);
107+
const showAvatar = config.get<boolean>('showAvatar', true) === true;
108+
109+
if (!this._isUserAuthenticated || !showAvatar) {
110+
this._logger.trace(`[GitHubSourceControlHistoryItemDetailsProvider][provideAvatar] Avatar resolution is disabled. (${showAvatar === false ? 'setting' : 'auth'})`);
100111
return undefined;
101112
}
102113

@@ -185,7 +196,7 @@ export class GitHubSourceControlHistoryItemDetailsProvider implements SourceCont
185196
// signed in with their GitHub account or they have signed out. Disable the
186197
// avatar resolution until the user signes in with their GitHub account.
187198
if (err instanceof AuthenticationError) {
188-
this._enabled = false;
199+
this._isUserAuthenticated = false;
189200
}
190201

191202
return undefined;

0 commit comments

Comments
 (0)