Skip to content

Commit cd260be

Browse files
bobo yangbobo yang
authored andcommitted
feat: Add toggle for public workflow updates
- Implement config-based control for workflow updates - Check for valid API keys before updating workflows - Add conditional logic to skip updates if disabled
1 parent 37d6f09 commit cd260be

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

devchat/_service/route/workflows.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,36 @@ def get_config():
5959

6060
@router.post("/update", response_model=response.UpdateWorkflows)
6161
def update_workflows():
62-
base_path = Path(WORKFLOWS_BASE)
63-
64-
if HAS_GIT:
65-
updated, message = update_by_git(base_path)
62+
chat_config_path = Path(CHAT_DIR) / CHAT_CONFIG_FILENAME
63+
64+
if chat_config_path.exists():
65+
with open(chat_config_path, "r", encoding="utf-8") as file:
66+
chat_config = yaml.safe_load(file)
67+
68+
providers = chat_config.get("providers", {})
69+
devchat_api_key = providers.get("devchat", {}).get("api_key", "")
70+
openai_api_key = providers.get("openai", {}).get("api_key", "")
71+
72+
if devchat_api_key or openai_api_key:
73+
update_public_workflow = chat_config.get("update_public_workflow", True)
74+
75+
if update_public_workflow:
76+
base_path = Path(WORKFLOWS_BASE)
77+
78+
if HAS_GIT:
79+
updated, message = update_by_git(base_path)
80+
else:
81+
updated, message = update_by_zip(base_path)
82+
83+
copy_workflows_usr()
84+
85+
return response.UpdateWorkflows(updated=updated, message=message)
86+
else:
87+
return response.UpdateWorkflows(updated=False, message="Workflow update has been ignored due to configuration settings.")
88+
else:
89+
return response.UpdateWorkflows(updated=False, message="No valid API key found, workflow update ignored.")
6690
else:
67-
updated, message = update_by_zip(base_path)
68-
69-
copy_workflows_usr()
70-
71-
return response.UpdateWorkflows(updated=updated, message=message)
72-
91+
return response.UpdateWorkflows(updated=False, message="Configuration file not found, workflow update ignored.")
7392

7493
@router.post("/custom_update", response_model=response.UpdateWorkflows)
7594
def update_custom_workflows():

0 commit comments

Comments
 (0)