Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat(vscode-github): add status-bar icon for pull-request (#9)
Browse files Browse the repository at this point in the history
* feat(vscode-github): add status-bar icon for pull-request

show a status-bar icon and hightlight it when there is an active pull request for the current branch

* feat(vscode-github): add status-bar command

on click create pull-request if non currently active
  • Loading branch information
KnisterPeter authored Nov 14, 2016
1 parent 4359f6c commit 260cf5f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.vscode-test

npm-debug.log
vscode-github-*.vsix
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
"Other"
],
"activationEvents": [
"onCommand:extension.setGitHubToken",
"onCommand:extension.createPullRequest",
"onCommand:extension.checkoutPullRequests",
"onCommand:extension.browserPullRequest"
"*"
],
"main": "./out/src/extension",
"contributes": {
Expand Down
32 changes: 29 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<void> {
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<T>(command: T): T {
Expand Down Expand Up @@ -106,6 +131,7 @@ async function createPullRequest(): Promise<void> {
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) {
Expand Down

0 comments on commit 260cf5f

Please sign in to comment.