wony617 commited on
Commit
a5bcbae
·
1 Parent(s): 0e064c8

log: use separate GitHub client/token for logging

Browse files

Introduce logging_github_client using LOG_GITHUB_TOKEN (fallback to GITHUB_TOKEN) to isolate permissions between user PR actions and log repository writes.

Files changed (1) hide show
  1. pr_generator/agent.py +20 -1
pr_generator/agent.py CHANGED
@@ -37,6 +37,7 @@ class GitHubPRAgent:
37
  def __init__(self):
38
  self._github_client = None
39
  self._llm = None
 
40
 
41
  @property
42
  def github_client(self) -> Optional[Github]:
@@ -66,6 +67,24 @@ class GitHubPRAgent:
66
  )
67
  return self._llm
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  def append_to_log_file(
70
  self,
71
  log_entry: str,
@@ -97,7 +116,7 @@ class GitHubPRAgent:
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
103
  try:
 
37
  def __init__(self):
38
  self._github_client = None
39
  self._llm = None
40
+ self._log_github_client = None
41
 
42
  @property
43
  def github_client(self) -> Optional[Github]:
 
67
  )
68
  return self._llm
69
 
70
+ @property
71
+ def logging_github_client(self) -> Optional[Github]:
72
+ """Return GitHub API client for logging with optional separate token.
73
+
74
+ Uses LOG_GITHUB_TOKEN if set; otherwise falls back to GITHUB_TOKEN.
75
+ """
76
+ if not REQUIRED_LIBS_AVAILABLE:
77
+ raise ImportError("Required libraries not found.")
78
+
79
+ if self._log_github_client is None:
80
+ token = os.environ.get("LOG_GITHUB_TOKEN") or os.environ.get("GITHUB_TOKEN")
81
+ if not token:
82
+ print("Warning: LOG_GITHUB_TOKEN/GITHUB_TOKEN not set for logging.")
83
+ return Github() # Limited access
84
+ self._log_github_client = Github(token)
85
+
86
+ return self._log_github_client
87
+
88
  def append_to_log_file(
89
  self,
90
  log_entry: str,
 
116
  branch_name = os.environ.get("LOG_BRANCH", "log_event")
117
  path = os.environ.get("LOG_FILE_PATH", "pr_success.log")
118
 
119
+ repo = self.logging_github_client.get_repo(f"{owner}/{repo_name}")
120
 
121
  # Ensure branch exists; if not, create from default branch
122
  try: