Skip to content

Commit

Permalink
feat: impl issue page node handle
Browse files Browse the repository at this point in the history
  • Loading branch information
MadratJerry committed Sep 3, 2024
1 parent 2a33081 commit 6cb63be
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions petercat_utils/rag_helper/git_issue_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def handle(self):
self.update_status(TaskStatus.IN_PROGRESS)
if self.node_type == GitIssueTaskNodeType.REPO:
return self.handle_repo_node()
elif self.node_type == GitIssueTaskNodeType.ISSUE_PAGE:
return self.handle_issue_page_node()

Check warning on line 70 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L69-L70

Added lines #L69 - L70 were not covered by tests
elif self.node_type == GitIssueTaskNodeType.ISSUE:
return self.handle_issue_node()
else:
Expand All @@ -84,6 +86,7 @@ def handle_repo_node(self):

slice_page_index = latest_page[0]["page_index"] if len(latest_page) > 0 else 0

Check warning on line 87 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L87

Added line #L87 was not covered by tests

# The latest page might have a new issue.
if len(latest_page) > 0:
create_rag_git_issue_task(latest_page[0]).send()

Check warning on line 91 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L90-L91

Added lines #L90 - L91 were not covered by tests

Expand All @@ -109,10 +112,45 @@ def handle_repo_node(self):
issue_task = create_rag_git_issue_task(record)
issue_task.send()

Check warning on line 113 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L109-L113

Added lines #L109 - L113 were not covered by tests

return (self.get_table().update(
{"status": TaskStatus.COMPLETED.value})
.eq("id", self.id)
.execute())
return self.update_status(TaskStatus.COMPLETED)

Check warning on line 115 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L115

Added line #L115 was not covered by tests

def handle_issue_page_node(self):
repo = g.get_repo(self.repo_name)
issues = repo.get_issues(state='all').get_page(self.page_index)

Check warning on line 119 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L118-L119

Added lines #L118 - L119 were not covered by tests

task_list = list(
map(
lambda item: {
"repo_name": self.repo_name,
"issue_id": item.number,
"status": TaskStatus.NOT_STARTED.value,
"node_type": GitIssueTaskNodeType.ISSUE.value,
"from_task_id": self.id,
"bot_id": self.bot_id,
},
issues,
),
)
if len(task_list) > 0:
existing_issues = (self.get_table()

Check warning on line 135 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L135

Added line #L135 was not covered by tests
.select('*')
.in_('issue_id', [item['issue_id'] for item in task_list])
.eq('repo_name', self.repo_name)
.eq('node_type', GitIssueTaskNodeType.ISSUE.value)
.execute()
)

existing_issue_ids = {int(issue['issue_id']) for issue in existing_issues.data}

Check warning on line 143 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L143

Added line #L143 was not covered by tests

new_task_list = [item for item in task_list if item['issue_id'] not in existing_issue_ids]
if len(new_task_list) > 0:
result = self.get_table().insert(new_task_list).execute()
for record in result.data:
issue_task = create_rag_git_issue_task(record)
issue_task.send()

Check warning on line 150 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L145-L150

Added lines #L145 - L150 were not covered by tests

return self.update_status(TaskStatus.COMPLETED)

Check warning on line 152 in petercat_utils/rag_helper/git_issue_task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/git_issue_task.py#L152

Added line #L152 was not covered by tests


def handle_issue_node(self):
issue_retrieval.add_knowledge_by_issue(
Expand Down

0 comments on commit 6cb63be

Please sign in to comment.