-
Notifications
You must be signed in to change notification settings - Fork 79
feat: issue task control #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MadratJerry
wants to merge
4
commits into
main
Choose a base branch
from
feat/issue-task-control
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
from ..data_class import GitIssueTaskNodeType, TaskStatus, TaskType, RAGGitIssueConfig | ||
from ..rag_helper import issue_retrieval | ||
|
||
g = Github() | ||
GITHUB_PER_PAGE = 30 | ||
g = Github(per_page=GITHUB_PER_PAGE) | ||
|
||
|
||
def add_rag_git_issue_task(config: RAGGitIssueConfig): | ||
|
@@ -22,8 +23,21 @@ | |
return res | ||
|
||
|
||
def create_rag_git_issue_task(record): | ||
return GitIssueTask(id=record["id"], | ||
issue_id=record["issue_id"], | ||
repo_name=record["repo_name"], | ||
node_type=record["node_type"], | ||
bot_id=record["bot_id"], | ||
status=record["status"], | ||
from_id=record["from_task_id"], | ||
page_index=record["page_index"] | ||
) | ||
|
||
|
||
class GitIssueTask(GitTask): | ||
issue_id: str | ||
issue_id: int | ||
page_index: int | ||
node_type: GitIssueTaskNodeType | ||
|
||
def __init__(self, | ||
|
@@ -33,11 +47,13 @@ | |
repo_name, | ||
status=TaskStatus.NOT_STARTED, | ||
from_id=None, | ||
id=None | ||
id=None, | ||
page_index=None | ||
): | ||
super().__init__(bot_id=bot_id, type=TaskType.GIT_ISSUE, from_id=from_id, id=id, status=status, | ||
repo_name=repo_name) | ||
self.issue_id = issue_id | ||
self.page_index = page_index | ||
self.node_type = GitIssueTaskNodeType(node_type) | ||
|
||
def extra_save_data(self): | ||
|
@@ -50,20 +66,63 @@ | |
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() | ||
elif self.node_type == GitIssueTaskNodeType.ISSUE: | ||
return self.handle_issue_node() | ||
else: | ||
raise ValueError(f"Unsupported node type [{self.node_type}]") | ||
|
||
def handle_repo_node(self): | ||
repo = g.get_repo(self.repo_name) | ||
repo.get_issues() | ||
issues = [issue for issue in repo.get_issues()] | ||
issues = repo.get_issues(state='all') | ||
latest_page = (self.get_table() | ||
.select('*') | ||
.eq('repo_name', self.repo_name) | ||
.eq('node_type', GitIssueTaskNodeType.ISSUE_PAGE.value) | ||
.order('page_index', desc=True) | ||
.limit(1) | ||
.execute()).data | ||
|
||
slice_page_index = latest_page[0]["page_index"] if len(latest_page) > 0 else 0 | ||
|
||
# The latest page might have a new issue. | ||
if len(latest_page) > 0: | ||
create_rag_git_issue_task(latest_page[0]).send() | ||
|
||
if issues.totalCount > 0: | ||
pages = issues.totalCount // GITHUB_PER_PAGE + (1 if issues.totalCount % GITHUB_PER_PAGE != 0 else 0) | ||
pages_array = list(range(1, pages + 1))[slice_page_index:] | ||
task_list = list( | ||
map( | ||
lambda item: { | ||
"repo_name": self.repo_name, | ||
"status": TaskStatus.NOT_STARTED.value, | ||
"node_type": GitIssueTaskNodeType.ISSUE_PAGE.value, | ||
"from_task_id": self.id, | ||
"bot_id": self.bot_id, | ||
"page_index": item | ||
}, | ||
pages_array, | ||
), | ||
) | ||
if len(task_list) > 0: | ||
result = self.get_table().insert(task_list).execute() | ||
for record in result.data: | ||
issue_task = create_rag_git_issue_task(record) | ||
issue_task.send() | ||
|
||
return self.update_status(TaskStatus.COMPLETED) | ||
|
||
def handle_issue_page_node(self): | ||
repo = g.get_repo(self.repo_name) | ||
issues = repo.get_issues(state='all').get_page(self.page_index) | ||
|
||
task_list = list( | ||
map( | ||
lambda item: { | ||
"repo_name": self.repo_name, | ||
"issue_id": str(item.number), | ||
"issue_id": item.number, | ||
"status": TaskStatus.NOT_STARTED.value, | ||
"node_type": GitIssueTaskNodeType.ISSUE.value, | ||
"from_task_id": self.id, | ||
|
@@ -73,22 +132,25 @@ | |
), | ||
) | ||
if len(task_list) > 0: | ||
result = self.get_table().insert(task_list).execute() | ||
for record in result.data: | ||
issue_task = GitIssueTask(id=record["id"], | ||
issue_id=record["issue_id"], | ||
repo_name=record["repo_name"], | ||
node_type=record["node_type"], | ||
bot_id=record["bot_id"], | ||
status=record["status"], | ||
from_id=record["from_task_id"] | ||
) | ||
issue_task.send() | ||
|
||
return (self.get_table().update( | ||
{"status": TaskStatus.COMPLETED.value}) | ||
.eq("id", self.id) | ||
.execute()) | ||
existing_issues = (self.get_table() | ||
.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} | ||
|
||
new_task_list = [item for item in task_list if item['issue_id'] not in existing_issue_ids] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
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() | ||
|
||
return self.update_status(TaskStatus.COMPLETED) | ||
|
||
|
||
def handle_issue_node(self): | ||
issue_retrieval.add_knowledge_by_issue( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
handle_issue_page_node
method does not handle the case whererepo.get_issues(state='all').get_page(self.page_index)
returns an empty list. This could lead to potential errors when processing issues.