Add ability to set commit messages when editing functions

This commit is contained in:
Peter Stockings
2025-12-02 20:36:55 +11:00
parent 2253c8f7a7
commit 46339cc4cf
6 changed files with 63 additions and 3 deletions

View File

@@ -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