4
4
from ..data_class import GitIssueTaskNodeType , TaskStatus , TaskType , RAGGitIssueConfig
5
5
from ..rag_helper import issue_retrieval
6
6
7
- g = Github ()
7
+ GITHUB_PER_PAGE = 30
8
+ g = Github (per_page = GITHUB_PER_PAGE )
8
9
9
10
10
11
def add_rag_git_issue_task (config : RAGGitIssueConfig ):
@@ -24,16 +25,19 @@ def add_rag_git_issue_task(config: RAGGitIssueConfig):
24
25
25
26
def create_rag_git_issue_task (record ):
26
27
return GitIssueTask (id = record ["id" ],
27
- issue_id = record ["issue_id" ],
28
- repo_name = record ["repo_name" ],
29
- node_type = record ["node_type" ],
30
- bot_id = record ["bot_id" ],
31
- status = record ["status" ],
32
- from_id = record ["from_task_id" ],
33
- page_index = record ["page_index" ]
34
- )
28
+ issue_id = record ["issue_id" ],
29
+ repo_name = record ["repo_name" ],
30
+ node_type = record ["node_type" ],
31
+ bot_id = record ["bot_id" ],
32
+ status = record ["status" ],
33
+ from_id = record ["from_task_id" ],
34
+ page_index = record ["page_index" ]
35
+ )
36
+
37
+
35
38
class GitIssueTask (GitTask ):
36
- issue_id : str
39
+ issue_id : int
40
+ page_index : int
37
41
node_type : GitIssueTaskNodeType
38
42
39
43
def __init__ (self ,
@@ -43,11 +47,13 @@ def __init__(self,
43
47
repo_name ,
44
48
status = TaskStatus .NOT_STARTED ,
45
49
from_id = None ,
46
- id = None
50
+ id = None ,
51
+ page_index = None
47
52
):
48
53
super ().__init__ (bot_id = bot_id , type = TaskType .GIT_ISSUE , from_id = from_id , id = id , status = status ,
49
54
repo_name = repo_name )
50
55
self .issue_id = issue_id
56
+ self .page_index = page_index
51
57
self .node_type = GitIssueTaskNodeType (node_type )
52
58
53
59
def extra_save_data (self ):
@@ -67,33 +73,41 @@ def handle(self):
67
73
68
74
def handle_repo_node (self ):
69
75
repo = g .get_repo (self .repo_name )
70
- repo .get_issues ()
71
- issues = [issue for issue in repo .get_issues ()]
72
- task_list = list (
73
- map (
74
- lambda item : {
75
- "repo_name" : self .repo_name ,
76
- "issue_id" : str (item .number ),
77
- "status" : TaskStatus .NOT_STARTED .value ,
78
- "node_type" : GitIssueTaskNodeType .ISSUE .value ,
79
- "from_task_id" : self .id ,
80
- "bot_id" : self .bot_id ,
81
- },
82
- issues ,
83
- ),
84
- )
85
- if len (task_list ) > 0 :
86
- result = self .get_table ().insert (task_list ).execute ()
87
- for record in result .data :
88
- issue_task = GitIssueTask (id = record ["id" ],
89
- issue_id = record ["issue_id" ],
90
- repo_name = record ["repo_name" ],
91
- node_type = record ["node_type" ],
92
- bot_id = record ["bot_id" ],
93
- status = record ["status" ],
94
- from_id = record ["from_task_id" ]
95
- )
96
- issue_task .send ()
76
+ issues = repo .get_issues (state = 'all' )
77
+ latest_page = (self .get_table ()
78
+ .select ('*' )
79
+ .eq ('repo_name' , self .repo_name )
80
+ .eq ('node_type' , GitIssueTaskNodeType .ISSUE_PAGE .value )
81
+ .order ('page_index' , desc = True )
82
+ .limit (1 )
83
+ .execute ()).data
84
+
85
+ slice_page_index = latest_page [0 ]["page_index" ] if len (latest_page ) > 0 else 0
86
+
87
+ if len (latest_page ) > 0 :
88
+ create_rag_git_issue_task (latest_page [0 ]).send ()
89
+
90
+ if issues .totalCount > 0 :
91
+ pages = issues .totalCount // GITHUB_PER_PAGE + (1 if issues .totalCount % GITHUB_PER_PAGE != 0 else 0 )
92
+ pages_array = list (range (1 , pages + 1 ))[slice_page_index :]
93
+ task_list = list (
94
+ map (
95
+ lambda item : {
96
+ "repo_name" : self .repo_name ,
97
+ "status" : TaskStatus .NOT_STARTED .value ,
98
+ "node_type" : GitIssueTaskNodeType .ISSUE_PAGE .value ,
99
+ "from_task_id" : self .id ,
100
+ "bot_id" : self .bot_id ,
101
+ "page_index" : item
102
+ },
103
+ pages_array ,
104
+ ),
105
+ )
106
+ if len (task_list ) > 0 :
107
+ result = self .get_table ().insert (task_list ).execute ()
108
+ for record in result .data :
109
+ issue_task = create_rag_git_issue_task (record )
110
+ issue_task .send ()
97
111
98
112
return (self .get_table ().update (
99
113
{"status" : TaskStatus .COMPLETED .value })
0 commit comments