diff --git a/src/helper/constants.ts b/src/helper/constants.ts index 0c1fbac..1de3088 100644 --- a/src/helper/constants.ts +++ b/src/helper/constants.ts @@ -143,4 +143,20 @@ export const SETTINGS_SCHEMA: SettingSchemaDesc[] = [ default: false, description: "Auto push when logseq hide", }, + { + key: "typeCommitMessage", + title: "Type Commit Message", + type: "enum", + default: "Default Message With Date", + description: "Type of commit message to use", + enumPicker: "select", + enumChoices: ['Custom Message' , 'Default Message', 'Custom Message With Date', 'Default Message With Date'], + }, + { + key: "customCommitMessage", + title: "Custom Commit Message", + type: "string", + default: "", + description: "Custom commit message for plugin (valid only if commit message is set to Custom Message)", + } ]; diff --git a/src/helper/git.ts b/src/helper/git.ts index 3cc6eaa..a3e0468 100644 --- a/src/helper/git.ts +++ b/src/helper/git.ts @@ -140,3 +140,36 @@ export const push = async (showRes = true): Promise => { } return res } + + +/** + * Returns the commit message based on the selected commit message type in the logseq settings. + * @returns The commit message. + */ +export const commitMessage = () : string => { + + let defaultMessage = "[logseq-plugin-git:commit]"; + + switch (logseq.settings?.typeCommitMessage as string) { + case "Default Message": + return defaultMessage; + case "Default Message With Date": + return defaultMessage + " " + new Date().toISOString(); + case "Custom Message": + let customMessage = logseq.settings?.customCommitMessage as string; + if (customMessage.trim() === "") { + return defaultMessage; + } else { + return customMessage; + } + case "Custom Message With Date": + let customMessageWithDate = logseq.settings?.customCommitMessage as string; + if (customMessageWithDate.trim() === "") { + return defaultMessage + " " + new Date().toISOString(); + } else { + return customMessageWithDate + " " + new Date().toISOString(); + } + default: + return defaultMessage; + } +} diff --git a/src/main.tsx b/src/main.tsx index 3a6192b..bcdd691 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -6,6 +6,7 @@ import { BUTTONS, LOADING_STYLE, SETTINGS_SCHEMA } from "./helper/constants"; import { checkout, commit, + commitMessage, log, pull, pullRebase, @@ -77,7 +78,7 @@ if (isDevelopment) { }), commit: debounce(async function () { hidePopup(); - await commit(true, `[logseq-plugin-git:commit] ${new Date().toISOString()}`); + await commit(true, commitMessage()); checkStatus(); }), push: debounce(async function () { @@ -95,7 +96,7 @@ if (isDevelopment) { if (changed) { const res = await commit( true, - `[logseq-plugin-git:commit] ${new Date().toISOString()}` + commitMessage() ); if (res.exitCode === 0) await push(true); }