@@ -15,6 +15,8 @@ class GitHubRepoAPI(IRepositoryAPI):
1515
1616 def __init__ (self , client ):
1717 self .client = client
18+ self ._issue_cache = {}
19+ self ._pull_cache = {}
1820
1921 def get_repository (self , id : str ) -> Repository | None :
2022 try :
@@ -49,66 +51,82 @@ def get_contributors(self, repo: Repository) -> list[Contributor]:
4951
5052 def get_issues (self , repo : Repository ) -> list [Issue ]:
5153 try :
52- issues = self .client .get_repo (repo ._id ).get_issues (state = 'all' )
53- return [
54- Issue (
54+ repo_obj = self .client .get_repo (repo ._id )
55+ issues = repo_obj .get_issues (state = 'all' )
56+
57+ issue_dict = {}
58+ result = []
59+ for i in issues :
60+ issue_obj = Issue (
5561 _id = i .number ,
5662 title = i .title ,
5763 author = Contributor (i .user .login , i .user .email or "" ),
5864 state = i .state
59- ) for i in issues
60- ]
65+ )
66+ result .append (issue_obj )
67+ issue_dict [i .number ] = issue_obj
68+
69+ self ._issue_cache [repo ._id ] = issue_dict
70+ return result
71+
6172 except Exception as e :
6273 logging .error (f"Failed to get issues from GitHub for repo { repo .name } : { e } " )
6374 return []
6475
6576 def get_pull_requests (self , repo : Repository ) -> list [PullRequest ]:
6677 try :
6778 pulls = self .client .get_repo (repo ._id ).get_pulls (state = 'all' )
68- return [
69- PullRequest (
79+
80+ pull_dict = {}
81+ result = []
82+ for p in pulls :
83+ pr_obj = PullRequest (
7084 _id = p .number ,
7185 title = p .title ,
7286 author = Contributor (p .user .login , p .user .email or "" ),
7387 state = p .state
74- ) for p in pulls
75- ]
88+ )
89+ result .append (pr_obj )
90+ pull_dict [p .number ] = pr_obj
91+
92+ self ._pull_cache [repo ._id ] = pull_dict
93+ return result
94+
7695 except Exception as e :
7796 logging .error (f"Failed to get pull requests from GitHub for repo { repo .name } : { e } " )
7897 return []
79-
98+
8099 def get_branches (self , repo : Repository ) -> list [Branch ]:
81100 try :
82101 repo_client = self .client .get_repo (repo ._id )
83102 branches = repo_client .get_branches ()
84103 result = []
85-
104+
86105 for branch in branches :
87106 commit = repo_client .get_commit (branch .commit .sha )
88-
89-
107+
90108 author = commit .author
91109 contributor = Contributor (
92110 username = author .login if author else "unknown" ,
93111 email = commit .commit .author .email or ""
94112 )
95-
113+
96114 commit_obj = Commit (
97115 _id = commit .sha ,
98116 message = commit .commit .message ,
99117 author = contributor ,
100118 date = commit .commit .author .date
101119 )
102-
120+
103121 result .append (
104122 Branch (
105123 name = branch .name ,
106124 last_commit = commit_obj
107125 )
108126 )
109-
127+
110128 return result
111-
129+
112130 except Exception as e :
113131 logging .error (f"Failed to get branches from GitHub for repo { repo .name } : { e } " )
114132 return []
@@ -124,7 +142,7 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
124142 api = GitHubRepoAPI (client )
125143
126144 # Укажите ваш репозиторий
127- repo_name = ""
145+ repo_name = "repo-name "
128146
129147 # Получение репозитория
130148 repo = api .get_repository (repo_name )
@@ -138,7 +156,7 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
138156 # Получение коммитов
139157 commits = api .get_commits (repo )
140158 print (f"Total commits: { len (commits )} " )
141- for commit in commits [:10 ]: # Выведем первые 10 коммитов
159+ for commit in commits [:10 ]:
142160 print (f"Commit: { commit ._id } , Message: { commit .message } , Author: { commit .author .username } " )
143161
144162 # Получение контрибьюторов
@@ -150,16 +168,15 @@ def get_wiki_pages(self, repo: Repository) -> list[WikiPage]:
150168 # Получение issues
151169 issues = api .get_issues (repo )
152170 print (f"Total issues: { len (issues )} " )
153- for issue in issues [:10 ]: # Выведем первые 10 issues
171+ for issue in issues [:10 ]:
154172 print (f"Issue: { issue ._id } , Title: { issue .title } , State: { issue .state } " )
155173
156174 # Получение pull requests
157175 pulls = api .get_pull_requests (repo )
158176 print (f"Total pull requests: { len (pulls )} " )
159- for pull in pulls [:10 ]: # Выведем первые 10 pull requests
177+ for pull in pulls [:10 ]:
160178 print (f"Pull Request: { pull ._id } , Title: { pull .title } , State: { pull .state } " )
161179
162-
163180 # Получение веток
164181 branches = api .get_branches (repo )
165182 print (f"Total branches: { len (branches )} " )
0 commit comments