Add ability to set commit messages when editing functions
This commit is contained in:
2
db.py
2
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)
|
'UPDATE users SET theme_preference=%s WHERE id=%s', [theme, user_id], commit=True)
|
||||||
def get_http_function_history(self, function_id):
|
def get_http_function_history(self, function_id):
|
||||||
http_function_history = self.execute(
|
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
|
return http_function_history
|
||||||
|
|
||||||
def create_api_key(self, user_id, name, key, scopes, rate_limit_count=None, rate_limit_period=None):
|
def create_api_key(self, user_id, name, key, scopes, rate_limit_count=None, rate_limit_period=None):
|
||||||
|
|||||||
5
migrations/006_add_commit_messages.sql
Normal file
5
migrations/006_add_commit_messages.sql
Normal file
@@ -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;
|
||||||
@@ -222,6 +222,7 @@ def edit(function_id):
|
|||||||
log_response = request.json.get("log_response")
|
log_response = request.json.get("log_response")
|
||||||
runtime = request.json.get("runtime", "node")
|
runtime = request.json.get("runtime", "node")
|
||||||
description = request.json.get("description", "")
|
description = request.json.get("description", "")
|
||||||
|
commit_message = request.json.get("commit_message", "")
|
||||||
|
|
||||||
updated_version = db.edit_http_function(
|
updated_version = db.edit_http_function(
|
||||||
user_id,
|
user_id,
|
||||||
@@ -237,6 +238,22 @@ def edit(function_id):
|
|||||||
description
|
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"}
|
return {"status": "success", "message": f"{name} updated"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
@@ -331,7 +348,7 @@ def history(function_id):
|
|||||||
# Fetch all versions
|
# Fetch all versions
|
||||||
versions = db.execute(
|
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
|
FROM http_functions_versions
|
||||||
WHERE http_function_id = %s
|
WHERE http_function_id = %s
|
||||||
ORDER BY version_number DESC
|
ORDER BY version_number DESC
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ def edit(function_id):
|
|||||||
data = request.json
|
data = request.json
|
||||||
trigger_type = data.get('trigger_type')
|
trigger_type = data.get('trigger_type')
|
||||||
runtime = data.get('runtime', 'node')
|
runtime = data.get('runtime', 'node')
|
||||||
|
commit_message = data.get('commit_message', '')
|
||||||
|
|
||||||
# Validate trigger type
|
# Validate trigger type
|
||||||
if trigger_type not in ('interval', 'date', 'cron'):
|
if trigger_type not in ('interval', 'date', 'cron'):
|
||||||
@@ -416,6 +417,22 @@ def edit(function_id):
|
|||||||
],
|
],
|
||||||
commit=True)
|
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({
|
return jsonify({
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"message": "Timer function updated successfully"
|
"message": "Timer function updated successfully"
|
||||||
@@ -572,7 +589,7 @@ def history(function_id):
|
|||||||
|
|
||||||
# Fetch all versions
|
# Fetch all versions
|
||||||
versions = db.execute("""
|
versions = db.execute("""
|
||||||
SELECT version_number, script, versioned_at
|
SELECT version_number, script, versioned_at, commit_message
|
||||||
FROM timer_function_versions
|
FROM timer_function_versions
|
||||||
WHERE timer_function_id = %s
|
WHERE timer_function_id = %s
|
||||||
ORDER BY version_number DESC
|
ORDER BY version_number DESC
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ const FunctionHistory = {
|
|||||||
"div.text-sm.text-gray-600.dark:text-gray-400",
|
"div.text-sm.text-gray-600.dark:text-gray-400",
|
||||||
new Date(version.versioned_at).toLocaleString()
|
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
|
||||||
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ const Editor = {
|
|||||||
this.aiModalOpen = false;
|
this.aiModalOpen = false;
|
||||||
this.aiModalContent = "";
|
this.aiModalContent = "";
|
||||||
this.aiModalTitle = "";
|
this.aiModalTitle = "";
|
||||||
|
|
||||||
|
// Commit Message
|
||||||
|
this.commitMessage = "";
|
||||||
},
|
},
|
||||||
|
|
||||||
oncreate() {
|
oncreate() {
|
||||||
@@ -248,6 +251,7 @@ const Editor = {
|
|||||||
is_enabled: this.isEnabled,
|
is_enabled: this.isEnabled,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
runtime: this.runtime,
|
runtime: this.runtime,
|
||||||
|
commit_message: this.commitMessage,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
@@ -259,6 +263,7 @@ const Editor = {
|
|||||||
log_response: this.logResponse,
|
log_response: this.logResponse,
|
||||||
runtime: this.runtime,
|
runtime: this.runtime,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
|
commit_message: this.commitMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await m.request({
|
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(
|
m(
|
||||||
"div",
|
"div",
|
||||||
{ class: "flex items-center justify-end space-x-3 pt-2" },
|
{ class: "flex items-center justify-end space-x-3 pt-2" },
|
||||||
|
|||||||
Reference in New Issue
Block a user