-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathautofill.ts
51 lines (43 loc) · 1.54 KB
/
autofill.ts
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
/**
* Autofill module.
*/
import * as vscode from "vscode";
import { Repository } from "./api/git";
import { getChanges } from "./git/cli";
import { getCommitTemplateValue } from "./git/commitTemplate";
import { getCommitMsg, setCommitMsg } from "./gitExtension";
import { generateMsg } from "./prepareCommitMsg";
export const NO_LINES_MSG = `\
Unable to generate message as no changes files can be seen.
Try saving your files or stage any new (untracked) files.\
`;
/**
* Generate and fill a commit message in the Git extenside sidebar.
*
* Steps:
*
* 1. Read git command output and the message in the Git Extension commit message box.
* 2. Generate a message.
* 3. Push message value to the commit message box.
*
* New functionality in the extension - the commit message file is read
* explicitly and the content used. Any content in the Git pane that was the
* "old message" is ignored then.
*
* This function is based on `prefixCommit` from the `git-prefix` extension.
*/
export async function makeAndFillCommitMsg(repository: Repository) {
const fileChanges = await getChanges();
console.debug("diff-index:", fileChanges);
if (!fileChanges.length) {
vscode.window.showErrorMessage(NO_LINES_MSG);
return;
}
const oldMsg = getCommitMsg(repository);
console.debug("Old message: ", oldMsg);
const newMsg = generateMsg(fileChanges, oldMsg);
console.debug("New message: ", newMsg);
const commitMessageValue = await getCommitTemplateValue();
console.debug({ commitMessageValue });
setCommitMsg(repository, newMsg);
}