@@ -78,8 +78,7 @@ def _build_contribution_graph_from_git(repo_path: str = ".") -> list:
7878 # Get commit dates
7979 result = subprocess .run (
8080 ['git' , 'log' , '--pretty=format:%ai' , '--all' ],
81- capture_output = True , text = True , cwd = repo_path ,
82- env = {** os .environ , 'GH_TOKEN' : os .getenv ('GH_TOKEN' )}
81+ capture_output = True , text = True , cwd = repo_path
8382 )
8483 if result .returncode != 0 :
8584 return []
@@ -133,8 +132,19 @@ def __init__(self, token: Optional[str] = None):
133132 Args:
134133 token: Optional GitHub personal access token
135134 """
136- self .token = token
137- pass
135+ super ().__init__ (token )
136+
137+ def _build_env (self ) -> dict :
138+ """
139+ Build environment dict with token if available.
140+
141+ Returns:
142+ Environment dict for subprocess calls
143+ """
144+ env = os .environ .copy ()
145+ if self .token :
146+ env ['GH_TOKEN' ] = self .token
147+ return env
138148
139149 def _check_gh_cli (self ) -> None :
140150 """Check if GitHub CLI is installed and authenticated."""
@@ -217,7 +227,7 @@ def _gh_api(self, endpoint: str, method: str = "GET") -> Any:
217227 capture_output = True ,
218228 text = True ,
219229 timeout = 30 ,
220- env = { ** os . environ , 'GH_TOKEN' : os . getenv ( 'GH_TOKEN' )}
230+ env = self . _build_env ()
221231 )
222232 if result .returncode != 0 :
223233 raise Exception (f"gh api failed: { result .stderr } " )
@@ -442,7 +452,7 @@ def _search_items(self, query: str, per_page: int = 5) -> Dict[str, Any]:
442452 capture_output = True ,
443453 text = True ,
444454 timeout = 30 ,
445- env = { ** os . environ , 'GH_TOKEN' : os . getenv ( 'GH_TOKEN' )}
455+ env = self . _build_env ()
446456 )
447457 if result .returncode != 0 :
448458 return {'total_count' : 0 , 'items' : []}
@@ -554,7 +564,7 @@ def _fetch_contribution_graph(self, username: str) -> list:
554564 capture_output = True ,
555565 text = True ,
556566 timeout = 30 ,
557- env = { ** os . environ , 'GH_TOKEN' : os . getenv ( 'GH_TOKEN' )}
567+ env = self . _build_env ()
558568 )
559569
560570 if result .returncode != 0 :
@@ -646,8 +656,7 @@ def _api_request(self, endpoint: str) -> Any:
646656 cmd ,
647657 capture_output = True ,
648658 text = True ,
649- timeout = 30 ,
650- env = {** os .environ , 'GH_TOKEN' : os .getenv ('GH_TOKEN' )}
659+ timeout = 30
651660 )
652661 if result .returncode != 0 :
653662 raise Exception (f"API request failed: { result .stderr } " )
0 commit comments