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

Commit

Permalink
feat: add configurable status bar
Browse files Browse the repository at this point in the history
For customization the status bar command is configurable to any known
command.

Closes #140
  • Loading branch information
KnisterPeter committed Sep 6, 2017
1 parent 88cc753 commit 19a9e01
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Current it is possible to do the following:
* Support for GitHub Enterprise (on-premise installations)
* Browse open issues
* Browse the current open file (including current cursor position)
* Configure the statusbar behaviour by setting the `github.statusBarCommand` configuration value.

![Create pull request](images/create-pull-request.png)

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
],
"default": "off",
"description": "By default the pull request description is the first commit message. When this property is set, the user is asked for a description when creating the PR. This can be a single-line description via an input dialog ('singleLine') or a multi-line markdown description via the editor configured in git ('gitEditor')."
},
"github.statusBarCommand": {
"type": ["string", "null"],
"description": "Defines which command is executed when clicking the status bar item. Default behaviour is the create-pull-request-then-merge cycle (different command based on state). For example to open the current pull request set this to 'vscode-github.browserSimplePullRequest'",
"default": null
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CommandManager } from './command-manager';
import { checkExistence } from './git';
import { GitHubError } from './github';
import { GitHubManager, Tokens } from './github-manager';
import { StatusBarManager } from './status-bar-manager';

@component
export class Extension {
Expand All @@ -32,6 +33,7 @@ export class Extension {
this.checkVersionAndToken(this.context, tokens);

this.tsdi.get(CommandManager);
this.tsdi.get(StatusBarManager);

if (!vscode.workspace.workspaceFolders) {
return;
Expand Down
49 changes: 35 additions & 14 deletions src/status-bar-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const githubPullRequestIcon = '$(git-pull-request)';
@component
export class StatusBarManager {

private customStatusBarCommand: string | null;

private refreshInterval: number;

@inject('vscode.ExtensionContext')
private context: vscode.ExtensionContext;

Expand All @@ -37,8 +41,12 @@ export class StatusBarManager {

@initialize
protected init(): void {
const config = vscode.workspace.getConfiguration('github');
this.customStatusBarCommand = config.get('statusBarCommand', null);
this.refreshInterval = config.get('refreshPullRequestStatus', 5) * 1000;

this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
this.statusBar.command = '';
this.statusBar.command = this.customStatusBarCommand || '';
this.statusBar.text = `${githubPullRequestIcon} ...`;
this.statusBar.color = colors.none;
this.context.subscriptions.push(this.statusBar);
Expand All @@ -60,8 +68,7 @@ export class StatusBarManager {
throw e;
}
}
setTimeout(() => { this.refreshStatus(); },
vscode.workspace.getConfiguration('github').get<number>('refreshPullRequestStatus', 5) * 1000);
setTimeout(() => { this.refreshStatus(); }, this.refreshInterval);
}

public async updateStatus(): Promise<void> {
Expand All @@ -72,8 +79,10 @@ export class StatusBarManager {
this.statusBar.show();
this.statusBar.color = colors.none;
this.statusBar.text = `${githubPullRequestIcon}`;
this.statusBar.tooltip = 'Not on a pull request branch. Click to checkout pull request';
this.statusBar.command = 'vscode-github.checkoutPullRequests';
if (!this.customStatusBarCommand) {
this.statusBar.tooltip = 'Not on a pull request branch. Click to checkout pull request';
this.statusBar.command = 'vscode-github.checkoutPullRequests';
}
}
}

Expand All @@ -82,16 +91,9 @@ export class StatusBarManager {
const pullRequest = await this.githubManager.getPullRequestForCurrentBranch();
this.statusBar.show();
if (pullRequest) {
const status = await this.calculateMergableStatus(pullRequest);
this.statusBar.color = colors[status];
this.statusBar.text = `${githubPullRequestIcon} #${pullRequest.number} ${status}`;
this.statusBar.tooltip = status === 'success' ? `Merge pull-request #${pullRequest.number}` : '';
this.statusBar.command = status === 'success' ? 'vscode-github.mergePullRequest' : '';
await this.showPullRequestStauts(pullRequest);
} else {
this.statusBar.color = colors.none;
this.statusBar.text = `${githubPullRequestIcon} Create PR`;
this.statusBar.tooltip = 'Create pull-request for current branch';
this.statusBar.command = 'vscode-github.createPullRequest';
this.showCreatePullRequestStatus();
}
} catch (e) {
if (e instanceof GitHubError) {
Expand All @@ -103,6 +105,25 @@ export class StatusBarManager {
}
}

private async showPullRequestStauts(pullRequest: PullRequest): Promise<void> {
const status = await this.calculateMergableStatus(pullRequest);
this.statusBar.color = colors[status];
this.statusBar.text = `${githubPullRequestIcon} #${pullRequest.number} ${status}`;
if (!this.customStatusBarCommand) {
this.statusBar.tooltip = status === 'success' ? `Merge pull-request #${pullRequest.number}` : '';
this.statusBar.command = status === 'success' ? 'vscode-github.mergePullRequest' : '';
}
}

private showCreatePullRequestStatus(): void {
this.statusBar.color = colors.none;
this.statusBar.text = `${githubPullRequestIcon} Create PR`;
if (!this.customStatusBarCommand) {
this.statusBar.tooltip = 'Create pull-request for current branch';
this.statusBar.command = 'vscode-github.createPullRequest';
}
}

private async calculateMergableStatus(pullRequest: PullRequest): Promise<PullRequestStatus> {
let status: PullRequestStatus = 'pending';
if (typeof pullRequest.mergeable === 'undefined') {
Expand Down

0 comments on commit 19a9e01

Please sign in to comment.