Skip to content
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

desc截断末尾添加全文url #246

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions server/tasks/github/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 14 additions & 3 deletions server/tasks/github/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions server/utils/github/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = []
Expand Down Expand Up @@ -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
Expand Down
Loading