@@ -46,7 +46,7 @@ def get_hours_since_update(issue):
4646 return delta .total_seconds () / 3600
4747
4848
49- def check_task_timeout (token , repo , issue , config ):
49+ def check_task_timeout (token , repo , issue , config , verbose = False ):
5050 """
5151 Check if a task issue has timed out and send reminder if needed.
5252
@@ -55,24 +55,34 @@ def check_task_timeout(token, repo, issue, config):
5555 repo: Repository in "owner/name" format
5656 issue: Issue object from GitHub API
5757 config: Configuration dictionary
58+ verbose: Enable verbose logging
5859
5960 Returns:
6061 True if reminder was sent, False otherwise
6162 """
6263 # Get priority from labels
6364 priority = get_label_value (issue , config .get ("priority_pattern" , r"^P([012])$" ))
6465 if not priority :
66+ if verbose :
67+ print (f" ⊘ 跳过: 未找到优先级标签" )
6568 return False
6669
6770 # Get timeout hours for this priority
6871 timeout_key = f"P{ priority } "
6972 timeout_hours = config .get ("timeout_hours" , {}).get (timeout_key )
7073 if timeout_hours is None :
74+ if verbose :
75+ print (f" ⊘ 跳过: { timeout_key } 未配置超时时间" )
7176 return False
7277
7378 # Check if issue has timed out
7479 hours_since_update = get_hours_since_update (issue )
80+ if verbose :
81+ print (f" 优先级: { timeout_key } , 超时阈值: { timeout_hours } h, 距上次更新: { hours_since_update :.1f} h" )
82+
7583 if hours_since_update < timeout_hours :
84+ if verbose :
85+ print (f" ⊘ 跳过: 未超时" )
7686 return False
7787
7888 # Get assignees to mention
@@ -112,6 +122,8 @@ def check_task_timeout(token, repo, issue, config):
112122 )
113123
114124 # Add comment
125+ if verbose :
126+ print (f" ✓ 发送超时提醒" )
115127 comment (token , repo , issue_number , reminder_msg )
116128
117129 # Optional: Add a label to mark as reminded
@@ -122,14 +134,15 @@ def check_task_timeout(token, repo, issue, config):
122134 return True
123135
124136
125- def scan_repo_tasks (token , repo , config ):
137+ def scan_repo_tasks (token , repo , config , verbose = False ):
126138 """
127139 Scan a single repository for task issues that need reminders.
128140
129141 Args:
130142 token: GitHub API token
131143 repo: Repository in "owner/name" format
132144 config: Configuration dictionary
145+ verbose: Enable verbose logging
133146
134147 Returns:
135148 Number of reminders sent
@@ -153,33 +166,45 @@ def scan_repo_tasks(token, repo, config):
153166 print (f"Error searching { repo } : { e } " )
154167 return 0
155168
169+ if verbose :
170+ print (f"找到 { len (issues )} 个待检查的任务 Issue\n " )
171+
156172 # Filter issues by priority and check for timeouts
157173 priority_filter = config .get ("priorities_to_check" , ["P0" , "P1" , "P2" ])
158174 priority_pattern = config .get ("priority_pattern" , r"^P([012])$" )
159175
160176 reminders_sent = 0
161177 for issue in issues :
178+ if verbose :
179+ print (f"检查 Issue #{ issue ['number' ]} : { issue ['title' ]} " )
180+
162181 # Check if issue has one of the target priorities
163182 priority = get_label_value (issue , priority_pattern )
164183 if not priority or f"P{ priority } " not in priority_filter :
184+ if verbose :
185+ print (f" ⊘ 跳过: 优先级 P{ priority } 不在检查范围 { priority_filter } \n " )
165186 continue
166187
167188 # Check if timeout and send reminder
168- if check_task_timeout (token , repo , issue , config ):
189+ if check_task_timeout (token , repo , issue , config , verbose = verbose ):
169190 reminders_sent += 1
170- print (f"Sent reminder for { repo } #{ issue ['number' ]} : { issue ['title' ]} " )
191+ print (f"✓ 发送提醒 { repo } #{ issue ['number' ]} : { issue ['title' ]} " )
192+
193+ if verbose :
194+ print ()
171195
172196 return reminders_sent
173197
174198
175- def scan_org_tasks (token , org , config ):
199+ def scan_org_tasks (token , org , config , verbose = False ):
176200 """
177201 Scan all repositories in an organization for task issues.
178202
179203 Args:
180204 token: GitHub API token
181205 org: Organization name
182206 config: Configuration dictionary
207+ verbose: Enable verbose logging
183208
184209 Returns:
185210 Number of reminders sent
@@ -191,6 +216,9 @@ def scan_org_tasks(token, org, config):
191216 print (f"Error listing repos for { org } : { e } " )
192217 return 0
193218
219+ if verbose :
220+ print (f"组织 { org } 中找到 { len (repos )} 个仓库\n " )
221+
194222 # Scan each repository
195223 total_reminders = 0
196224 for repo_obj in repos :
@@ -199,19 +227,27 @@ def scan_org_tasks(token, org, config):
199227 # Check if repo should be excluded
200228 exclude_repos = config .get ("exclude_repos" , [])
201229 if repo_full_name in exclude_repos or repo_obj ["name" ] in exclude_repos :
202- print (f"Skipping excluded repo: { repo_full_name } " )
230+ if verbose :
231+ print (f"⊘ 跳过排除的仓库: { repo_full_name } \n " )
232+ else :
233+ print (f"Skipping excluded repo: { repo_full_name } " )
203234 continue
204235
205- print (f"Scanning { repo_full_name } ... " )
206- reminders = scan_repo_tasks (token , repo_full_name , config )
236+ print (f"扫描仓库: { repo_full_name } " )
237+ reminders = scan_repo_tasks (token , repo_full_name , config , verbose = verbose )
207238 total_reminders += reminders
239+ if verbose :
240+ print ()
208241
209242 return total_reminders
210243
211244
212- def check ():
245+ def check (verbose = False ):
213246 """
214247 Main function to check tasks and send reminders based on configuration.
248+
249+ Args:
250+ verbose: Enable verbose logging
215251 """
216252 # Load configuration
217253 config_path = Path (__file__ ).parent .parent / "config" / "task-checker.yml"
@@ -225,25 +261,32 @@ def check():
225261 # Get scan scope
226262 scan_mode = cfg .get ("scan_mode" , "repo" ) # "repo" or "org"
227263
264+ if verbose :
265+ print (f"扫描模式: { scan_mode } " )
266+ print (f"任务标签: { cfg .get ('task_label' , 'Task' )} " )
267+ print (f"检查优先级: { cfg .get ('priorities_to_check' , ['P0' , 'P1' , 'P2' ])} " )
268+ print (f"超时配置: { cfg .get ('timeout_hours' , {})} " )
269+ print ()
270+
228271 if scan_mode == "org" :
229272 # Scan entire organization
230273 org = cfg .get ("org" , "" ).strip ()
231274 if not org :
232275 raise ValueError ("Organization (org) must be set in config when scan_mode is 'org'" )
233276
234- print (f"Scanning organization : { org } " )
235- reminders_sent = scan_org_tasks (token , org , cfg )
236- print (f"\n Total reminders sent : { reminders_sent } " )
277+ print (f"扫描组织 : { org } " )
278+ reminders_sent = scan_org_tasks (token , org , cfg , verbose = verbose )
279+ print (f"\n 总计发送提醒 : { reminders_sent } " )
237280
238281 elif scan_mode == "repo" :
239282 # Scan single repository
240283 repo = cfg .get ("repo" , "" ).strip ()
241284 if not repo :
242285 raise ValueError ("Repository (repo) must be set in config when scan_mode is 'repo'" )
243286
244- print (f"Scanning repository : { repo } " )
245- reminders_sent = scan_repo_tasks (token , repo , cfg )
246- print (f"\n Total reminders sent : { reminders_sent } " )
287+ print (f"扫描仓库 : { repo } " )
288+ reminders_sent = scan_repo_tasks (token , repo , cfg , verbose = verbose )
289+ print (f"\n 总计发送提醒 : { reminders_sent } " )
247290
248291 else :
249292 raise ValueError (f"Invalid scan_mode: { scan_mode } . Must be 'repo' or 'org'" )
0 commit comments