Skip to content

Commit 3d0cff8

Browse files
Supress auth error notifications for github triggered by Launchpad (#3397)
Silences error notifications from popping up from the Launchpad indicator's automatic "get my pull requests" query
1 parent 526650b commit 3d0cff8

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

src/plus/focus/focusProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class FocusProvider implements Disposable {
276276

277277
const [prsResult, subscriptionResult] = await Promise.allSettled([
278278
withDurationAndSlowEventOnTimeout(
279-
this.container.integrations.getMyPullRequests([HostingIntegrationId.GitHub], cancellation),
279+
this.container.integrations.getMyPullRequests([HostingIntegrationId.GitHub], cancellation, true),
280280
'getMyPullRequests',
281281
this.container,
282282
),

src/plus/integrations/integration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,15 +1160,18 @@ export abstract class HostingIntegration<
11601160
async searchMyPullRequests(
11611161
repo?: T,
11621162
cancellation?: CancellationToken,
1163+
silent?: boolean,
11631164
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>>;
11641165
async searchMyPullRequests(
11651166
repos?: T[],
11661167
cancellation?: CancellationToken,
1168+
silent?: boolean,
11671169
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>>;
11681170
@debug()
11691171
async searchMyPullRequests(
11701172
repos?: T | T[],
11711173
cancellation?: CancellationToken,
1174+
silent?: boolean,
11721175
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
11731176
const scope = getLogScope();
11741177
const connected = this.maybeConnected ?? (await this.isConnected());
@@ -1180,6 +1183,7 @@ export abstract class HostingIntegration<
11801183
this._session!,
11811184
repos != null ? (Array.isArray(repos) ? repos : [repos]) : undefined,
11821185
cancellation,
1186+
silent,
11831187
);
11841188
return { value: pullRequests, duration: Date.now() - start };
11851189
} catch (ex) {
@@ -1192,6 +1196,7 @@ export abstract class HostingIntegration<
11921196
session: ProviderAuthenticationSession,
11931197
repos?: T[],
11941198
cancellation?: CancellationToken,
1199+
silent?: boolean,
11951200
): Promise<SearchedPullRequest[] | undefined>;
11961201

11971202
async searchPullRequests(

src/plus/integrations/integrationService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ export class IntegrationService implements Disposable {
449449
async getMyPullRequests(
450450
integrationIds?: HostingIntegrationId[],
451451
cancellation?: CancellationToken,
452+
silent?: boolean,
452453
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
453454
const integrations: Map<HostingIntegration, ResourceDescriptor[] | undefined> = new Map();
454455
for (const integrationId of integrationIds?.length ? integrationIds : Object.values(HostingIntegrationId)) {
@@ -459,20 +460,21 @@ export class IntegrationService implements Disposable {
459460
}
460461
if (integrations.size === 0) return undefined;
461462

462-
return this.getMyPullRequestsCore(integrations, cancellation);
463+
return this.getMyPullRequestsCore(integrations, cancellation, silent);
463464
}
464465

465466
private async getMyPullRequestsCore(
466467
integrations: Map<HostingIntegration, ResourceDescriptor[] | undefined>,
467468
cancellation?: CancellationToken,
469+
silent?: boolean,
468470
): Promise<IntegrationResult<SearchedPullRequest[] | undefined>> {
469471
const start = Date.now();
470472

471473
const promises: Promise<IntegrationResult<SearchedPullRequest[] | undefined>>[] = [];
472474
for (const [integration, repos] of integrations) {
473475
if (integration == null) continue;
474476

475-
promises.push(integration.searchMyPullRequests(repos, cancellation));
477+
promises.push(integration.searchMyPullRequests(repos, cancellation, silent));
476478
}
477479

478480
const results = await Promise.allSettled(promises);

src/plus/integrations/providers/github.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
171171
{ accessToken }: AuthenticationSession,
172172
repos?: GitHubRepositoryDescriptor[],
173173
cancellation?: CancellationToken,
174+
silent?: boolean,
174175
): Promise<SearchedPullRequest[] | undefined> {
175176
return (await this.container.github)?.searchMyPullRequests(
176177
this,
177178
accessToken,
178179
{
179180
repos: repos?.map(r => `${r.owner}/${r.name}`),
180181
baseUrl: this.apiBaseUrl,
182+
silent: silent,
181183
},
182184
cancellation,
183185
);

src/plus/integrations/providers/github/github.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,11 +2629,16 @@ export class GitHubApi implements Disposable {
26292629
}
26302630
}
26312631

2632-
private handleException(ex: Error, provider: Provider | undefined, scope: LogScope | undefined): Error {
2632+
private handleException(
2633+
ex: Error,
2634+
provider: Provider | undefined,
2635+
scope: LogScope | undefined,
2636+
silent?: boolean,
2637+
): Error {
26332638
Logger.error(ex, scope);
26342639
// debugger;
26352640

2636-
if (ex instanceof AuthenticationError) {
2641+
if (ex instanceof AuthenticationError && !silent) {
26372642
void this.showAuthenticationErrorMessage(ex, provider);
26382643
}
26392644
return ex;
@@ -2706,7 +2711,14 @@ export class GitHubApi implements Disposable {
27062711
async searchMyPullRequests(
27072712
provider: Provider,
27082713
token: string,
2709-
options?: { search?: string; user?: string; repos?: string[]; baseUrl?: string; avatarSize?: number },
2714+
options?: {
2715+
search?: string;
2716+
user?: string;
2717+
repos?: string[];
2718+
baseUrl?: string;
2719+
avatarSize?: number;
2720+
silent?: boolean;
2721+
},
27102722
cancellation?: CancellationToken,
27112723
): Promise<SearchedPullRequest[]> {
27122724
const scope = getLogScope();
@@ -2817,15 +2829,22 @@ export class GitHubApi implements Disposable {
28172829
);
28182830
return results;
28192831
} catch (ex) {
2820-
throw this.handleException(ex, provider, scope);
2832+
throw this.handleException(ex, provider, scope, options?.silent);
28212833
}
28222834
}
28232835

28242836
@debug<GitHubApi['searchMyInvolvedPullRequests']>({ args: { 0: p => p.name, 1: '<token>' } })
28252837
private async searchMyInvolvedPullRequests(
28262838
provider: Provider,
28272839
token: string,
2828-
options?: { search?: string; user?: string; repos?: string[]; baseUrl?: string; avatarSize?: number },
2840+
options?: {
2841+
search?: string;
2842+
user?: string;
2843+
repos?: string[];
2844+
baseUrl?: string;
2845+
avatarSize?: number;
2846+
silent?: boolean;
2847+
},
28292848
cancellation?: CancellationToken,
28302849
): Promise<SearchedPullRequest[]> {
28312850
const scope = getLogScope();
@@ -2922,7 +2941,7 @@ export class GitHubApi implements Disposable {
29222941
const results: SearchedPullRequest[] = rsp.search.nodes.map(pr => toQueryResult(pr));
29232942
return results;
29242943
} catch (ex) {
2925-
throw this.handleException(ex, provider, scope);
2944+
throw this.handleException(ex, provider, scope, options?.silent);
29262945
}
29272946
}
29282947

0 commit comments

Comments
 (0)