Skip to content

Commit bf284a9

Browse files
committed
added default message to be last commit message
1 parent a528a4a commit bf284a9

4 files changed

Lines changed: 51 additions & 110 deletions

File tree

src/commands/commit/shareProjectUpdate.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from "vscode";
2+
import { API } from "../../@types/git";
23
import { CommitAPI } from "../../commitAPI";
34
import { getWebviewContent } from "../../utils";
45

@@ -43,7 +44,7 @@ const shareProjectUpdate = (context: vscode.ExtensionContext) => {
4344
}
4445

4546
// Show list of projects and get the selection
46-
const selectedProjectTitle = await vscode.window.showQuickPick(
47+
let selectedProjectTitle = await vscode.window.showQuickPick(
4748
projects.map((project: Project) => {
4849
return (
4950
project.title +
@@ -55,14 +56,16 @@ const shareProjectUpdate = (context: vscode.ExtensionContext) => {
5556
}
5657
);
5758

58-
if (!selectedProjectTitle) {
59+
if (!selectedProjectTitle || selectedProjectTitle === undefined) {
5960
return;
6061
}
6162

63+
// Remove (Default) from the title
64+
selectedProjectTitle = selectedProjectTitle.replace(" (Default)", "");
65+
6266
// Get the Project Object
6367
const selectedProject: Project | undefined = projects.find(
64-
(project: { title: string }) =>
65-
project.title === selectedProjectTitle.replace("(Default)", "")
68+
(project: { title: string }) => project.title === selectedProjectTitle
6669
);
6770

6871
if (!selectedProject || selectedProject === undefined) {
@@ -82,9 +85,10 @@ const shareProjectUpdate = (context: vscode.ExtensionContext) => {
8285

8386
// Send Project ID to the WebView
8487
shareProjectUpdatePanel.webview.postMessage({
85-
command: "setProjectId",
88+
command: "setWebViewProject",
8689
data: JSON.stringify({
8790
projectId: selectedProject.id,
91+
lastCommitMessage: await getCommitMessage(context),
8892
}),
8993
});
9094

@@ -128,4 +132,33 @@ const processWebviewMessage = async (
128132
}
129133
};
130134

135+
const getCommitMessage = async (context: vscode.ExtensionContext) => {
136+
const gitAPI = context.workspaceState.get<API>("gitAPI");
137+
if (!gitAPI) {
138+
return;
139+
}
140+
141+
// Get workspace folder
142+
const workspaceFolders = vscode.workspace.workspaceFolders;
143+
if (!workspaceFolders) {
144+
return;
145+
}
146+
147+
// Get root path
148+
const rootPath = workspaceFolders[0].uri.fsPath;
149+
150+
// Get repository
151+
const repository = gitAPI.repositories.find(
152+
(repo) => repo.rootUri.fsPath === rootPath
153+
);
154+
155+
if (!repository) {
156+
return;
157+
}
158+
159+
// Get commit message
160+
const commit = await repository.getCommit("HEAD");
161+
return commit?.message || "";
162+
};
163+
131164
export default shareProjectUpdate;

src/extension.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -149,39 +149,6 @@ const getGitExtension = async (context: vscode.ExtensionContext) => {
149149
context.workspaceState.update("gitAPI", gitAPI);
150150
};
151151

152-
const getCommitMessage = async (context: vscode.ExtensionContext) => {
153-
const gitAPI = context.workspaceState.get<API>("gitAPI");
154-
if (!gitAPI) {
155-
return;
156-
}
157-
158-
// Get workspace folder
159-
const workspaceFolders = vscode.workspace.workspaceFolders;
160-
if (!workspaceFolders) {
161-
return;
162-
}
163-
164-
// Get root path
165-
const rootPath = workspaceFolders[0].uri.fsPath;
166-
167-
// Get repository
168-
const repository = gitAPI.repositories.find(
169-
(repo) => repo.rootUri.fsPath === rootPath
170-
);
171-
172-
if (!repository) {
173-
return;
174-
}
175-
176-
// Get commit message
177-
const commit = await repository.getCommit("HEAD");
178-
179-
const commitMEssage = commit?.message;
180-
181-
// const commitMessage: string | undefined = repository.state.HEAD?.commit;
182-
return "commitMessage";
183-
};
184-
185152
// This method is called when your extension is deactivated
186153
export function deactivate() {
187154
// Get extension context

static/webview/index.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
</head>
1010

1111
<body class="container bg-transparent text-white">
12-
<h1>Update Project</h1>
12+
<h1 class="d-flex justify-content-center py-2">Add Update Project</h1>
13+
<p class="d-flex justify-content-center fst-italic">Update field is pre populated with last commit message from local git history</p>
1314
<!-- Markdown Editor and Preview -->
1415
<div class="d-flex justify-content-between">
15-
<textarea class="px-2 py-1 rounded" style="width: 47%" name="update-input" id="update-input" rows="20"></textarea>
16+
<textarea class="px-2 py-1 rounded" style="width: 47%" id="update-input" rows="20"></textarea>
1617
<p class="px-2 py-1 rounded bg-light h-auto m-0 overflow-auto text-black" style="width: 47%" id="update-preview"></p>
1718
</div>
1819

@@ -28,8 +29,13 @@ <h1>Update Project</h1>
2829
const vscode = acquireVsCodeApi();
2930
var converter = new showdown.Converter();
3031
let projectId = "";
32+
let lastCommitMessage = "";
3133

3234
window.onload = () => {
35+
console.log("Loading")
36+
// Set the value of the input field
37+
const updateInput = document.getElementById("update-input");
38+
updateInput.value = lastCommitMessage;
3339
// Get focus on the input field
3440
document.getElementById("update-input").focus();
3541
};
@@ -76,10 +82,14 @@ <h1>Update Project</h1>
7682
const data = eventData.data;
7783

7884
switch (command) {
79-
case "setProjectId":
85+
case "setWebViewProject":
8086
// Update the project id
8187
const parsedData = JSON.parse(data);
8288
projectId = parsedData.projectId;
89+
lastCommitMessage = parsedData.lastCommitMessage;
90+
// Set the value of the input field
91+
const updateInput = document.getElementById("update-input");
92+
updateInput.value = lastCommitMessage;
8393
break;
8494
default:
8595
break;

static/webview/index.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)