@@ -23,6 +23,7 @@ export interface PullRequestData {
23
23
export class GitHubRepository implements IGitHubRepository {
24
24
private _octokit : Octokit ;
25
25
private _initialized : boolean ;
26
+ private _authenticationStatus : vscode . StatusBarItem ;
26
27
public get octokit ( ) : Octokit {
27
28
if ( this . _octokit === undefined ) {
28
29
if ( ! this . _initialized ) {
@@ -34,7 +35,32 @@ export class GitHubRepository implements IGitHubRepository {
34
35
return this . _octokit ;
35
36
}
36
37
38
+ public set octokit ( newOctokit : Octokit ) {
39
+ if ( newOctokit !== this . _octokit ) {
40
+ this . _octokit = newOctokit ;
41
+
42
+ // update status bar item
43
+ this . updateAuthenticationStatus ( ) ;
44
+ }
45
+ }
46
+
37
47
constructor ( public readonly remote : Remote , private readonly _credentialStore : CredentialStore ) {
48
+ this . _authenticationStatus = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
49
+ const normalizedUri = this . remote . gitProtocol . normalizeUri ( ) ;
50
+ this . _authenticationStatus . text = `${ remote . owner } /${ remote . repositoryName } ⟷ Sign in to ${ normalizedUri . authority } ` ;
51
+ this . _authenticationStatus . command = 'pr.signin' ;
52
+ this . _authenticationStatus . show ( ) ;
53
+ }
54
+
55
+ updateAuthenticationStatus ( ) {
56
+ setTimeout ( async ( ) => {
57
+ if ( this . _octokit ) {
58
+ const currentUser = await this . _octokit . users . get ( { } ) ;
59
+ const userName = currentUser . data . login ;
60
+ this . _authenticationStatus . text = `${ this . remote . owner } /${ this . remote . repositoryName } ⟷ ${ userName } ` ;
61
+ this . _authenticationStatus . command = null ;
62
+ }
63
+ } , 0 ) ;
38
64
}
39
65
40
66
async ensure ( ) : Promise < GitHubRepository > {
@@ -47,10 +73,10 @@ export class GitHubRepository implements IGitHubRepository {
47
73
SIGNIN_COMMAND ) ;
48
74
49
75
if ( result === SIGNIN_COMMAND ) {
50
- this . _octokit = await this . _credentialStore . login ( this . remote ) ;
76
+ this . octokit = await this . _credentialStore . login ( this . remote ) ;
51
77
}
52
78
} else {
53
- this . _octokit = await this . _credentialStore . getOctokit ( this . remote ) ;
79
+ this . octokit = await this . _credentialStore . getOctokit ( this . remote ) ;
54
80
}
55
81
56
82
return this ;
@@ -59,11 +85,11 @@ export class GitHubRepository implements IGitHubRepository {
59
85
async authenticate ( ) : Promise < boolean > {
60
86
this . _initialized = true ;
61
87
if ( ! await this . _credentialStore . hasOctokit ( this . remote ) ) {
62
- this . _octokit = await this . _credentialStore . login ( this . remote ) ;
88
+ this . octokit = await this . _credentialStore . login ( this . remote ) ;
63
89
} else {
64
- this . _octokit = this . _credentialStore . getOctokit ( this . remote ) ;
90
+ this . octokit = this . _credentialStore . getOctokit ( this . remote ) ;
65
91
}
66
- return this . _octokit !== undefined ;
92
+ return this . octokit !== undefined ;
67
93
}
68
94
69
95
async getDefaultBranch ( ) : Promise < string > {
0 commit comments