diff --git a/db.py b/db.py index 73604fc..a844ce8 100644 --- a/db.py +++ b/db.py @@ -184,7 +184,7 @@ ORDER BY invocation_time DESC""", [http_function_id]) 'UPDATE users SET theme_preference=%s WHERE id=%s', [theme, user_id], commit=True) def get_http_function_history(self, function_id): http_function_history = self.execute( - 'SELECT version_id, http_function_id, script_content, version_number, updated_at FROM http_functions_versions WHERE http_function_id=%s ORDER BY version_number DESC', [function_id]) + 'SELECT version_id, http_function_id, script_content, version_number, updated_at, commit_message FROM http_functions_versions WHERE http_function_id=%s ORDER BY version_number DESC', [function_id]) return http_function_history def create_api_key(self, user_id, name, key, scopes, rate_limit_count=None, rate_limit_period=None): diff --git a/migrations/006_add_commit_messages.sql b/migrations/006_add_commit_messages.sql new file mode 100644 index 0000000..2c7a135 --- /dev/null +++ b/migrations/006_add_commit_messages.sql @@ -0,0 +1,5 @@ +ALTER TABLE http_functions_versions +ADD COLUMN IF NOT EXISTS commit_message TEXT; + +ALTER TABLE timer_function_versions +ADD COLUMN IF NOT EXISTS commit_message TEXT; diff --git a/routes/http.py b/routes/http.py index d45e07c..76f60ce 100644 --- a/routes/http.py +++ b/routes/http.py @@ -222,6 +222,7 @@ def edit(function_id): log_response = request.json.get("log_response") runtime = request.json.get("runtime", "node") description = request.json.get("description", "") + commit_message = request.json.get("commit_message", "") updated_version = db.edit_http_function( user_id, @@ -237,6 +238,22 @@ def edit(function_id): description ) + # Update the commit message for the newly created version + # Note: The database trigger creates a new version after the UPDATE, + # so we need to get the latest version number + if commit_message: + latest_version = db.execute( + "SELECT MAX(version_number) as version_number FROM http_functions_versions WHERE http_function_id = %s", + [function_id], + one=True + ) + if latest_version: + db.execute( + "UPDATE http_functions_versions SET commit_message = %s WHERE http_function_id = %s AND version_number = %s", + [commit_message, function_id, latest_version['version_number']], + commit=True + ) + return {"status": "success", "message": f"{name} updated"} except Exception as e: print(e) @@ -331,7 +348,7 @@ def history(function_id): # Fetch all versions versions = db.execute( """ - SELECT version_number, script_content AS script, updated_at AS versioned_at + SELECT version_number, script_content AS script, updated_at AS versioned_at, commit_message FROM http_functions_versions WHERE http_function_id = %s ORDER BY version_number DESC diff --git a/routes/timer.py b/routes/timer.py index 4710207..7f7fbdc 100644 --- a/routes/timer.py +++ b/routes/timer.py @@ -354,6 +354,7 @@ def edit(function_id): data = request.json trigger_type = data.get('trigger_type') runtime = data.get('runtime', 'node') + commit_message = data.get('commit_message', '') # Validate trigger type if trigger_type not in ('interval', 'date', 'cron'): @@ -415,6 +416,22 @@ def edit(function_id): current_user.id ], commit=True) + + # Update the commit message for the newly created version + # Note: The database trigger creates a new version after the UPDATE, + # so we need to get the latest version number + if commit_message: + latest_version = db.execute( + "SELECT MAX(version_number) as version_number FROM timer_function_versions WHERE timer_function_id = %s", + [function_id], + one=True + ) + if latest_version: + db.execute( + "UPDATE timer_function_versions SET commit_message = %s WHERE timer_function_id = %s AND version_number = %s", + [commit_message, function_id, latest_version['version_number']], + commit=True + ) return jsonify({ "status": "success", @@ -572,7 +589,7 @@ def history(function_id): # Fetch all versions versions = db.execute(""" - SELECT version_number, script, versioned_at + SELECT version_number, script, versioned_at, commit_message FROM timer_function_versions WHERE timer_function_id = %s ORDER BY version_number DESC diff --git a/static/js/mithril/FunctionHistory.js b/static/js/mithril/FunctionHistory.js index 3116c24..33b1cbc 100644 --- a/static/js/mithril/FunctionHistory.js +++ b/static/js/mithril/FunctionHistory.js @@ -65,6 +65,10 @@ const FunctionHistory = { "div.text-sm.text-gray-600.dark:text-gray-400", new Date(version.versioned_at).toLocaleString() ), + version.commit_message && m( + "div.text-xs.text-gray-500.dark:text-gray-500.italic.mt-1", + version.commit_message + ), ] ); }) diff --git a/static/js/mithril/editor.js b/static/js/mithril/editor.js index 0bd5900..482e9bb 100644 --- a/static/js/mithril/editor.js +++ b/static/js/mithril/editor.js @@ -66,6 +66,9 @@ const Editor = { this.aiModalOpen = false; this.aiModalContent = ""; this.aiModalTitle = ""; + + // Commit Message + this.commitMessage = ""; }, oncreate() { @@ -248,6 +251,7 @@ const Editor = { is_enabled: this.isEnabled, description: this.description, runtime: this.runtime, + commit_message: this.commitMessage, } : { name: this.name, @@ -259,6 +263,7 @@ const Editor = { log_response: this.logResponse, runtime: this.runtime, description: this.description, + commit_message: this.commitMessage, }; const response = await m.request({ @@ -946,6 +951,18 @@ const Editor = { ]), ], + // Commit Message Input (only show for edit mode) + this.isEdit && m("div", { class: "flex flex-col space-y-2 pt-2" }, [ + m("label", { class: "text-sm font-medium text-gray-700 dark:text-gray-300" }, "Commit Message (Optional)"), + m("textarea", { + class: "w-full p-2 border rounded bg-white dark:bg-gray-700 dark:border-gray-600 text-sm", + rows: 2, + placeholder: "Describe the changes you made...", + value: this.commitMessage, + oninput: (e) => (this.commitMessage = e.target.value) + }) + ]), + m( "div", { class: "flex items-center justify-end space-x-3 pt-2" },