Elffuss BraidHub

kikocis/auto-code-rover public

Allow reading of comments for github issue
Changesetfd06fcc9577a72e68f9c15cc94cd3f0893004d3c7e1191561e2bee506e4da02b
AuthorMartin Mirchev <mirchevmartin2203@gmail.com> · 2024-09-10 12:23 +08:00
CommitterMartin Mirchev <mirchevmartin2203@gmail.com> · 2024-09-10 12:23 +08:00
Parentsc354dbc7a0ea

Browse the files at this changeset

3 files changed

modified app/main.py +12 −1
@@ -106,7 +106,12 @@
106106 setup_dir = abspath(setup_dir)
107107
108108 task = RawGithubTask(
109- args.task_id, args.clone_link, args.commit_hash, args.issue_link, setup_dir
109+ args.task_id,
110+ args.clone_link,
111+ args.commit_hash,
112+ args.issue_link,
113+ setup_dir,
114+ args.use_comments,
110115 )
111116 groups = {"github": [task]}
112117 run_task_groups(groups, num_processes)
@@ -160,6 +165,12 @@
160165 type=str,
161166 help="The commit hash to checkout. If not specified, the latest commit on default branch will be used.",
162167 )
168+ parser.add_argument(
169+ "--use-comments",
170+ action="store_true",
171+ default=False,
172+ help="Include the comments of the issue.",
173+ )
163174 parser.add_argument("--issue-link", type=str, help="The link to the issue.")
164175 parser.add_argument(
165176 "--setup-dir",
modified app/model/common.py +1 −1
@@ -206,7 +206,7 @@
206206 completion_tokens=completion_tokens,
207207 )
208208 )
209- litellm.set_verbose = True
209+ # litellm.set_verbose = True
210210 SELECTED_MODEL = LiteLLMGeneric(
211211 real_model_name,
212212 prompt_tokens_cost_usd_dollar,
modified app/raw_tasks.py +33 −6
@@ -95,6 +95,7 @@
9595 commit_hash: str | None,
9696 issue_link: str,
9797 setup_dir: str,
98+ use_comments: bool = False,
9899 ):
99100 self._task_id = task_id
100101 self.clone_link = clone_link
@@ -102,6 +103,7 @@
102103 self.commit_hash = commit_hash
103104 self.issue_link = issue_link
104105 self.setup_dir = setup_dir
106+ self.use_comments = use_comments
105107 self.clone_path = pjoin(self.setup_dir, self.task_id)
106108 self.problem_statement, self.created_at = self.fetch_issue()
107109 self.clone_repo()
@@ -144,7 +146,7 @@
144146 if "github.com" not in self.issue_link:
145147 raise NotImplementedError("Only GitHub issues are supported for now.")
146148
147- retrieved_issue = self.fetch_github_issue(self.issue_link)
149+ retrieved_issue = self.fetch_github_issue(self.issue_link, self.use_comments)
148150
149151 if retrieved_issue is None:
150152 raise RuntimeError(
@@ -185,7 +187,9 @@
185187 return body
186188
187189 @classmethod
188- def fetch_github_issue(cls, issue_url: str) -> tuple[str, str, str]:
190+ def fetch_github_issue(
191+ cls, issue_url: str, use_comments: bool = False
192+ ) -> tuple[str, str, str]:
189193 """Extract owner, repo, and issue number from the URL"""
190194
191195 # Example issue URL: https://github.com/owner/repo/issues/123
@@ -193,17 +197,40 @@
193197 _, owner, repo, _, issue_number = issue_url.rsplit("/", 4)
194198
195199 api_url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}"
196- response = httpx.get(api_url)
200+ comments_url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}/comments"
197201
198- if response.status_code != 200:
202+ issue_response = httpx.get(api_url)
203+
204+ if issue_response.status_code != 200:
199205 raise RuntimeError(
200- f"Failed to fetch issue information: {response.status_code}"
206+ f"Failed to fetch issue information: {issue_response.status_code}"
201207 )
202208
203- issue_info = response.json()
209+ issue_info = issue_response.json()
204210
205211 title = issue_info["title"]
206212 body = issue_info["body"]
213+
214+ if use_comments:
215+ comments_response = httpx.get(comments_url)
216+ if comments_response.status_code != 200:
217+ raise RuntimeError(
218+ f"Failed to fetch comments information: {comments_response.status_code}"
219+ )
220+
221+ comments_info = comments_response.json()
222+ for comment in comments_info:
223+ if (
224+ "user" not in comment
225+ or comment["user"]["type"] == "Bot"
226+ or comment["user"]["login"] == "acr-bot"
227+ ):
228+ continue
229+
230+ body += (
231+ f"\nUser: {comment['user']['login']}\nComment: {comment['body']}"
232+ )
233+
207234 created_at = issue_info["created_at"]
208235
209236 return title, body, created_at