|
5 | 5 | from pydantic import BaseModel |
6 | 6 | from rich import print as rprint |
7 | 7 |
|
8 | | -from codegen.cli.api.endpoints import ( |
9 | | - CREATE_ENDPOINT, |
10 | | - DEPLOY_ENDPOINT, |
11 | | - DOCS_ENDPOINT, |
12 | | - EXPERT_ENDPOINT, |
13 | | - IDENTIFY_ENDPOINT, |
14 | | - IMPROVE_ENDPOINT, |
15 | | - LOOKUP_ENDPOINT, |
16 | | - PR_LOOKUP_ENDPOINT, |
17 | | - RUN_ENDPOINT, |
18 | | - RUN_ON_PR_ENDPOINT, |
19 | | -) |
20 | | -from codegen.cli.api.schemas import ( |
21 | | - AskExpertInput, |
22 | | - AskExpertResponse, |
23 | | - CodemodRunType, |
24 | | - CreateInput, |
25 | | - CreateResponse, |
26 | | - DeployInput, |
27 | | - DeployResponse, |
28 | | - DocsInput, |
29 | | - DocsResponse, |
30 | | - IdentifyResponse, |
31 | | - ImproveCodemodInput, |
32 | | - ImproveCodemodResponse, |
33 | | - LookupInput, |
34 | | - LookupOutput, |
35 | | - PRLookupInput, |
36 | | - PRLookupResponse, |
37 | | - RunCodemodInput, |
38 | | - RunCodemodOutput, |
39 | | - RunOnPRInput, |
40 | | - RunOnPRResponse, |
41 | | -) |
42 | | -from codegen.cli.auth.session import CodegenSession |
43 | | - |
44 | | - |
45 | | -def convert_to_ui(data): |
46 | | - """Simple stub for convert_to_ui function.""" |
47 | | - return data |
48 | | - |
49 | | - |
50 | 8 | from codegen.cli.env.global_env import global_env |
51 | 9 | from codegen.cli.errors import InvalidTokenError, ServerError |
52 | | -from codegen.cli.utils.codemods import Codemod |
53 | | -from codegen.cli.utils.function_finder import DecoratedFunction |
54 | | -from codegen.shared.enums.programming_language import ProgrammingLanguage |
55 | 10 |
|
56 | 11 | InputT = TypeVar("InputT", bound=BaseModel) |
57 | 12 | OutputT = TypeVar("OutputT", bound=BaseModel) |
@@ -120,155 +75,3 @@ def _make_request( |
120 | 75 | except requests.RequestException as e: |
121 | 76 | msg = f"Network error: {e!s}" |
122 | 77 | raise ServerError(msg) |
123 | | - |
124 | | - def run( |
125 | | - self, |
126 | | - function: DecoratedFunction | Codemod, |
127 | | - include_source: bool = True, |
128 | | - run_type: CodemodRunType = CodemodRunType.DIFF, |
129 | | - template_context: dict[str, str] | None = None, |
130 | | - ) -> RunCodemodOutput: |
131 | | - """Run a codemod transformation. |
132 | | -
|
133 | | - Args: |
134 | | - function: The function or codemod to run |
135 | | - include_source: Whether to include the source code in the request. |
136 | | - If False, uses the deployed version. |
137 | | - run_type: Type of run (diff or pr) |
138 | | - template_context: Context variables to pass to the codemod |
139 | | -
|
140 | | - """ |
141 | | - session = CodegenSession.from_active_session() |
142 | | - base_input = { |
143 | | - "codemod_name": function.name, |
144 | | - "repo_full_name": session.config.repository.full_name, |
145 | | - "codemod_run_type": run_type, |
146 | | - } |
147 | | - |
148 | | - # Only include source if requested |
149 | | - if include_source: |
150 | | - source = function.get_current_source() if isinstance(function, Codemod) else function.source |
151 | | - base_input["codemod_source"] = convert_to_ui(source) |
152 | | - |
153 | | - # Add template context if provided |
154 | | - if template_context: |
155 | | - base_input["template_context"] = template_context |
156 | | - |
157 | | - input_data = RunCodemodInput(input=RunCodemodInput.BaseRunCodemodInput(**base_input)) |
158 | | - return self._make_request( |
159 | | - "POST", |
160 | | - RUN_ENDPOINT, |
161 | | - input_data, |
162 | | - RunCodemodOutput, |
163 | | - ) |
164 | | - |
165 | | - def get_docs(self) -> DocsResponse: |
166 | | - """Search documentation.""" |
167 | | - session = CodegenSession.from_active_session() |
168 | | - return self._make_request( |
169 | | - "GET", |
170 | | - DOCS_ENDPOINT, |
171 | | - DocsInput(docs_input=DocsInput.BaseDocsInput(repo_full_name=session.config.repository.full_name)), |
172 | | - DocsResponse, |
173 | | - ) |
174 | | - |
175 | | - def ask_expert(self, query: str) -> AskExpertResponse: |
176 | | - """Ask the expert system a question.""" |
177 | | - return self._make_request( |
178 | | - "GET", |
179 | | - EXPERT_ENDPOINT, |
180 | | - AskExpertInput(input=AskExpertInput.BaseAskExpertInput(query=query)), |
181 | | - AskExpertResponse, |
182 | | - ) |
183 | | - |
184 | | - def create(self, name: str, query: str) -> CreateResponse: |
185 | | - """Get AI-generated starter code for a codemod.""" |
186 | | - session = CodegenSession.from_active_session() |
187 | | - language = ProgrammingLanguage(session.config.repository.language) |
188 | | - return self._make_request( |
189 | | - "GET", |
190 | | - CREATE_ENDPOINT, |
191 | | - CreateInput(input=CreateInput.BaseCreateInput(name=name, query=query, language=language)), |
192 | | - CreateResponse, |
193 | | - ) |
194 | | - |
195 | | - def identify(self) -> IdentifyResponse | None: |
196 | | - """Identify the user's codemod.""" |
197 | | - return self._make_request( |
198 | | - "POST", |
199 | | - IDENTIFY_ENDPOINT, |
200 | | - None, |
201 | | - IdentifyResponse, |
202 | | - ) |
203 | | - |
204 | | - def deploy( |
205 | | - self, |
206 | | - codemod_name: str, |
207 | | - codemod_source: str, |
208 | | - lint_mode: bool = False, |
209 | | - lint_user_whitelist: list[str] | None = None, |
210 | | - message: str | None = None, |
211 | | - arguments_schema: dict | None = None, |
212 | | - ) -> DeployResponse: |
213 | | - """Deploy a codemod to the Modal backend.""" |
214 | | - session = CodegenSession.from_active_session() |
215 | | - return self._make_request( |
216 | | - "POST", |
217 | | - DEPLOY_ENDPOINT, |
218 | | - DeployInput( |
219 | | - input=DeployInput.BaseDeployInput( |
220 | | - codemod_name=codemod_name, |
221 | | - codemod_source=codemod_source, |
222 | | - repo_full_name=session.config.repository.full_name, |
223 | | - lint_mode=lint_mode, |
224 | | - lint_user_whitelist=lint_user_whitelist or [], |
225 | | - message=message, |
226 | | - arguments_schema=arguments_schema, |
227 | | - ) |
228 | | - ), |
229 | | - DeployResponse, |
230 | | - ) |
231 | | - |
232 | | - def lookup(self, codemod_name: str) -> LookupOutput: |
233 | | - """Look up a codemod by name.""" |
234 | | - session = CodegenSession.from_active_session() |
235 | | - return self._make_request( |
236 | | - "GET", |
237 | | - LOOKUP_ENDPOINT, |
238 | | - LookupInput(input=LookupInput.BaseLookupInput(codemod_name=codemod_name, repo_full_name=session.config.repository.full_name)), |
239 | | - LookupOutput, |
240 | | - ) |
241 | | - |
242 | | - def run_on_pr(self, codemod_name: str, repo_full_name: str, github_pr_number: int, language: str | None = None) -> RunOnPRResponse: |
243 | | - """Test a webhook against a specific PR.""" |
244 | | - return self._make_request( |
245 | | - "POST", |
246 | | - RUN_ON_PR_ENDPOINT, |
247 | | - RunOnPRInput( |
248 | | - input=RunOnPRInput.BaseRunOnPRInput( |
249 | | - codemod_name=codemod_name, |
250 | | - repo_full_name=repo_full_name, |
251 | | - github_pr_number=github_pr_number, |
252 | | - language=language, |
253 | | - ) |
254 | | - ), |
255 | | - RunOnPRResponse, |
256 | | - ) |
257 | | - |
258 | | - def lookup_pr(self, repo_full_name: str, github_pr_number: int) -> PRLookupResponse: |
259 | | - """Look up a PR by repository and PR number.""" |
260 | | - return self._make_request( |
261 | | - "GET", |
262 | | - PR_LOOKUP_ENDPOINT, |
263 | | - PRLookupInput(input=PRLookupInput.BasePRLookupInput(repo_full_name=repo_full_name, github_pr_number=github_pr_number)), |
264 | | - PRLookupResponse, |
265 | | - ) |
266 | | - |
267 | | - def improve_codemod(self, codemod: str, task: str, concerns: list[str], context: dict[str, str], language: ProgrammingLanguage) -> ImproveCodemodResponse: |
268 | | - """Improve a codemod.""" |
269 | | - return self._make_request( |
270 | | - "GET", |
271 | | - IMPROVE_ENDPOINT, |
272 | | - ImproveCodemodInput(input=ImproveCodemodInput.BaseImproveCodemodInput(codemod=codemod, task=task, concerns=concerns, context=context, language=language)), |
273 | | - ImproveCodemodResponse, |
274 | | - ) |
0 commit comments