diff --git a/server/tasks/github/issue.py b/server/tasks/github/issue.py index 078b7801..c80a0746 100644 --- a/server/tasks/github/issue.py +++ b/server/tasks/github/issue.py @@ -152,7 +152,13 @@ def on_issue_opened(event_dict: dict | None) -> list: return [] # 限制 body 长度 - issue_info.body = issue_info.body[:1000] if issue_info.body else None + issue_info.body = ( + issue_info.body[: 980 - len(issue_info.html_url)] + + "...\n\n点击查看全文: " + + issue_info.html_url + if len(issue_info.body) > 1000 + else issue_info.body + ) # 创建 issue new_issue = Issue( @@ -198,7 +204,14 @@ def on_issue_updated(event_dict: dict) -> list: if issue: issue.title = issue_info.title - issue.description = issue_info.body[:1000] if issue_info.body else None + issue_info.body = ( + issue_info.body[: 980 - len(issue_info.html_url)] + + "...\n\n点击查看全文: " + + issue_info.html_url + if len(issue_info.body) > 1000 + else issue_info.body + ) + issue.description = issue_info.body issue.extra = issue_info.model_dump() db.session.commit() diff --git a/server/tasks/github/pull_request.py b/server/tasks/github/pull_request.py index a1d37657..d80e713f 100644 --- a/server/tasks/github/pull_request.py +++ b/server/tasks/github/pull_request.py @@ -64,7 +64,13 @@ def on_pull_request_opened(event_dict: dict | list | None) -> list: return [] # 限制 body 长度 - pr_info.body = pr_info.body[:1000] if pr_info.body else "" + pr_info.body = ( + pr_info.body[: 980 - len(pr_info.html_url)] + + "...\n\n点击查看全文: " + + pr_info.html_url + if len(pr_info.body) > 1000 + else pr_info.body + ) # 创建 pullrequest new_pr = PullRequest( @@ -111,9 +117,14 @@ def on_pull_request_updated(event_dict: dict) -> list: ) if pr: pr.title = event.pull_request.title - pr.description = ( - event.pull_request.body[:1000] if event.pull_request.body else "" + event.pull_request.body = ( + event.pull_request.body[: 980 - len(event.pull_request.html_url)] + + "...\n\n点击查看全文: " + + event.pull_request.html_url + if len(event.pull_request.body) > 1000 + else event.pull_request.body ) + pr.description = event.pull_request.body pr.base = event.pull_request.base.ref pr.head = event.pull_request.head.ref pr.state = event.pull_request.state diff --git a/server/utils/github/model.py b/server/utils/github/model.py index b5ed46d0..ddbc99e8 100644 --- a/server/utils/github/model.py +++ b/server/utils/github/model.py @@ -62,6 +62,7 @@ class Issue(BaseModel): id: int number: int title: str + html_url: str body: Optional[str] = None state: str # open/closed labels: Optional[list[Label]] = [] @@ -96,6 +97,7 @@ class PullRequest(BaseModel): id: int number: int title: str + html_url: str body: Optional[str] = None state: str # open/closed merged: Optional[bool] = False