11import * as vscode from 'vscode' ;
2- import { PullRequest , PullRequestStatus } from './github' ;
2+ import { GitHubError , PullRequest , PullRequestStatus } from './github' ;
33import { GitHubManager } from './github-manager' ;
44
55const colors = {
@@ -15,8 +15,11 @@ export class StatusBarManager {
1515
1616 private githubManager : GitHubManager ;
1717
18- constructor ( context : vscode . ExtensionContext , githubManager : GitHubManager ) {
18+ private channel : vscode . OutputChannel ;
19+
20+ constructor ( context : vscode . ExtensionContext , githubManager : GitHubManager , channel : vscode . OutputChannel ) {
1921 this . githubManager = githubManager ;
22+ this . channel = channel ;
2023
2124 this . statusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
2225 this . statusBar . command = '' ;
@@ -35,17 +38,26 @@ export class StatusBarManager {
3538 }
3639
3740 public async updatePullRequestStatus ( ) : Promise < void > {
38- const pullRequest = await this . githubManager . getPullRequestForCurrentBranch ( ) ;
39- this . statusBar . show ( ) ;
40- if ( pullRequest ) {
41- const status = await this . calculateMergableStatus ( pullRequest ) ;
42- this . statusBar . color = colors [ status ] ;
43- this . statusBar . tooltip = status === 'success' ? `Merge pull-request #${ pullRequest . number } ` : '' ;
44- this . statusBar . command = status === 'success' ? 'extension.mergePullRequest' : '' ;
45- } else {
46- this . statusBar . color = colors . none ;
47- this . statusBar . tooltip = 'Create pull-request for current branch' ;
48- this . statusBar . command = 'extension.createPullRequest' ;
41+ try {
42+ const pullRequest = await this . githubManager . getPullRequestForCurrentBranch ( ) ;
43+ this . statusBar . show ( ) ;
44+ if ( pullRequest ) {
45+ const status = await this . calculateMergableStatus ( pullRequest ) ;
46+ this . statusBar . color = colors [ status ] ;
47+ this . statusBar . tooltip = status === 'success' ? `Merge pull-request #${ pullRequest . number } ` : '' ;
48+ this . statusBar . command = status === 'success' ? 'extension.mergePullRequest' : '' ;
49+ } else {
50+ this . statusBar . color = colors . none ;
51+ this . statusBar . tooltip = 'Create pull-request for current branch' ;
52+ this . statusBar . command = 'extension.createPullRequest' ;
53+ }
54+ } catch ( e ) {
55+ if ( e instanceof GitHubError ) {
56+ console . log ( e ) ;
57+ this . channel . appendLine ( 'Update pull request status error:' ) ;
58+ this . channel . appendLine ( JSON . stringify ( e . response , undefined , ' ' ) ) ;
59+ }
60+ throw e ;
4961 }
5062 }
5163
0 commit comments