-
Notifications
You must be signed in to change notification settings - Fork 1
fix(server.py): 修复issue关闭时误触发action的问题 #86
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -745,6 +745,27 @@ async def handle_notification(client: httpx.AsyncClient, note: Dict): | |||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # 检查通知类型 - 只处理 issue 和 pull_request 类型 | ||||||||||||||||||||||||||||||
| # GitHub 通知的 subject.type 可以是: "Issue", "PullRequest", "Commit", "Discussion" 等 | ||||||||||||||||||||||||||||||
| # 但 issue 关闭等事件也会触发通知,我们需要检查 URL 中是否包含事件信息 | ||||||||||||||||||||||||||||||
| subject_type = note.get("subject", {}).get("type") | ||||||||||||||||||||||||||||||
| logger.info(f"Notification subject type: {subject_type}") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # 检查 URL 中是否包含事件类型(如 /issues/123 可能是 issue 关闭事件) | ||||||||||||||||||||||||||||||
| # 我们需要确保只处理真正包含 @mention 的内容,而不是所有相关事件 | ||||||||||||||||||||||||||||||
| # 例如:issue 被关闭时,如果之前被 @mention 过,也会触发通知 | ||||||||||||||||||||||||||||||
| # 但这种通知不应该触发 workflow,因为没有新的 @mention | ||||||||||||||||||||||||||||||
| if subject_type and subject_type not in ["Issue", "PullRequest", "Commit", "Discussion"]: | ||||||||||||||||||||||||||||||
WhiteElephant-abc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
| logger.info(f"Ignoring notification with unsupported subject type: {subject_type}") | ||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
| await client.patch( | ||||||||||||||||||||||||||||||
| f"{REST_API}/notifications/threads/{thread_id}", | ||||||||||||||||||||||||||||||
| headers={"Authorization": f"token {BOT_TOKEN}"} | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| except: | ||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| try: | |
| await client.patch( | |
| f"{REST_API}/notifications/threads/{thread_id}", | |
| headers={"Authorization": f"token {BOT_TOKEN}"} | |
| ) | |
| except: | |
| pass | |
| try: | |
| await client.patch( | |
| f"{REST_API}/notifications/threads/{thread_id}", | |
| headers={"Authorization": f"token {BOT_TOKEN}"} | |
| ) | |
| except Exception as e: | |
| logger.warning(f"Failed to mark notification {thread_id} as read: {e}") |
Outdated
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.
Outdated
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.
与之前的代码块类似,这里也使用了空的 except: 块。这会隐藏所有潜在的错误,使得问题排查变得困难。建议捕获具体的 Exception 并记录日志,以便了解API调用失败的原因。
| try: | |
| await client.patch( | |
| f"{REST_API}/notifications/threads/{thread_id}", | |
| headers={"Authorization": f"token {BOT_TOKEN}"} | |
| ) | |
| except: | |
| pass | |
| try: | |
| await client.patch( | |
| f"{REST_API}/notifications/threads/{thread_id}", | |
| headers={"Authorization": f"token {BOT_TOKEN}"} | |
| ) | |
| except Exception as e: | |
| logger.warning(f"Failed to mark notification {thread_id} as read: {e}") |
Outdated
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.
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.
这里的注释有些过时和误导性。第一行说只处理
issue和pull_request,但代码实际上还处理了Commit和Discussion。第三行说要检查 URL,但代码检查的是subject.type。建议更新注释以匹配代码逻辑,提高可维护性。