@@ -25,7 +25,7 @@ import {
25
25
} from '../common/settingKeys' ;
26
26
import { ITelemetry } from '../common/telemetry' ;
27
27
import { fromPRUri , fromReviewUri , KnownMediaExtensions , PRUriParams , Schemes , toReviewUri } from '../common/uri' ;
28
- import { formatError , groupBy , onceEvent } from '../common/utils' ;
28
+ import { formatError , groupBy , isPreRelease , onceEvent } from '../common/utils' ;
29
29
import { FOCUS_REVIEW_MODE } from '../constants' ;
30
30
import { GitHubCreatePullRequestLinkProvider } from '../github/createPRLinkProvider' ;
31
31
import { FolderRepositoryManager } from '../github/folderRepositoryManager' ;
@@ -267,9 +267,40 @@ export class ReviewManager {
267
267
}
268
268
}
269
269
270
+ private hasShownLogRequest : boolean = false ;
270
271
private async validateStatueAndSetContext ( silent : boolean , updateLayout : boolean ) {
271
- await this . validateState ( silent , updateLayout ) ;
272
- await vscode . commands . executeCommand ( 'setContext' , 'github:stateValidated' , true ) ;
272
+ // TODO @alexr 00: There's a bug where validateState never returns sometimes. It's not clear what's causing this.
273
+ // This is a temporary workaround to ensure that the validateStatueAndSetContext promise always resolves.
274
+ // Additional logs have been added, and the issue is being tracked here: https://github.com/microsoft/vscode-pull-request-git/issues/5277
275
+ let timeout : NodeJS . Timeout | undefined ;
276
+ const timeoutPromise = new Promise < void > ( resolve => {
277
+ timeout = setTimeout ( ( ) => {
278
+ if ( timeout ) {
279
+ clearTimeout ( timeout ) ;
280
+ timeout = undefined ;
281
+ Logger . error ( 'Timeout occurred while validating state.' , ReviewManager . ID ) ;
282
+ if ( ! this . hasShownLogRequest && isPreRelease ( this . _context ) ) {
283
+ this . hasShownLogRequest = true ;
284
+ vscode . window . showErrorMessage ( vscode . l10n . t ( 'A known error has occurred refreshing the repository state. Please share logs from "GitHub Pull Request" in the [tracking issue]({0}).' , 'https://github.com/microsoft/vscode-pull-request-github/issues/5277' ) ) ;
285
+ }
286
+ }
287
+ resolve ( ) ;
288
+ } , 1000 * 60 * 2 ) ;
289
+ } ) ;
290
+
291
+ const validatePromise = new Promise < void > ( resolve => {
292
+ this . validateState ( silent , updateLayout ) . then ( ( ) => {
293
+ vscode . commands . executeCommand ( 'setContext' , 'github:stateValidated' , true ) . then ( ( ) => {
294
+ if ( timeout ) {
295
+ clearTimeout ( timeout ) ;
296
+ timeout = undefined ;
297
+ }
298
+ resolve ( ) ;
299
+ } ) ;
300
+ } ) ;
301
+ } ) ;
302
+
303
+ return Promise . race ( [ validatePromise , timeoutPromise ] ) ;
273
304
}
274
305
275
306
private async offerIgnoreBranch ( currentBranchName ) : Promise < boolean > {
@@ -388,8 +419,10 @@ export class ReviewManager {
388
419
const previousPrNumber = this . _prNumber ;
389
420
let pr = await this . resolvePullRequest ( matchingPullRequestMetadata ) ;
390
421
if ( ! pr ) {
422
+ Logger . appendLine ( `Unable to resolve PR #${ matchingPullRequestMetadata . prNumber } ` , ReviewManager . ID ) ;
391
423
return ;
392
424
}
425
+ Logger . appendLine ( `Resolved PR #${ matchingPullRequestMetadata . prNumber } , state is ${ pr . state } ` , ReviewManager . ID ) ;
393
426
394
427
// Check if the PR is open, if not, check if there's another PR from the same branch on GitHub
395
428
if ( pr . state !== GithubItemStateEnum . Open ) {
@@ -416,14 +449,14 @@ export class ReviewManager {
416
449
. get < { merged : boolean , closed : boolean } > ( USE_REVIEW_MODE , { merged : true , closed : false } ) ;
417
450
418
451
if ( pr . isClosed && ! useReviewConfiguration . closed ) {
419
- await this . clear ( true ) ;
420
452
Logger . appendLine ( 'This PR is closed' , ReviewManager . ID ) ;
453
+ await this . clear ( true ) ;
421
454
return ;
422
455
}
423
456
424
457
if ( pr . isMerged && ! useReviewConfiguration . merged ) {
425
- await this . clear ( true ) ;
426
458
Logger . appendLine ( 'This PR is merged' , ReviewManager . ID ) ;
459
+ await this . clear ( true ) ;
427
460
return ;
428
461
}
429
462
@@ -471,6 +504,7 @@ export class ReviewManager {
471
504
this . _changesSinceLastReviewProgress . endProgress ( ) ;
472
505
} )
473
506
) ;
507
+ Logger . appendLine ( `Register in memory content provider` , ReviewManager . ID ) ;
474
508
await this . registerGitHubInMemContentProvider ( ) ;
475
509
476
510
this . statusBarItem . text = '$(git-pull-request) ' + vscode . l10n . t ( 'Pull Request #{0}' , pr . number ) ;
0 commit comments