1
+ import { join } from 'path' ;
2
+ import * as sander from 'sander' ;
1
3
import * as vscode from 'vscode' ;
2
4
import * as git from './git' ;
3
5
import { getClient , GitHub , GitHubError , ListPullRequestsParameters , CreatePullRequestBody } from './github' ;
4
6
5
7
let cwd : string ;
6
- let token : string ;
8
+ let storedToken : string ;
7
9
let github : GitHub ;
8
10
let channel : vscode . OutputChannel ;
9
11
let statusBar : vscode . StatusBarItem ;
10
12
11
13
export function activate ( context : vscode . ExtensionContext ) : void {
14
+ checkVersionAndToken ( context ) ;
15
+
12
16
cwd = vscode . workspace . rootPath ;
13
17
getToken ( context )
14
18
. then ( _token => {
15
- token = _token ;
19
+ storedToken = _token ;
16
20
refreshPullRequestStatus ( ) ;
17
21
} ) ;
18
22
@@ -40,8 +44,26 @@ export function activate(context: vscode.ExtensionContext): void {
40
44
context . subscriptions . push ( statusBar ) ;
41
45
}
42
46
47
+ function checkVersionAndToken ( context : vscode . ExtensionContext ) : void {
48
+ sander . readFile ( join ( context . extensionPath , 'package.json' ) )
49
+ . then ( content => JSON . parse ( content ) )
50
+ . then ( json => json . version as string )
51
+ . then ( version => {
52
+ return getToken ( context )
53
+ . then ( token => ( { token, version} ) ) ;
54
+ } )
55
+ . then ( ( { version, token} ) => {
56
+ const storedVersion = context . globalState . get ( 'version-test' ) ;
57
+ if ( version !== storedVersion && ! Boolean ( token ) ) {
58
+ context . globalState . update ( 'version-test' , version ) ;
59
+ vscode . window . showInformationMessage (
60
+ 'To enable the Visual Studio Code GitHub Support, please set a Personal Access Token' ) ;
61
+ }
62
+ } ) ;
63
+ }
64
+
43
65
async function refreshPullRequestStatus ( ) : Promise < void > {
44
- if ( token ) {
66
+ if ( storedToken ) {
45
67
await updatePullRequestStatus ( ) ;
46
68
}
47
69
setTimeout ( refreshPullRequestStatus , 5000 ) ;
@@ -74,7 +96,7 @@ async function updatePullRequestStatus(forceState?: boolean): Promise<void> {
74
96
75
97
function wrapCommand < T > ( command : T ) : T {
76
98
const wrap : any = ( ...args : any [ ] ) => {
77
- if ( Boolean ( token ) && Boolean ( cwd ) ) {
99
+ if ( Boolean ( storedToken ) && Boolean ( cwd ) ) {
78
100
return ( command as any ) . apply ( null , args ) ;
79
101
} else {
80
102
vscode . window . showWarningMessage ( 'Please setup your Github Personal Access Token '
@@ -90,7 +112,7 @@ function getToken(context: vscode.ExtensionContext): PromiseLike<string> {
90
112
91
113
function getGitHubClient ( ) : GitHub {
92
114
if ( ! github ) {
93
- github = getClient ( token ) ;
115
+ github = getClient ( storedToken ) ;
94
116
}
95
117
return github ;
96
118
}
@@ -115,7 +137,7 @@ function createGithubTokenCommand(context: vscode.ExtensionContext): () => Promi
115
137
return vscode . window . showInputBox ( options )
116
138
. then ( input => {
117
139
context . globalState . update ( 'token' , input ) ;
118
- token = input ;
140
+ storedToken = input ;
119
141
} ) ;
120
142
} ;
121
143
}
0 commit comments