forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitNode.ts
More file actions
87 lines (76 loc) · 2.89 KB
/
Copy pathcommitNode.ts
File metadata and controls
87 lines (76 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as path from 'path';
import { PullRequestsGetCommitsResponseItem } from '@octokit/rest';
import { TreeNode } from './treeNode';
import { GitFileChangeNode } from './fileChangeNode';
import { toReviewUri } from '../../common/uri';
import { getGitChangeType } from '../../common/diffHunk';
import { Comment } from '../../common/comment';
import { PullRequestManager } from '../../github/pullRequestManager';
import { PullRequestModel } from '../../github/pullRequestModel';
export class CommitNode extends TreeNode implements vscode.TreeItem {
public label: string;
public sha: string;
public collapsibleState: vscode.TreeItemCollapsibleState;
public iconPath: vscode.Uri | undefined;
public contextValue?: string;
constructor(
public parent: TreeNode | vscode.TreeView<TreeNode>,
private readonly pullRequestManager: PullRequestManager,
private readonly pullRequest: PullRequestModel,
private readonly commit: PullRequestsGetCommitsResponseItem,
private readonly comments: Comment[]
) {
super();
this.label = commit.commit.message;
this.sha = commit.sha;
this.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
let userIconUri: vscode.Uri | undefined;
try {
if (commit.author && commit.author.avatar_url) {
userIconUri = vscode.Uri.parse(`${commit.author.avatar_url}&s=${64}`);
}
} catch (_) {
// no-op
}
this.iconPath = userIconUri;
this.contextValue = 'commit';
}
getTreeItem(): vscode.TreeItem {
return this;
}
async getChildren(): Promise<TreeNode[]> {
const fileChanges = await this.pullRequestManager.getCommitChangedFiles(this.pullRequest, this.commit);
const fileChangeNodes = fileChanges.map(change => {
const matchingComments = this.comments.filter(comment => comment.path === change.filename && comment.originalCommitId === this.commit.sha);
const fileName = change.filename;
const uri = vscode.Uri.parse(path.join(`commit~${this.commit.sha.substr(0, 8)}`, fileName));
const fileChangeNode = new GitFileChangeNode(
this,
this.pullRequest,
getGitChangeType(change.status),
fileName,
undefined,
toReviewUri(uri, fileName, undefined, this.commit.sha, true, { base: false }),
toReviewUri(uri, fileName, undefined, this.commit.sha, true, { base: true }),
false,
[],
matchingComments,
this.commit.sha
);
fileChangeNode.command = {
title: 'View Changes',
command: 'pr.viewChanges',
arguments: [
fileChangeNode
]
};
return fileChangeNode;
});
return Promise.resolve(fileChangeNodes);
}
}