diff --git a/.gitignore b/.gitignore index e38ca024..351559be 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .vscode-test npm-debug.log +vscode-github-*.vsix diff --git a/README.md b/README.md index 0a71e8f8..eff0ed4b 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,17 @@ Current it is possible to do the following: To use this extension one needs to create a new GitHub Personal Access Token and registers it in the extension. The 'GitHub: Set Personal Access Token' should be executed for that. -![GitHub Personal Access Token](./images/github-personal-access-token.png) +![GitHub Personal Access Token](images/github-personal-access-token.png) -![GitHub Personal Access Token](./images/github-personal-access-token2.png) +![GitHub Personal Access Token](images/github-personal-access-token2.png) -![Set GitHub Personal Access Token](./images/set-personal-access-token.png) +![Set GitHub Personal Access Token](images/set-personal-access-token.png) * Create a new pull request based on the current branch and the last commit The current branch will be requested to merge into master and the pull request title is the commit message summary. -![Create pull request](./images/create-pull-request.png) +![Create pull request](images/create-pull-request.png) * Checkout one of the open pull requests * Browse one of the open pull requests in your default browser +* Show if the current branch has an associated pull-request on github in the status bar diff --git a/package.json b/package.json index 492ad027..f27b7cc6 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,7 @@ "Other" ], "activationEvents": [ - "onCommand:extension.setGitHubToken", - "onCommand:extension.createPullRequest", - "onCommand:extension.checkoutPullRequests", - "onCommand:extension.browserPullRequest" + "*" ], "main": "./out/src/extension", "contributes": { diff --git a/src/extension.ts b/src/extension.ts index ea1a7f8d..230ed47e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,12 +9,17 @@ let cwd: string; let token: string; let github: GitHub; let channel: vscode.OutputChannel; +let statusBar: vscode.StatusBarItem; export function activate(context: vscode.ExtensionContext): void { cwd = vscode.workspace.rootPath; - getToken(context).then(_token => { - token = _token; - }); + getToken(context) + .then(_token => { + token = _token; + if (token) { + updatePullRequestStatus(); + } + }); channel = vscode.window.createOutputChannel('github'); context.subscriptions.push(channel); @@ -32,6 +37,26 @@ export function activate(context: vscode.ExtensionContext): void { context.subscriptions.push( vscode.commands.registerCommand('extension.browserPullRequest', wrapCommand(browserPullRequest))); + + statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); + statusBar.command = 'extension.statusBarCommand'; + statusBar.text = '$(git-pull-request)'; + statusBar.color = '#888'; + statusBar.show(); + context.subscriptions.push(statusBar); +} + +async function updatePullRequestStatus(forceState?: boolean): Promise { + const hasPullRequest = await hasPullRequestForCurrentBranch(); + if (forceState || hasPullRequest) { + statusBar.color = '#fff'; + statusBar.tooltip = ''; + statusBar.command = ''; + } else { + statusBar.color = '#888'; + statusBar.tooltip = 'Create pull-request for current branch'; + statusBar.command = 'extension.createPullRequest'; + } } function wrapCommand(command: T): T { @@ -106,6 +131,7 @@ async function createPullRequest(): Promise { channel.appendLine('Create pull request:'); channel.appendLine(JSON.stringify(body, undefined, ' ')); const pullRequest = await getGitHubClient().createPullRequest(owner, repository, body); + updatePullRequestStatus(true); vscode.window.showInformationMessage(`Successfully created #${pullRequest.number}`); } } catch (e) {