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
99 lines (89 loc) · 3.02 KB
/
Copy pathcommitNode.ts
File metadata and controls
99 lines (89 loc) · 3.02 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
88
89
90
91
92
93
94
95
96
97
98
99
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as vscode from 'vscode';
import { IComment } from '../../common/comment';
import { getGitChangeType } from '../../common/diffHunk';
import { toReviewUri } from '../../common/uri';
import { OctokitCommon } from '../../github/common';
import { FolderRepositoryManager } from '../../github/folderRepositoryManager';
import { PullRequestModel } from '../../github/pullRequestModel';
import { GitFileChangeNode } from './fileChangeNode';
import { TreeNode, TreeNodeParent } from './treeNode';
export class CommitNode extends TreeNode implements vscode.TreeItem {
public sha: string;
public collapsibleState: vscode.TreeItemCollapsibleState;
public iconPath: vscode.Uri | undefined;
public contextValue?: string;
constructor(
public parent: TreeNodeParent,
private readonly pullRequestManager: FolderRepositoryManager,
private readonly pullRequest: PullRequestModel,
private readonly commit: OctokitCommon.PullsListCommitsResponseItem,
private readonly comments: IComment[],
private readonly isCurrent: boolean
) {
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.pullRequest.getCommitChangedFiles(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.posix.join(`commit~${this.commit.sha.substr(0, 8)}`, fileName));
const fileChangeNode = new GitFileChangeNode(
this,
this.pullRequestManager,
this.pullRequest,
getGitChangeType(change.status!),
fileName,
undefined,
toReviewUri(
uri,
fileName,
undefined,
this.commit.sha,
true,
{ base: false },
this.pullRequestManager.repository.rootUri,
),
toReviewUri(
uri,
fileName,
undefined,
this.commit.sha,
true,
{ base: true },
this.pullRequestManager.repository.rootUri,
),
[],
matchingComments,
this.commit.sha,
this.isCurrent
);
fileChangeNode.useViewChangesCommand();
return fileChangeNode;
});
return Promise.resolve(fileChangeNodes);
}
}