Skip to content

Commit

Permalink
Logging for review manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jun 11, 2018
1 parent 358c77a commit 73c489c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Resource } from './common/resources';
import { ReviewManager } from './review/reviewManager';
import { CredentialStore } from './credentials';
import { registerCommands } from './commands';
import Logger from './logger';

export async function activate(context: vscode.ExtensionContext) {
// initialize resources
Expand All @@ -36,12 +37,14 @@ export async function activate(context: vscode.ExtensionContext) {
})
);

Logger.appendLine('Looking for git repository');
const repository = new Repository(rootPath);
let repositoryInitialized = false;
repository.onDidRunGitStatus(async e => {
if (repositoryInitialized) {
return;
}
Logger.appendLine('Git repository found, initializing review manager and pr tree view.')
repositoryInitialized = true;
let credentialStore = new CredentialStore(configuration);
await repository.connectGitHub(credentialStore);
Expand Down
4 changes: 4 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { window, OutputChannel } from 'vscode';

const Logger: OutputChannel = window.createOutputChannel('GitHub Pull Request');
export default Logger;
22 changes: 14 additions & 8 deletions src/review/reviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FileChangesProvider } from './fileChangesProvider';
import { GitContentProvider } from './gitContentProvider';
import { DiffChangeType } from '../models/diffHunk';
import { PRFileChangeNode } from '../tree/prFileChangeNode';
import Logger from '../logger';


export class ReviewManager implements vscode.DecorationProvider {
Expand Down Expand Up @@ -73,7 +74,6 @@ export class ReviewManager implements vscode.DecorationProvider {
static get instance() {
return ReviewManager._instance;
}

get prFileChangesProvider() {
if (!this._prFileChangesProvider) {
this._prFileChangesProvider = new FileChangesProvider(this._context);
Expand Down Expand Up @@ -103,9 +103,17 @@ export class ReviewManager implements vscode.DecorationProvider {
}

private async validateState() {
Logger.appendLine('Review> validate local branch state');
let branch = this._repository.HEAD;
if (!branch) {
this.clear(true);
return;
}

let matchingPullRequestMetadata = await PullRequestGitHelper.getMatchingPullRequestMetadataForBranch(this._repository, this._repository.HEAD.name);

if (!matchingPullRequestMetadata) {
Logger.appendLine(`Review> no matching pull request metadata found for current branch ${this._repository.HEAD.name}`);
this.clear(true);
return;
}
Expand All @@ -114,19 +122,15 @@ export class ReviewManager implements vscode.DecorationProvider {
return;
}

let branch = this._repository.HEAD;
if (!branch) {
this.clear(true);
return;
}

let remote = branch.upstream ? branch.upstream.remote : null;
if (!remote) {
Logger.appendLine(`Review> current branch ${this._repository.HEAD.name} hasn't setup remote yet`);
this.clear(true);
return;
}

// we switch to another PR, let's clean up first.
Logger.appendLine(`Review> current branch ${this._repository.HEAD.name} is associated with pull request #${matchingPullRequestMetadata.prNumber}`);
this.clear(false);
this._prNumber = matchingPullRequestMetadata.prNumber;
this._lastCommitSha = null;
Expand All @@ -152,10 +156,12 @@ export class ReviewManager implements vscode.DecorationProvider {
await this.prFileChangesProvider.showPullRequestFileChanges(pr, this._localFileChanges);

this._onDidChangeDecorations.fire();
Logger.appendLine(`Review> register comments provider`);
this.registerCommentProvider();

this.statusBarItem.text = '$(git-branch) Pull Request #' + this._prNumber;
this.statusBarItem.command = 'pr.openInGitHub';
Logger.appendLine(`Review> display pull request status bar indicator and refresh pull request tree view.`);
this.statusBarItem.show();
vscode.commands.executeCommand('pr.refreshList');
}
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
],
"sourceMap": true,
"rootDir": "./src",
"jsx": "react"
"jsx": "react",
"typeRoots": [
"./node_modules/@types",
"./src/typings/"
]
},
"include": [
"src/**/*"
Expand Down

0 comments on commit 73c489c

Please sign in to comment.