From 7b55b6fb995f3061d86dd35661ea342819578638 Mon Sep 17 00:00:00 2001 From: freeziyou <80776877@qq.com> Date: Mon, 11 Mar 2024 11:43:25 +0800 Subject: [PATCH 1/2] add desc tips --- server/tasks/github/issue.py | 20 +++++++++++++++++--- server/tasks/github/pull_request.py | 18 +++++++++++++++--- server/utils/github/model.py | 2 ++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/server/tasks/github/issue.py b/server/tasks/github/issue.py index 078b7801..de507aca 100644 --- a/server/tasks/github/issue.py +++ b/server/tasks/github/issue.py @@ -152,7 +152,15 @@ 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_desc = "" + if issue_info.body: + issue_desc = ( + 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( @@ -161,7 +169,7 @@ def on_issue_opened(event_dict: dict | None) -> list: issue_number=issue_info.number, title=issue_info.title, # TODO 这里超过1024的长度了,暂时不想单纯的增加字段长度,因为飞书那边消息也是有限制的 - description=issue_info.body, + description=issue_desc, extra=issue_info.model_dump(), ) db.session.add(new_issue) @@ -198,7 +206,13 @@ 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.description = ( + 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.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..f9f292e5 100644 --- a/server/tasks/github/pull_request.py +++ b/server/tasks/github/pull_request.py @@ -64,7 +64,15 @@ 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_desc = "" + if pr_info.body: + pr_desc = ( + 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( @@ -72,7 +80,7 @@ def on_pull_request_opened(event_dict: dict | list | None) -> list: repo_id=repo.id, pull_request_number=pr_info.number, title=pr_info.title, - description=pr_info.body, + description=pr_desc, base=pr_info.base.ref, head=pr_info.head.ref, state=pr_info.state, @@ -112,7 +120,11 @@ 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[: 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.base = event.pull_request.base.ref pr.head = event.pull_request.head.ref 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 From c7bf14413398a0091f308d9a3d955b817b878e7e Mon Sep 17 00:00:00 2001 From: freeziyou <80776877@qq.com> Date: Mon, 11 Mar 2024 11:50:43 +0800 Subject: [PATCH 2/2] add desc tips --- server/tasks/github/issue.py | 21 ++++++++++----------- server/tasks/github/pull_request.py | 21 ++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/server/tasks/github/issue.py b/server/tasks/github/issue.py index de507aca..c80a0746 100644 --- a/server/tasks/github/issue.py +++ b/server/tasks/github/issue.py @@ -152,15 +152,13 @@ def on_issue_opened(event_dict: dict | None) -> list: return [] # 限制 body 长度 - issue_desc = "" - if issue_info.body: - issue_desc = ( - 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_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( @@ -169,7 +167,7 @@ def on_issue_opened(event_dict: dict | None) -> list: issue_number=issue_info.number, title=issue_info.title, # TODO 这里超过1024的长度了,暂时不想单纯的增加字段长度,因为飞书那边消息也是有限制的 - description=issue_desc, + description=issue_info.body, extra=issue_info.model_dump(), ) db.session.add(new_issue) @@ -206,13 +204,14 @@ def on_issue_updated(event_dict: dict) -> list: if issue: issue.title = issue_info.title - issue.description = ( + 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 f9f292e5..d80e713f 100644 --- a/server/tasks/github/pull_request.py +++ b/server/tasks/github/pull_request.py @@ -64,15 +64,13 @@ def on_pull_request_opened(event_dict: dict | list | None) -> list: return [] # 限制 body 长度 - pr_desc = "" - if pr_info.body: - pr_desc = ( - 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 - ) + 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( @@ -80,7 +78,7 @@ def on_pull_request_opened(event_dict: dict | list | None) -> list: repo_id=repo.id, pull_request_number=pr_info.number, title=pr_info.title, - description=pr_desc, + description=pr_info.body, base=pr_info.base.ref, head=pr_info.head.ref, state=pr_info.state, @@ -119,13 +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 = ( 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