wony617
commited on
Commit
Β·
0e064c8
1
Parent(s):
d583cc9
log: use env/static settings for log target; remove header option
Browse filesappend_to_log_file now resolves owner/repo/branch/path from environment (LOG_REPO or LOG_REPO_OWNER/LOG_REPO_NAME, LOG_BRANCH, LOG_FILE_PATH). Updated call site to pass only JSONL entry. Removed header handling to keep pure JSONL.
- agent/workflow.py +2 -10
- pr_generator/agent.py +24 -9
agent/workflow.py
CHANGED
|
@@ -204,19 +204,11 @@ def generate_github_pr(
|
|
| 204 |
else:
|
| 205 |
toctree_status = f"\nπ **Toctree Update Failed:** β {toctree_result['message']}"
|
| 206 |
|
| 207 |
-
# Append full result JSON to GitHub log file
|
| 208 |
try:
|
| 209 |
import json
|
| 210 |
log_entry = json.dumps(result, ensure_ascii=False) + "\n"
|
| 211 |
-
log_res = agent.append_to_log_file(
|
| 212 |
-
owner=github_config["owner"],
|
| 213 |
-
repo_name=github_config["repo_name"],
|
| 214 |
-
branch_name="log_event",
|
| 215 |
-
path="pr_success.log",
|
| 216 |
-
log_entry=log_entry,
|
| 217 |
-
# Ensure pure JSONL (no header)
|
| 218 |
-
header_if_new="",
|
| 219 |
-
)
|
| 220 |
print(f"π Log append result: {log_res}")
|
| 221 |
except Exception as e:
|
| 222 |
print(f"β Failed to append PR log via GitHub API: {e}")
|
|
|
|
| 204 |
else:
|
| 205 |
toctree_status = f"\nπ **Toctree Update Failed:** β {toctree_result['message']}"
|
| 206 |
|
| 207 |
+
# Append full result JSON to GitHub log file (always, env-configured repo/branch/path)
|
| 208 |
try:
|
| 209 |
import json
|
| 210 |
log_entry = json.dumps(result, ensure_ascii=False) + "\n"
|
| 211 |
+
log_res = agent.append_to_log_file(log_entry=log_entry)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
print(f"π Log append result: {log_res}")
|
| 213 |
except Exception as e:
|
| 214 |
print(f"β Failed to append PR log via GitHub API: {e}")
|
pr_generator/agent.py
CHANGED
|
@@ -68,19 +68,35 @@ class GitHubPRAgent:
|
|
| 68 |
|
| 69 |
def append_to_log_file(
|
| 70 |
self,
|
| 71 |
-
owner: str,
|
| 72 |
-
repo_name: str,
|
| 73 |
-
branch_name: str,
|
| 74 |
-
path: str,
|
| 75 |
log_entry: str,
|
| 76 |
commit_message: str = "chore(log): append PR result entry",
|
| 77 |
-
header_if_new: str = "# PR Success Log\n",
|
| 78 |
) -> str:
|
| 79 |
"""Append a log entry to a file on a specific branch using GitHub API.
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
"""
|
| 83 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
repo = self.github_client.get_repo(f"{owner}/{repo_name}")
|
| 85 |
|
| 86 |
# Ensure branch exists; if not, create from default branch
|
|
@@ -118,12 +134,11 @@ class GitHubPRAgent:
|
|
| 118 |
return "SUCCESS: Log appended"
|
| 119 |
except GithubException as e:
|
| 120 |
if e.status == 404:
|
| 121 |
-
# File does not exist; create with
|
| 122 |
-
content_to_write = (header_if_new or "") + log_entry
|
| 123 |
repo.create_file(
|
| 124 |
path=path,
|
| 125 |
message=commit_message,
|
| 126 |
-
content=
|
| 127 |
branch=branch_name,
|
| 128 |
)
|
| 129 |
return "SUCCESS: Log file created and first entry appended"
|
|
|
|
| 68 |
|
| 69 |
def append_to_log_file(
|
| 70 |
self,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
log_entry: str,
|
| 72 |
commit_message: str = "chore(log): append PR result entry",
|
|
|
|
| 73 |
) -> str:
|
| 74 |
"""Append a log entry to a file on a specific branch using GitHub API.
|
| 75 |
|
| 76 |
+
Target repository/branch/path are read from environment variables:
|
| 77 |
+
- LOG_REPO or LOG_REPO_OWNER + LOG_REPO_NAME
|
| 78 |
+
- LOG_BRANCH (default: 'log_event')
|
| 79 |
+
- LOG_FILE_PATH (default: 'pr_success.log')
|
| 80 |
"""
|
| 81 |
try:
|
| 82 |
+
# Resolve target repo and path from environment/static settings
|
| 83 |
+
repo_spec = os.environ.get("LOG_REPO")
|
| 84 |
+
owner = None
|
| 85 |
+
repo_name = None
|
| 86 |
+
if repo_spec and "/" in repo_spec:
|
| 87 |
+
owner, repo_name = repo_spec.split("/", 1)
|
| 88 |
+
else:
|
| 89 |
+
owner = os.environ.get("LOG_REPO_OWNER")
|
| 90 |
+
repo_name = os.environ.get("LOG_REPO_NAME")
|
| 91 |
+
|
| 92 |
+
if not owner or not repo_name:
|
| 93 |
+
return (
|
| 94 |
+
"log file append failed: 400 Missing LOG_REPO or LOG_REPO_OWNER/LOG_REPO_NAME"
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
branch_name = os.environ.get("LOG_BRANCH", "log_event")
|
| 98 |
+
path = os.environ.get("LOG_FILE_PATH", "pr_success.log")
|
| 99 |
+
|
| 100 |
repo = self.github_client.get_repo(f"{owner}/{repo_name}")
|
| 101 |
|
| 102 |
# Ensure branch exists; if not, create from default branch
|
|
|
|
| 134 |
return "SUCCESS: Log appended"
|
| 135 |
except GithubException as e:
|
| 136 |
if e.status == 404:
|
| 137 |
+
# File does not exist; create with first entry (pure JSONL line)
|
|
|
|
| 138 |
repo.create_file(
|
| 139 |
path=path,
|
| 140 |
message=commit_message,
|
| 141 |
+
content=log_entry,
|
| 142 |
branch=branch_name,
|
| 143 |
)
|
| 144 |
return "SUCCESS: Log file created and first entry appended"
|