kikocis/auto-code-rover public
Changesets · Branches · Tags · Compare
| Changeset | d942afa3e83c412c258ff1def3742c8f3e03b2c8a2d6869cb01dd54036fc3cf8 |
|---|---|
| Author | Martin Mirchev <mirchevmartin2203@gmail.com> · 2024-07-18 14:02 +08:00 |
| Committer | Martin Mirchev <mirchevmartin2203@gmail.com> · 2024-07-18 14:02 +08:00 |
| Parents | 831d2a8f2ea0 |
1 file changed
modified app/raw_tasks.py +29 −0
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import json |
| 2 | 2 | import os |
| 3 | +import re | |
| 3 | 4 | import shutil |
| 4 | 5 | from abc import ABC, abstractmethod |
| 5 | 6 | from os.path import join as pjoin |
| @@ -147,10 +148,38 @@ | ||
| 147 | 148 | |
| 148 | 149 | title, body, created_at = retrieved_issue |
| 149 | 150 | |
| 151 | + body = self.process_links(body) | |
| 152 | + | |
| 150 | 153 | problem_statement = f"{title}\n{body}" |
| 151 | 154 | |
| 152 | 155 | return problem_statement, created_at |
| 153 | 156 | |
| 157 | + @classmethod | |
| 158 | + def process_links(cls, body: str): | |
| 159 | + code_pattern = re.compile( | |
| 160 | + r"https://github.com/(.*?)/blob/(.*)/(.*)#L(\d+)-L(\d+)" | |
| 161 | + ) | |
| 162 | + replacements = [] | |
| 163 | + | |
| 164 | + for code_links in code_pattern.finditer(body): | |
| 165 | + print("Found link!") | |
| 166 | + repo_name = code_links.group(1) | |
| 167 | + commit = code_links.group(2) | |
| 168 | + file_path = code_links.group(3) | |
| 169 | + start_line = int(code_links.group(4)) | |
| 170 | + end_line = int(code_links.group(5)) | |
| 171 | + | |
| 172 | + file_contents = httpx.get( | |
| 173 | + f"https://raw.githubusercontent.com/{repo_name}/{commit}/{file_path}" | |
| 174 | + ).text.splitlines() | |
| 175 | + fragment = "\n".join(file_contents[start_line - 1 : end_line]) | |
| 176 | + | |
| 177 | + replacements.append((code_links.group(0), f"\n```{fragment }```\n")) | |
| 178 | + | |
| 179 | + for code_link, replacement in replacements: | |
| 180 | + body = body.replace(code_link, code_link + replacement) | |
| 181 | + return body | |
| 182 | + | |
| 154 | 183 | @classmethod |
| 155 | 184 | def fetch_github_issue(cls, issue_url: str) -> tuple[str, str, str]: |
| 156 | 185 | """Extract owner, repo, and issue number from the URL""" |