1010from server .config import settings
1111from server .embeddings .base import EmbeddingProvider
1212from server .embeddings .jina import get_embedding_provider
13- from server .indexer .github_source import GitHubCommit , fetch_commits_with_diffs , list_commits
13+ from server .indexer .github_source import (
14+ GitHubCommit ,
15+ fetch_commits_with_diffs ,
16+ list_commits ,
17+ )
1418from server .indexer .pipeline import ProgressEvent
1519from server .store .commit_store import CommitStore
1620
@@ -78,25 +82,34 @@ async def index_service(
7882
7983 async with httpx .AsyncClient () as http_client :
8084 commits = await list_commits (
81- settings .github_token , svc .github_repo , svc .github_ref ,
82- root = svc .root , max_commits = settings .git_history_max_commits ,
85+ settings .github_token ,
86+ svc .github_repo ,
87+ svc .github_ref ,
88+ root = svc .root ,
89+ max_commits = settings .git_history_max_commits ,
8390 client = http_client ,
8491 )
8592
8693 if progress_callback :
87- await progress_callback (ProgressEvent (
88- phase = "discovery" ,
89- current = len (commits ),
90- total = len (commits ),
91- percentage = 100.0 ,
92- service = service_name ,
93- ))
94+ await progress_callback (
95+ ProgressEvent (
96+ phase = "discovery" ,
97+ current = len (commits ),
98+ total = len (commits ),
99+ percentage = 100.0 ,
100+ service = service_name ,
101+ )
102+ )
94103
95104 existing_shas = set () if force else await self ._store .get_indexed_shas (svc .name )
96105 new_commits = [c for c in commits if c .sha not in existing_shas ]
97106 skipped = len (commits ) - len (new_commits )
98107
99- shas_without_diffs = set (await self ._store .get_commits_without_diffs (svc .name )) if not force else set ()
108+ shas_without_diffs = (
109+ set (await self ._store .get_commits_without_diffs (svc .name ))
110+ if not force
111+ else set ()
112+ )
100113 commits_needing_diffs = [c for c in commits if c .sha in shas_without_diffs ]
101114
102115 if not new_commits and not commits_needing_diffs :
@@ -105,41 +118,55 @@ async def index_service(
105118 diff_updated = 0
106119
107120 if new_commits :
108- logger .info ("Fetching diffs for %d new commits in %s" , len (new_commits ), service_name )
121+ logger .info (
122+ "Fetching diffs for %d new commits in %s" ,
123+ len (new_commits ),
124+ service_name ,
125+ )
109126 new_commits = await fetch_commits_with_diffs (
110127 settings .github_token , svc .github_repo , new_commits
111128 )
112129 texts = [_build_embedding_text (c , svc .name ) for c in new_commits ]
113130 try :
114131 vectors = await self ._embedder .embed_batch (texts )
115132 except Exception as exc :
116- logger .error ("Embedding failed for %s git history: %s" , service_name , exc )
133+ logger .error (
134+ "Embedding failed for %s git history: %s" , service_name , exc
135+ )
117136 return {"error" : 1 , "new" : 0 , "skipped" : skipped , "diff_updated" : 0 }
118137
119138 if progress_callback :
120- await progress_callback (ProgressEvent (
121- phase = "embedding" ,
122- current = len (new_commits ),
123- total = len (new_commits ),
124- percentage = 100.0 ,
125- service = service_name ,
126- ))
139+ await progress_callback (
140+ ProgressEvent (
141+ phase = "embedding" ,
142+ current = len (new_commits ),
143+ total = len (new_commits ),
144+ percentage = 100.0 ,
145+ service = service_name ,
146+ )
147+ )
127148
128149 payloads = [_commit_to_payload (c , svc .name ) for c in new_commits ]
129150 await self ._store .upsert_commits (svc .name , payloads , vectors )
130151 logger .info ("Indexed %d new commits for %s" , len (new_commits ), service_name )
131152
132153 if progress_callback :
133- await progress_callback (ProgressEvent (
134- phase = "upserting" ,
135- current = len (new_commits ),
136- total = len (new_commits ),
137- percentage = 100.0 ,
138- service = service_name ,
139- ))
154+ await progress_callback (
155+ ProgressEvent (
156+ phase = "upserting" ,
157+ current = len (new_commits ),
158+ total = len (new_commits ),
159+ percentage = 100.0 ,
160+ service = service_name ,
161+ )
162+ )
140163
141164 if commits_needing_diffs :
142- logger .info ("Fetching diffs for %d existing commits in %s" , len (commits_needing_diffs ), service_name )
165+ logger .info (
166+ "Fetching diffs for %d existing commits in %s" ,
167+ len (commits_needing_diffs ),
168+ service_name ,
169+ )
143170 commits_needing_diffs = await fetch_commits_with_diffs (
144171 settings .github_token , svc .github_repo , commits_needing_diffs
145172 )
@@ -148,15 +175,21 @@ async def index_service(
148175 diff_updated = len (commits_needing_diffs )
149176
150177 if progress_callback :
151- await progress_callback (ProgressEvent (
152- phase = "upserting" ,
153- current = diff_updated ,
154- total = diff_updated ,
155- percentage = 100.0 ,
156- service = service_name ,
157- ))
158-
159- return {"new" : len (new_commits ), "skipped" : skipped , "diff_updated" : diff_updated }
178+ await progress_callback (
179+ ProgressEvent (
180+ phase = "upserting" ,
181+ current = diff_updated ,
182+ total = diff_updated ,
183+ percentage = 100.0 ,
184+ service = service_name ,
185+ )
186+ )
187+
188+ return {
189+ "new" : len (new_commits ),
190+ "skipped" : skipped ,
191+ "diff_updated" : diff_updated ,
192+ }
160193
161194 async def index_all (
162195 self ,
@@ -167,5 +200,7 @@ async def index_all(
167200 results : dict [str , Any ] = {}
168201 for svc in services :
169202 logger .info ("Indexing git history for: %s" , svc .name )
170- results [svc .name ] = await self .index_service (svc .name , force = force , progress_callback = progress_callback )
203+ results [svc .name ] = await self .index_service (
204+ svc .name , force = force , progress_callback = progress_callback
205+ )
171206 return results
0 commit comments