diff --git a/gimie/extractors/github.py b/gimie/extractors/github.py index 19d384f..96d56f6 100644 --- a/gimie/extractors/github.py +++ b/gimie/extractors/github.py @@ -111,7 +111,7 @@ def list_files(self) -> List[RemoteResource]: file = RemoteResource( path=item["name"], url=f'{repo_url}/raw/{defaultbranchref}/{item["path"]}', - headers=self._set_auth(), + headers=self._headers, ) file_list.append(file) return file_list @@ -233,9 +233,7 @@ def _repo_data(self) -> Dict[str, Any]: } } """ - response = send_graphql_query( - GH_API, repo_query, data, self._set_auth() - ) + response = send_graphql_query(GH_API, repo_query, data, self._headers) if "errors" in response: raise ValueError(response["errors"]) @@ -246,14 +244,14 @@ def _fetch_contributors(self) -> List[Person]: """Queries the GitHub GraphQL API to extract contributors through the commit list. NOTE: This is a workaround for the lack of a contributors field in the GraphQL API. """ - headers = self._set_auth() contributors = [] - resp = query_contributors(self.url, headers) + resp = query_contributors(self.url, self._headers) for user in resp: contributors.append(self._get_user(user)) return list(contributors) - def _set_auth(self) -> Any: + @cached_property + def _headers(self) -> Any: """Set authentication headers for GitHub API requests.""" try: if not self.token: diff --git a/gimie/extractors/gitlab.py b/gimie/extractors/gitlab.py index 0fa03a3..07f0a61 100644 --- a/gimie/extractors/gitlab.py +++ b/gimie/extractors/gitlab.py @@ -62,7 +62,7 @@ def list_files(self) -> List[RemoteResource]: file = RemoteResource( path=item["name"], url=f'{self.url}/-/raw/{defaultbranchref}/{item["name"]}', - headers=self._set_auth(), + headers=self._headers, ) file_list.append(file) return file_list @@ -226,14 +226,15 @@ def _repo_data(self) -> Dict[str, Any]: } """ response = send_graphql_query( - self.graphql_endpoint, project_query, data, self._set_auth() + self.graphql_endpoint, project_query, data, self._headers ) if "errors" in response: raise ValueError(response["errors"]) return response["data"]["project"] - def _set_auth(self) -> Any: + @cached_property + def _headers(self) -> Any: """Set authentication headers for Gitlab API requests.""" try: if not self.token: @@ -280,7 +281,7 @@ def _user_from_rest(self, username: str) -> Person: author = send_rest_query( self.rest_endpoint, f"/users?username={username}", - self._set_auth(), + self._headers, ) if isinstance(author, list): author = author[0]