diff --git a/package.json b/package.json index dcb1512b79..660f35f1cb 100644 --- a/package.json +++ b/package.json @@ -870,6 +870,11 @@ "default": false, "description": "%githubPullRequests.showPullRequestNumberInTree.description%" }, + "githubPullRequests.showCommitShaInTree": { + "type": "boolean", + "default": false, + "description": "%githubPullRequests.showCommitShaInTree.description%" + }, "githubPullRequests.pullRequestAvatarDisplay": { "type": "string", "enum": [ diff --git a/package.nls.json b/package.nls.json index 1aaa2cf34c..51128db7f6 100644 --- a/package.nls.json +++ b/package.nls.json @@ -190,6 +190,7 @@ "githubPullRequests.focusedMode.multiDiff": "Show all diffs in the pull request. If there are no changes, show the overview.", "githubPullRequests.focusedMode.false": "Do not change the layout.", "githubPullRequests.showPullRequestNumberInTree.description": "Shows the pull request number in the tree view.", + "githubPullRequests.showCommitShaInTree.description": "Shows the abbreviated commit SHA in the tree view.", "githubPullRequests.labelCreated.description": "Group of labels that you want to add to the pull request automatically. Labels that don't exist in the repository won't be added.", "githubPullRequests.labelCreated.label.description": "Each string element is the value of label that you want to add.", "githubPullRequests.pullRequestAvatarDisplay.description": "Which icon to use in the pull request tree view", diff --git a/src/common/settingKeys.ts b/src/common/settingKeys.ts index 895378c9c3..527fa2592b 100644 --- a/src/common/settingKeys.ts +++ b/src/common/settingKeys.ts @@ -33,6 +33,7 @@ export const SHOW_CREATE_PULL_REQUEST_CANCEL_CONFIRMATION = 'showCreatePullReque export const QUICK_DIFF = 'quickDiff'; export const SET_AUTO_MERGE = 'setAutoMerge'; export const SHOW_PULL_REQUEST_NUMBER_IN_TREE = 'showPullRequestNumberInTree'; +export const SHOW_COMMIT_SHA_IN_TREE = 'showCommitShaInTree'; export const DEFAULT_MERGE_METHOD = 'defaultMergeMethod'; export const DEFAULT_DELETION_METHOD = 'defaultDeletionMethod'; export const SELECT_LOCAL_BRANCH = 'selectLocalBranch'; diff --git a/src/view/treeNodes/commitNode.ts b/src/view/treeNodes/commitNode.ts index ee95b34a12..3ae3f92664 100644 --- a/src/view/treeNodes/commitNode.ts +++ b/src/view/treeNodes/commitNode.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import { getGitChangeType } from '../../common/diffHunk'; -import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE } from '../../common/settingKeys'; +import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE, SHOW_COMMIT_SHA_IN_TREE } from '../../common/settingKeys'; import { DataUri, reviewPath, toReviewUri } from '../../common/uri'; import { dateFromNow } from '../../common/utils'; import { OctokitCommon } from '../../github/common'; @@ -35,7 +35,16 @@ export class CommitNode extends TreeNode implements vscode.TreeItem { this.sha = commit.sha; this.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed; this.contextValue = 'commit'; - this.description = commit.commit.author?.date ? dateFromNow(commit.commit.author.date) : undefined; + } + + private _getDescription(): string | undefined { + const date = this.commit.commit.author?.date ? dateFromNow(this.commit.commit.author.date) : undefined; + if (!vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(SHOW_COMMIT_SHA_IN_TREE, false)) { + return date; + } + const shortSha = this.sha.substring(0, 7); + return date ? `${shortSha} ยท ${date}` : shortSha; + } async getTreeItem(): Promise { @@ -48,6 +57,7 @@ export class CommitNode extends TreeNode implements vscode.TreeItem { this.iconPath = (await DataUri.avatarCirclesAsImageDataUris(this.pullRequestManager.context, [author], 16, 16))[0]; } } + this.description = this._getDescription(); return this; } diff --git a/src/view/treeNodes/commitsCategoryNode.ts b/src/view/treeNodes/commitsCategoryNode.ts index 7a0fb197ca..43bbe9e2f2 100644 --- a/src/view/treeNodes/commitsCategoryNode.ts +++ b/src/view/treeNodes/commitsCategoryNode.ts @@ -7,6 +7,7 @@ import * as vscode from 'vscode'; import { CommitNode } from './commitNode'; import { TreeNode, TreeNodeParent } from './treeNode'; import Logger, { PR_TREE } from '../../common/logger'; +import { PR_SETTINGS_NAMESPACE, SHOW_COMMIT_SHA_IN_TREE } from '../../common/settingKeys'; import { createCommitsNodeUri } from '../../common/uri'; import { FolderRepositoryManager } from '../../github/folderRepositoryManager'; import { PullRequestModel } from '../../github/pullRequestModel'; @@ -42,6 +43,12 @@ export class CommitsNode extends TreeNode implements vscode.TreeItem { this.refresh(this); } })); + this.childrenDisposables.push(vscode.workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${SHOW_COMMIT_SHA_IN_TREE}`)) { + Logger.appendLine(`Commit SHA display setting has changed, refreshing Commits node`, PR_TREE); + this.refresh(this); + } + })); } getTreeItem(): vscode.TreeItem {