Skip to content

Commit

Permalink
Allow reading of comments for github issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Marti2203 committed Sep 10, 2024
1 parent 519b642 commit 1aafff1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
13 changes: 12 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ def main(args, subparser_dest_attr_name: str = "command"):
setup_dir = abspath(setup_dir)

task = RawGithubTask(
args.task_id, args.clone_link, args.commit_hash, args.issue_link, setup_dir
args.task_id,
args.clone_link,
args.commit_hash,
args.issue_link,
setup_dir,
args.use_comments,
)
groups = {"github": [task]}
run_task_groups(groups, num_processes)
Expand Down Expand Up @@ -160,6 +165,12 @@ def set_github_parser_args(parser: ArgumentParser) -> None:
type=str,
help="The commit hash to checkout. If not specified, the latest commit on default branch will be used.",
)
parser.add_argument(
"--use-comments",
action="store_true",
default=False,
help="Include the comments of the issue.",
)
parser.add_argument("--issue-link", type=str, help="The link to the issue.")
parser.add_argument(
"--setup-dir",
Expand Down
2 changes: 1 addition & 1 deletion app/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def set_model(model_name: str):
completion_tokens=completion_tokens,
)
)
litellm.set_verbose = True
# litellm.set_verbose = True
SELECTED_MODEL = LiteLLMGeneric(
real_model_name,
prompt_tokens_cost_usd_dollar,
Expand Down
39 changes: 33 additions & 6 deletions app/raw_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ def __init__(
commit_hash: str | None,
issue_link: str,
setup_dir: str,
use_comments: bool = False,
):
self._task_id = task_id
self.clone_link = clone_link
# if commit_hash is None, assume using the HEAD of default branch
self.commit_hash = commit_hash
self.issue_link = issue_link
self.setup_dir = setup_dir
self.use_comments = use_comments
self.clone_path = pjoin(self.setup_dir, self.task_id)
self.problem_statement, self.created_at = self.fetch_issue()
self.clone_repo()
Expand Down Expand Up @@ -144,7 +146,7 @@ def fetch_issue(self):
if "github.com" not in self.issue_link:
raise NotImplementedError("Only GitHub issues are supported for now.")

retrieved_issue = self.fetch_github_issue(self.issue_link)
retrieved_issue = self.fetch_github_issue(self.issue_link, self.use_comments)

if retrieved_issue is None:
raise RuntimeError(
Expand Down Expand Up @@ -185,25 +187,50 @@ def process_links(cls, body: str):
return body

@classmethod
def fetch_github_issue(cls, issue_url: str) -> tuple[str, str, str]:
def fetch_github_issue(
cls, issue_url: str, use_comments: bool = False
) -> tuple[str, str, str]:
"""Extract owner, repo, and issue number from the URL"""

# Example issue URL: https://github.com/owner/repo/issues/123

_, owner, repo, _, issue_number = issue_url.rsplit("/", 4)

api_url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}"
response = httpx.get(api_url)
comments_url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}/comments"

if response.status_code != 200:
issue_response = httpx.get(api_url)

if issue_response.status_code != 200:
raise RuntimeError(
f"Failed to fetch issue information: {response.status_code}"
f"Failed to fetch issue information: {issue_response.status_code}"
)

issue_info = response.json()
issue_info = issue_response.json()

title = issue_info["title"]
body = issue_info["body"]

if use_comments:
comments_response = httpx.get(comments_url)
if comments_response.status_code != 200:
raise RuntimeError(
f"Failed to fetch comments information: {comments_response.status_code}"
)

comments_info = comments_response.json()
for comment in comments_info:
if (
"user" not in comment
or comment["user"]["type"] == "Bot"
or comment["user"]["login"] == "acr-bot"
):
continue

body += (
f"\nUser: {comment['user']['login']}\nComment: {comment['body']}"
)

created_at = issue_info["created_at"]

return title, body, created_at
Expand Down

0 comments on commit 1aafff1

Please sign in to comment.