Skip to content

Commit 28ba6ae

Browse files
authored
Merge pull request #879 from JeffreyCA/copy-commit-hash
Support copying commit hash from commit list
2 parents 52e45b6 + cd6351c commit 28ba6ae

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
"title": "Open File in GitHub",
193193
"category": "GitHub Pull Requests"
194194
},
195+
{
196+
"command": "pr.copyCommitHash",
197+
"title": "Copy Commit Hash",
198+
"category": "GitHub Pull Requests"
199+
},
195200
{
196201
"command": "pr.openDiffView",
197202
"title": "Open Diff View",
@@ -335,6 +340,10 @@
335340
{
336341
"command": "pr.signinAndRefreshList",
337342
"when": "false"
343+
},
344+
{
345+
"command": "pr.copyCommitHash",
346+
"when": "false"
338347
}
339348
],
340349
"view/title": [
@@ -379,6 +388,10 @@
379388
"command": "pr.openFileInGitHub",
380389
"when": "view =~ /(pr|prStatus)/ && viewItem =~ /filechange/"
381390
},
391+
{
392+
"command": "pr.copyCommitHash",
393+
"when": "view == prStatus && viewItem =~ /commit/"
394+
},
382395
{
383396
"command": "pr.openDescriptionToTheSide",
384397
"group": "inline",

src/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ReviewManager } from './view/reviewManager';
1010
import { PullRequestOverviewPanel } from './github/pullRequestOverview';
1111
import { fromReviewUri, ReviewUriParams } from './common/uri';
1212
import { GitFileChangeNode, InMemFileChangeNode } from './view/treeNodes/fileChangeNode';
13+
import { CommitNode } from './view/treeNodes/commitNode';
1314
import { PRNode } from './view/treeNodes/pullRequestNode';
1415
import { ITelemetry, PullRequest } from './github/interface';
1516
import { formatError } from './common/utils';
@@ -132,6 +133,10 @@ export function registerCommands(context: vscode.ExtensionContext, prManager: Pu
132133
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(e.blobUrl!));
133134
}));
134135

136+
context.subscriptions.push(vscode.commands.registerCommand('pr.copyCommitHash', (e: CommitNode) => {
137+
vscode.env.clipboard.writeText(e.sha);
138+
}));
139+
135140
context.subscriptions.push(vscode.commands.registerCommand('pr.openDiffView', (fileChangeNode: GitFileChangeNode | InMemFileChangeNode) => {
136141
const parentFilePath = fileChangeNode.parentFilePath;
137142
const filePath = fileChangeNode.filePath;

src/view/treeNodes/commitNode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import { PullRequestModel } from '../../github/pullRequestModel';
1616

1717
export class CommitNode extends TreeNode implements vscode.TreeItem {
1818
public label: string;
19+
public sha: string;
1920
public collapsibleState: vscode.TreeItemCollapsibleState;
2021
public iconPath: vscode.Uri | undefined;
22+
public contextValue?: string;
2123

2224
constructor(
2325
public parent: TreeNode | vscode.TreeView<TreeNode>,
@@ -28,8 +30,8 @@ export class CommitNode extends TreeNode implements vscode.TreeItem {
2830
) {
2931
super();
3032
this.label = commit.commit.message;
33+
this.sha = commit.sha;
3134
this.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
32-
3335
let userIconUri: vscode.Uri | undefined;
3436
try {
3537
if (commit.author && commit.author.avatar_url) {
@@ -40,6 +42,7 @@ export class CommitNode extends TreeNode implements vscode.TreeItem {
4042
}
4143

4244
this.iconPath = userIconUri;
45+
this.contextValue = 'commit';
4346
}
4447

4548
getTreeItem(): vscode.TreeItem {

0 commit comments

Comments
 (0)