Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,13 @@
"id": "pr",
"name": "GitHub Pull Requests",
"when": "!config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && workspaceFolderCount != 0"
},
{
"id": "prStatus",
"name": "Changes In Pull Request",
"when": "!config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && github:inReviewMode"
}
],
"scm": [
{
"id": "pr",
"name": "GitHub Pull Requests",
"when": "config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && workspaceFolderCount != 0"
},
{
"id": "prStatus",
"name": "Changes In Pull Request",
"when": "config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && github:inReviewMode"
}
]
},
Expand Down Expand Up @@ -382,11 +372,6 @@
"command": "pr.refreshList",
"when": "view == pr",
"group": "navigation"
},
{
"command": "pr.refreshChanges",
"when": "view == prStatus",
"group": "navigation"
}
],
"view/item/context": [
Expand All @@ -412,26 +397,26 @@
},
{
"command": "pr.openFileInGitHub",
"when": "view =~ /(pr|prStatus)/ && viewItem =~ /filechange/"
"when": "view == pr && viewItem =~ /filechange/"
},
{
"command": "pr.copyCommitHash",
"when": "view == prStatus && viewItem =~ /commit/"
"when": "view == pr && viewItem =~ /commit/"
},
{
"command": "pr.openDescriptionToTheSide",
"group": "inline",
"when": "view =~ /(pr|prStatus)/ && viewItem =~ /description/"
"when": "view == pr && viewItem =~ /description/"
},
{
"command": "review.openFile",
"group": "inline",
"when": "config.git.openDiffOnClick && view == prStatus && viewItem =~ /filechange(?!:DELETE)/"
"when": "config.git.openDiffOnClick && view == pr && viewItem =~ /filechange:active(?!:DELETE)/"
},
{
"command": "pr.openDiffView",
"group": "inline",
"when": "!config.git.openDiffOnClick && view == prStatus && viewItem =~ /filechange(?!:DELETE)/"
"when": "!config.git.openDiffOnClick && view == pr && viewItem =~ /filechange:active(?!:DELETE)/"
}
],
"editor/title": [
Expand Down
13 changes: 8 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { GitErrorCodes } from './git/api';
import { Comment } from './common/comment';
import { PullRequestManager } from './github/pullRequestManager';
import { PullRequestModel } from './github/pullRequestModel';
import { ActivePRNode } from './view/treeNodes/activePullRequestNode';

const _onDidUpdatePR = new vscode.EventEmitter<PullRequest | undefined>();
export const onDidUpdatePR: vscode.Event<PullRequest | undefined> = _onDidUpdatePR.event;
Expand Down Expand Up @@ -258,9 +259,12 @@ export function registerCommands(context: vscode.ExtensionContext, prManager: Pu

context.subscriptions.push(vscode.commands.registerCommand('pr.openDescription', async (descriptionNode: DescriptionNode) => {
if (!descriptionNode) {
// the command is triggerred from command palette or status bar, which means we are already in checkout mode.
let rootNodes = await reviewManager.prFileChangesProvider.getChildren();
descriptionNode = rootNodes[0] as DescriptionNode;
// the command is triggerred from command palette or status bar, which means we are already in checkout mode. Assume the PR exists
// in the "Local Pull Request Branches" category
const rootNodes = await reviewManager.prsTreeDataProvider.getChildren();
const localFileChanges = await rootNodes[0].getChildren();
const activePR = localFileChanges.filter(change => change instanceof ActivePRNode)[0];
descriptionNode = (await activePR.getChildren())[0] as DescriptionNode;
}
const pullRequest = ensurePR(prManager, descriptionNode.pullRequestModel);
// Create and show a new webview
Expand Down Expand Up @@ -292,11 +296,10 @@ export function registerCommands(context: vscode.ExtensionContext, prManager: Pu
}

// Show the file change in a diff view.
let { path, ref, commit } = fromReviewUri(fileChange.filePath);
let { path, commit } = fromReviewUri(fileChange.filePath);
let previousCommit = `${commit}^`;
const query: ReviewUriParams = {
path: path,
ref: ref,
commit: previousCommit,
base: true,
isOutdated: true
Expand Down
7 changes: 2 additions & 5 deletions src/common/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { PullRequestModel } from '../github/pullRequestModel';

export interface ReviewUriParams {
path: string;
ref?: string;
commit?: string;
base: boolean;
isOutdated: boolean;
Expand Down Expand Up @@ -43,10 +42,9 @@ export interface GitUriOptions {
base: boolean;
}

export function toDiffViewFileUri(uri: Uri, filePath: string | undefined, ref: string | undefined, commit: string, isOutdated: boolean, options: GitUriOptions): Uri {
export function toDiffViewFileUri(uri: Uri, filePath: string | undefined, commit: string, isOutdated: boolean, options: GitUriOptions): Uri {
const params: ReviewUriParams = {
path: filePath ? filePath : uri.path,
ref,
commit: commit,
base: options.base,
isOutdated
Expand All @@ -67,10 +65,9 @@ export function toDiffViewFileUri(uri: Uri, filePath: string | undefined, ref: s
// As a mitigation for extensions like ESLint showing warnings and errors
// for git URIs, let's change the file extension of these uris to .git,
// when `replaceFileExtension` is true.
export function toReviewUri(uri: Uri, filePath: string | undefined, ref: string | undefined, commit: string, isOutdated: boolean, options: GitUriOptions): Uri {
export function toReviewUri(uri: Uri, filePath: string | undefined, commit: string, isOutdated: boolean, options: GitUriOptions): Uri {
const params: ReviewUriParams = {
path: filePath ? filePath : uri.path,
ref,
commit: commit,
base: options.base,
isOutdated
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function init(context: vscode.ExtensionContext, git: GitAPI, repository: R
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
context.subscriptions.push(new FileTypeDecorationProvider());
const prManager = new PullRequestManager(repository, telemetry);
const reviewManager = new ReviewManager(context, Keychain.onDidChange, repository, prManager, telemetry);
const reviewManager = new ReviewManager(Keychain.onDidChange, repository, prManager, telemetry);
registerCommands(context, prManager, reviewManager, telemetry);

git.repositories.forEach(repo => {
Expand Down
4 changes: 4 additions & 0 deletions src/github/pullRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { EXTENSION_ID } from '../constants';
import { fromPRUri } from '../common/uri';
import { convertRESTPullRequestToRawPullRequest, convertPullRequestsGetCommentsResponseItemToComment, convertIssuesCreateCommentResponseToComment, parseGraphQLTimelineEvents, convertRESTTimelineEvents, getRelatedUsersFromTimelineEvents, parseGraphQLComment } from './utils';
import { PendingReviewIdResponse, TimelineEventsResponse, PullRequestCommentsResponse, AddCommentResponse, SubmitReviewResponse, DeleteReviewResponse, EditCommentResponse } from './graphql';
import { GitFileChange } from '../view/treeNodes/fileChangeNode';
const queries = require('./queries.gql');

interface PageInformation {
Expand Down Expand Up @@ -98,6 +99,9 @@ export const onDidSubmitReview: vscode.Event<Comment[]> = _onDidSubmitReview.eve
export class PullRequestManager {
static ID = 'PullRequestManager';
private _activePullRequest?: PullRequestModel;
public activeFileChanges?: GitFileChange[];
public activeOutdatedFileChanges?: GitFileChange[];
public activeComments?: Comment[];
private _credentialStore: CredentialStore;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of having view info in PullRequestManager. We can probably keep the information in prsTreeDataProvider. The ReviewManager takes care of git status change, and modifying PullRequestManager.activePullRequest, prsTreeDataProvider then listens to activePullRequest change event and reveal/refresh the tree when necessary.

private _githubRepositories: GitHubRepository[];
private _mentionableUsers?: { [key: string]: IAccount[] };
Expand Down
140 changes: 0 additions & 140 deletions src/view/prChangesTreeDataProvider.ts

This file was deleted.

12 changes: 7 additions & 5 deletions src/view/prsTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
private _disposables: vscode.Disposable[];
private _childrenDisposables: vscode.Disposable[];
private _view: vscode.TreeView<TreeNode>;
private _firstLoad = true;

get view(): vscode.TreeView<TreeNode> {
return this._view;
Expand Down Expand Up @@ -68,14 +69,15 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
}

let result = [
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.LocalPullRequest),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.RequestReview),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.AssignedToMe),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.Mine),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.All)
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.LocalPullRequest, this._firstLoad),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.RequestReview, this._firstLoad),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.AssignedToMe, this._firstLoad),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.Mine, this._firstLoad),
new CategoryTreeNode(this._view, this._prManager, this._telemetry, PRType.All, this._firstLoad)
];

this._childrenDisposables = result;
this._firstLoad = false;
return Promise.resolve(result);
}
if (this._prManager.repository.state.remotes.length === 0) {
Expand Down
Loading