Skip to content

Commit

Permalink
feat: Added Custom Commit Message (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: GCaringi <giannicaringi94@gmail.com>
  • Loading branch information
GCaringi committed May 21, 2024
1 parent 20c297e commit 3773f8b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/helper/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
}
];
33 changes: 33 additions & 0 deletions src/helper/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,36 @@ export const push = async (showRes = true): Promise<IGitResult> => {
}
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;
}
}
5 changes: 3 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BUTTONS, LOADING_STYLE, SETTINGS_SCHEMA } from "./helper/constants";
import {
checkout,
commit,
commitMessage,
log,
pull,
pullRebase,
Expand Down Expand Up @@ -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 () {
Expand All @@ -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);
}
Expand Down

0 comments on commit 3773f8b

Please sign in to comment.