mirror of
https://github.com/johndoe6345789/AutoMetabuilder.git
synced 2026-04-24 13:54:59 +00:00
Add multilingual support by externalizing messages to JSON files; update main.py and GitHub integration to use loaded messages for better localization.
This commit is contained in:
@@ -2,3 +2,4 @@ GITHUB_TOKEN=token123
|
||||
GITHUB_REPOSITORY=owner/repo
|
||||
RAW_PROMPT_URL=https://raw.githubusercontent.com/johndoe6345789/metabuilder/main/getonwithit.prompt.yml
|
||||
GITHUB_MODELS_ENDPOINT=https://models.github.ai/inference
|
||||
APP_LANG=en # Supported: en, es, fr, nl, pirate
|
||||
|
||||
@@ -4,6 +4,17 @@ from github.Repository import Repository
|
||||
from github.Issue import Issue
|
||||
from github.PullRequest import PullRequest
|
||||
|
||||
import json
|
||||
|
||||
def load_messages():
|
||||
lang = os.environ.get("APP_LANG", "en")
|
||||
messages_path = os.path.join(os.path.dirname(__file__), f"messages_{lang}.json")
|
||||
if not os.path.exists(messages_path):
|
||||
# Fallback to English if the requested language file doesn't exist
|
||||
messages_path = os.path.join(os.path.dirname(__file__), "messages_en.json")
|
||||
with open(messages_path, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
class GitHubIntegration:
|
||||
def __init__(self, token: str, repo_name: str):
|
||||
self.github = Github(token)
|
||||
@@ -30,5 +41,6 @@ def get_repo_name_from_env() -> str:
|
||||
repo_name = os.environ.get("GITHUB_REPOSITORY")
|
||||
if not repo_name:
|
||||
# Fallback or error
|
||||
raise ValueError("GITHUB_REPOSITORY environment variable not set")
|
||||
msgs = load_messages()
|
||||
raise ValueError(msgs["error_github_repo_missing"])
|
||||
return repo_name
|
||||
|
||||
@@ -17,19 +17,29 @@ def load_prompt_yaml(url: str, token: str) -> dict:
|
||||
r.raise_for_status()
|
||||
return yaml.safe_load(r.text)
|
||||
|
||||
def load_messages():
|
||||
lang = os.environ.get("APP_LANG", "en")
|
||||
messages_path = os.path.join(os.path.dirname(__file__), f"messages_{lang}.json")
|
||||
if not os.path.exists(messages_path):
|
||||
# Fallback to English if the requested language file doesn't exist
|
||||
messages_path = os.path.join(os.path.dirname(__file__), "messages_en.json")
|
||||
with open(messages_path, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
def main():
|
||||
msgs = load_messages()
|
||||
token = os.environ.get("GITHUB_TOKEN")
|
||||
if not token:
|
||||
print("Error: GITHUB_TOKEN environment variable not set.")
|
||||
print(msgs["error_github_token_missing"])
|
||||
return
|
||||
|
||||
# Initialize GitHub Integration
|
||||
try:
|
||||
repo_name = get_repo_name_from_env()
|
||||
gh = GitHubIntegration(token, repo_name)
|
||||
print(f"Integrated with repository: {repo_name}")
|
||||
print(msgs["info_integrated_repo"].format(repo_name=repo_name))
|
||||
except Exception as e:
|
||||
print(f"Warning: GitHub integration failed: {e}")
|
||||
print(msgs["warn_github_init_failed"].format(error=e))
|
||||
gh = None
|
||||
|
||||
endpoint = os.environ.get("GITHUB_MODELS_ENDPOINT", DEFAULT_ENDPOINT)
|
||||
@@ -57,20 +67,20 @@ def main():
|
||||
issues = gh.get_open_issues()
|
||||
issue_list = "\n".join([f"- #{i.number}: {i.title}" for i in issues[:5]])
|
||||
if issue_list:
|
||||
sdlc_context += f"\nOpen Issues:\n{issue_list}"
|
||||
sdlc_context += f"\n{msgs['open_issues_label']}\n{issue_list}"
|
||||
|
||||
prs = gh.get_pull_requests()
|
||||
pr_list = "\n".join([f"- #{p.number}: {p.title}" for p in prs[:5]])
|
||||
if pr_list:
|
||||
sdlc_context += f"\nOpen Pull Requests:\n{pr_list}"
|
||||
sdlc_context += f"\n{msgs['open_prs_label']}\n{pr_list}"
|
||||
except Exception as e:
|
||||
print(f"Error fetching SDLC context: {e}")
|
||||
print(msgs["error_sdlc_context"].format(error=e))
|
||||
|
||||
if sdlc_context:
|
||||
messages.append({"role": "system", "content": f"SDLC Context:{sdlc_context}"})
|
||||
messages.append({"role": "system", "content": f"{msgs['sdlc_context_label']}{sdlc_context}"})
|
||||
|
||||
# Add runtime request
|
||||
messages.append({"role": "user", "content": "What should I do next?"})
|
||||
messages.append({"role": "user", "content": msgs["user_next_step"]})
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model=model,
|
||||
@@ -82,7 +92,7 @@ def main():
|
||||
)
|
||||
|
||||
response_message = response.choices[0].message
|
||||
print(response_message.content if response_message.content else "Tool call requested...")
|
||||
print(response_message.content if response_message.content else msgs["info_tool_call_requested"])
|
||||
|
||||
# Handle tool calls
|
||||
if response_message.tool_calls:
|
||||
@@ -92,17 +102,17 @@ def main():
|
||||
|
||||
if function_name == "create_branch":
|
||||
if gh:
|
||||
print(f"Executing: create_branch({args})")
|
||||
print(msgs["info_executing_create_branch"].format(args=args))
|
||||
gh.create_branch(**args)
|
||||
else:
|
||||
print("Error: GitHub integration not available for tool call.")
|
||||
print(msgs["error_github_not_available"])
|
||||
|
||||
elif function_name == "create_pull_request":
|
||||
if gh:
|
||||
print(f"Executing: create_pull_request({args})")
|
||||
print(msgs["info_executing_create_pr"].format(args=args))
|
||||
gh.create_pull_request(**args)
|
||||
else:
|
||||
print("Error: GitHub integration not available for tool call.")
|
||||
print(msgs["error_github_not_available"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
15
src/autometabuilder/messages_en.json
Normal file
15
src/autometabuilder/messages_en.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"error_github_token_missing": "Error: GITHUB_TOKEN environment variable not set.",
|
||||
"info_integrated_repo": "Integrated with repository: {repo_name}",
|
||||
"warn_github_init_failed": "Warning: GitHub integration failed: {error}",
|
||||
"error_sdlc_context": "Error fetching SDLC context: {error}",
|
||||
"user_next_step": "What should I do next?",
|
||||
"info_tool_call_requested": "Tool call requested...",
|
||||
"info_executing_create_branch": "Executing: create_branch({args})",
|
||||
"info_executing_create_pr": "Executing: create_pull_request({args})",
|
||||
"error_github_not_available": "Error: GitHub integration not available for tool call.",
|
||||
"error_github_repo_missing": "GITHUB_REPOSITORY environment variable not set",
|
||||
"sdlc_context_label": "SDLC Context:",
|
||||
"open_issues_label": "Open Issues:",
|
||||
"open_prs_label": "Open Pull Requests:"
|
||||
}
|
||||
15
src/autometabuilder/messages_es.json
Normal file
15
src/autometabuilder/messages_es.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"error_github_token_missing": "Error: variable de entorno GITHUB_TOKEN no configurada.",
|
||||
"info_integrated_repo": "Integrado con el repositorio: {repo_name}",
|
||||
"warn_github_init_failed": "Advertencia: falló la integración con GitHub: {error}",
|
||||
"error_sdlc_context": "Error al obtener el contexto de SDLC: {error}",
|
||||
"user_next_step": "¿Qué debo hacer a continuación?",
|
||||
"info_tool_call_requested": "Llamada a herramienta solicitada...",
|
||||
"info_executing_create_branch": "Ejecutando: create_branch({args})",
|
||||
"info_executing_create_pr": "Ejecutando: create_pull_request({args})",
|
||||
"error_github_not_available": "Error: la integración de GitHub no está disponible para la llamada a la herramienta.",
|
||||
"error_github_repo_missing": "variable de entorno GITHUB_REPOSITORY no configurada",
|
||||
"sdlc_context_label": "Contexto de SDLC:",
|
||||
"open_issues_label": "Issues abiertos:",
|
||||
"open_prs_label": "Pull Requests abiertos:"
|
||||
}
|
||||
15
src/autometabuilder/messages_fr.json
Normal file
15
src/autometabuilder/messages_fr.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"error_github_token_missing": "Erreur : la variable d'environnement GITHUB_TOKEN n'est pas définie.",
|
||||
"info_integrated_repo": "Intégré au dépôt : {repo_name}",
|
||||
"warn_github_init_failed": "Avertissement : l'intégration GitHub a échoué : {error}",
|
||||
"error_sdlc_context": "Erreur lors de la récupération du contexte SDLC : {error}",
|
||||
"user_next_step": "Que dois-je faire ensuite ?",
|
||||
"info_tool_call_requested": "Appel d'outil demandé...",
|
||||
"info_executing_create_branch": "Exécution : create_branch({args})",
|
||||
"info_executing_create_pr": "Exécution : create_pull_request({args})",
|
||||
"error_github_not_available": "Erreur : l'intégration GitHub n'est pas disponible pour l'appel d'outil.",
|
||||
"error_github_repo_missing": "La variable d'environnement GITHUB_REPOSITORY n'est pas définie",
|
||||
"sdlc_context_label": "Contexte SDLC :",
|
||||
"open_issues_label": "Tickets ouverts :",
|
||||
"open_prs_label": "Pull Requests ouvertes :"
|
||||
}
|
||||
15
src/autometabuilder/messages_nl.json
Normal file
15
src/autometabuilder/messages_nl.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"error_github_token_missing": "Fout: GITHUB_TOKEN omgevingsvariabele is niet ingesteld.",
|
||||
"info_integrated_repo": "Geïntegreerd met repository: {repo_name}",
|
||||
"warn_github_init_failed": "Waarschuwing: GitHub-integratie mislukt: {error}",
|
||||
"error_sdlc_context": "Fout bij het ophalen van SDLC-context: {error}",
|
||||
"user_next_step": "Wat moet ik nu doen?",
|
||||
"info_tool_call_requested": "Tool-aanroep aangevraagd...",
|
||||
"info_executing_create_branch": "Uitvoeren: create_branch({args})",
|
||||
"info_executing_create_pr": "Uitvoeren: create_pull_request({args})",
|
||||
"error_github_not_available": "Fout: GitHub-integratie niet beschikbaar voor tool-aanroep.",
|
||||
"error_github_repo_missing": "GITHUB_REPOSITORY omgevingsvariabele is niet ingesteld",
|
||||
"sdlc_context_label": "SDLC-context:",
|
||||
"open_issues_label": "Openstaande issues:",
|
||||
"open_prs_label": "Openstaande pull requests:"
|
||||
}
|
||||
15
src/autometabuilder/messages_pirate.json
Normal file
15
src/autometabuilder/messages_pirate.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"error_github_token_missing": "Arr! The GITHUB_TOKEN be missin' from the map!",
|
||||
"info_integrated_repo": "Anchored to the vessel: {repo_name}",
|
||||
"warn_github_init_failed": "Avast! GitHub integration hit a reef: {error}",
|
||||
"error_sdlc_context": "Failed to haul the SDLC context: {error}",
|
||||
"user_next_step": "What be our next course, Captain?",
|
||||
"info_tool_call_requested": "The crew be callin' for a tool...",
|
||||
"info_executing_create_branch": "Carvin' a new path: create_branch({args})",
|
||||
"info_executing_create_pr": "Sendin' a message in a bottle: create_pull_request({args})",
|
||||
"error_github_not_available": "Arr! GitHub be not in sight for this task.",
|
||||
"error_github_repo_missing": "The GITHUB_REPOSITORY be lost at sea!",
|
||||
"sdlc_context_label": "The Ship's Log:",
|
||||
"open_issues_label": "Troubles on the horizon:",
|
||||
"open_prs_label": "Bottles in the water:"
|
||||
}
|
||||
Reference in New Issue
Block a user