From 34a076c767440c9e98f000dea156b3c6af9b6139 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Fri, 21 May 2021 15:07:04 +0800 Subject: [PATCH] :alembic: add label event and event debug notify --- .editorconfig | 39 ++++++++++++++++ src/libs/github/models/issue.py | 28 ++++++------ src/libs/github/models/timeline.py | 26 +++++------ src/plugins/github/libs/issue/render.py | 15 ++++++- .../templates/components/issue-label.html | 24 ++++++++++ .../github/libs/issue/templates/issue.html | 12 +++-- .../github/libs/issue/templates/label.html | 44 +++++++++++++++++++ ...eview_request.html => review-request.html} | 4 +- src/plugins/nonebot_plugin_sentry/config.py | 3 +- 9 files changed, 158 insertions(+), 37 deletions(-) create mode 100644 .editorconfig create mode 100644 src/plugins/github/libs/issue/templates/components/issue-label.html create mode 100644 src/plugins/github/libs/issue/templates/label.html rename src/plugins/github/libs/issue/templates/{review_request.html => review-request.html} (94%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fe19866 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,39 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +# The JSON files contain newlines inconsistently +[*.json] +insert_final_newline = ignore + +# Minified JavaScript files shouldn't be changed +[**.min.js] +indent_style = ignore +insert_final_newline = ignore + +# Makefiles always use tabs for indentation +[Makefile] +indent_style = tab + +# Batch files use tabs for indentation +[*.bat] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false + +# Matches the exact files either package.json or .travis.yml +[{package.json,.travis.yml}] +indent_size = 2 + +[{*.py,*.pyi}] +indent_size = 4 diff --git a/src/libs/github/models/issue.py b/src/libs/github/models/issue.py index e16f8e3..8dd99ea 100644 --- a/src/libs/github/models/issue.py +++ b/src/libs/github/models/issue.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2021-03-11 16:57:04 @LastEditors : yanyongyu -@LastEditTime : 2021-05-21 01:02:36 +@LastEditTime : 2021-05-21 14:43:11 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -23,7 +23,8 @@ from .comment import Comment from .timeline import (TimelineEvent, TimelineEventCommited, TimelineEventCommented, TimelineEventReviewed, TimelineEventReviewRequested, TimelineEventRenamed, - TimelineEventMerged, TimelineEventClosed) + TimelineEventLabeled, TimelineEventMerged, + TimelineEventClosed) class IssuePullRequest(_BaseModel): @@ -71,7 +72,7 @@ class Issue(BaseModel): async def get_comments(self) -> PaginatedList[Comment]: """ GET /repo/:full_name/issues/:number/comments - + https://docs.github.com/en/rest/reference/issues#list-issue-comments """ headers = {"Accept": "application/vnd.github.v3.full+json"} @@ -84,22 +85,21 @@ class Issue(BaseModel): async def get_timeline(self) -> PaginatedList[TimelineEvent]: """ GET /repo/:full_name/issues/:number/timeline - + https://docs.github.com/en/rest/reference/issues#list-timeline-events-for-an-issue """ headers = { "Accept": "application/vnd.github.mockingbird-preview.full+json" } - return PaginatedList(Union[TimelineEventCommited, - TimelineEventCommented, - TimelineEventReviewed, - TimelineEventReviewRequested, - TimelineEventRenamed, TimelineEventMerged, - TimelineEventClosed, TimelineEvent], - self.requester, - "GET", - self.timeline_url, - headers=headers) + return PaginatedList( + Union[TimelineEventCommited, TimelineEventCommented, + TimelineEventReviewed, TimelineEventReviewRequested, + TimelineEventRenamed, TimelineEventLabeled, + TimelineEventMerged, TimelineEventClosed, TimelineEvent], + self.requester, + "GET", + self.timeline_url, + headers=headers) async def get_diff(self) -> str: """ diff --git a/src/libs/github/models/timeline.py b/src/libs/github/models/timeline.py index 231fe81..d6bc698 100644 --- a/src/libs/github/models/timeline.py +++ b/src/libs/github/models/timeline.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2021-05-14 00:57:33 @LastEditors : yanyongyu -@LastEditTime : 2021-05-21 02:24:18 +@LastEditTime : 2021-05-21 14:47:24 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -100,7 +100,7 @@ class TimelineEventReviewed(TimelineEvent): pull_request_url: str author_association: str submitted_at: datetime - body: str + body: Optional[str] body_text: Optional[str] body_html: Optional[str] links: TimelineEventReviewedLinks = Field(alias="_links") @@ -136,17 +136,6 @@ class TimelineEventRenamed(TimelineEvent): rename: TimelineEventRenamedDetail -class TimelineEventMerged(TimelineEvent): - event: Literal["merged"] - id: int - node_id: str - url: str - actor: User - commit_id: str - commit_url: str - created_at: datetime - - class TimelineEventLabeledInfo(_BaseModel): name: str color: str @@ -164,6 +153,17 @@ class TimelineEventLabeled(TimelineEvent): label: TimelineEventLabeledInfo +class TimelineEventMerged(TimelineEvent): + event: Literal["merged"] + id: int + node_id: str + url: str + actor: User + commit_id: str + commit_url: str + created_at: datetime + + class TimelineEventClosed(TimelineEvent): event: Literal["closed"] id: int diff --git a/src/plugins/github/libs/issue/render.py b/src/plugins/github/libs/issue/render.py index 05d350c..5bbd93f 100644 --- a/src/plugins/github/libs/issue/render.py +++ b/src/plugins/github/libs/issue/render.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2021-05-14 17:09:12 @LastEditors : yanyongyu -@LastEditTime : 2021-05-16 23:52:11 +@LastEditTime : 2021-05-21 15:04:44 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -18,8 +18,9 @@ from datetime import datetime import jinja2 import humanize from unidiff import PatchSet +from nonebot.log import logger -from src.libs.github.models import Issue +from src.libs.github.models import Issue, TimelineEvent env = jinja2.Environment(extensions=["jinja2.ext.loopcontrols"], loader=jinja2.FileSystemLoader( @@ -44,9 +45,19 @@ def review_state(value: str) -> str: return states.get(value, value) +def debug_event(event: TimelineEvent): + # not sub class of TimelineEvent + if type(event) is TimelineEvent: + # event not passed process + logger.error(f"Unhandled event type: {event.event}", event=event.dict()) + return "" + return event + + env.filters["classname"] = classname env.filters["relative_time"] = relative_time env.filters["review_state"] = review_state +env.filters["debug_event"] = debug_event async def issue_to_html(owner: str, repo_name: str, issue: Issue) -> str: diff --git a/src/plugins/github/libs/issue/templates/components/issue-label.html b/src/plugins/github/libs/issue/templates/components/issue-label.html new file mode 100644 index 0000000..98e5faf --- /dev/null +++ b/src/plugins/github/libs/issue/templates/components/issue-label.html @@ -0,0 +1,24 @@ + + + + {{ labelname }} + diff --git a/src/plugins/github/libs/issue/templates/issue.html b/src/plugins/github/libs/issue/templates/issue.html index c81483e..f855b17 100644 --- a/src/plugins/github/libs/issue/templates/issue.html +++ b/src/plugins/github/libs/issue/templates/issue.html @@ -2,7 +2,7 @@ * @Author : yanyongyu * @Date : 2021-05-14 17:11:26 * @LastEditors : yanyongyu - * @LastEditTime : 2021-05-17 10:06:44 + * @LastEditTime : 2021-05-21 15:05:28 * @Description : None * @GitHub : https://github.com/yanyongyu --> @@ -23,7 +23,7 @@ {% set event = issue %} {% set showavatar = true %} {% set ns = namespace(merged=false) %} - + {% include "comment.html" %} {% for event in timeline -%} @@ -38,11 +38,14 @@ {% include "review.html" %} {% elif event|classname == "TimelineEventReviewRequested" -%} - {% include "review_request.html" %} + {% include "review-request.html" %} {% elif event|classname == "TimelineEventRenamed" -%} {% include "rename.html" %} + {% elif event|classname == "TimelineEventLabeled" -%} + {% include "label.html" %} + {% elif event|classname == "TimelineEventMerged" -%} {% include "merge.html" %} {% if loop.nextitem|classname == "TimelineEventClosed" -%} @@ -56,10 +59,11 @@ {%- else -%} {% include "close.html" %} {%- endif %} - + {%- else -%} + {{ event|debug_event }} {%- endif %} {%- endfor %} diff --git a/src/plugins/github/libs/issue/templates/label.html b/src/plugins/github/libs/issue/templates/label.html new file mode 100644 index 0000000..1504145 --- /dev/null +++ b/src/plugins/github/libs/issue/templates/label.html @@ -0,0 +1,44 @@ + + +
+
+ +
+
+ + + + {{ event.actor.login }} + + added + {% set labelname = event.label.name %} + {% set labelcolor = event.label.color %} + {% include "components/issue-label.html" %} + label + {{event.created_at|relative_time}} +
+
diff --git a/src/plugins/github/libs/issue/templates/review_request.html b/src/plugins/github/libs/issue/templates/review-request.html similarity index 94% rename from src/plugins/github/libs/issue/templates/review_request.html rename to src/plugins/github/libs/issue/templates/review-request.html index fcb4415..c054293 100644 --- a/src/plugins/github/libs/issue/templates/review_request.html +++ b/src/plugins/github/libs/issue/templates/review-request.html @@ -2,7 +2,7 @@ * @Author : yanyongyu * @Date : 2021-05-21 01:06:07 * @LastEditors : yanyongyu - * @LastEditTime : 2021-05-21 01:19:04 + * @LastEditTime : 2021-05-21 14:21:02 * @Description : None * @GitHub : https://github.com/yanyongyu --> @@ -47,6 +47,6 @@ {%- endif %} - {{event.created_at|relative_time}} + {{event.created_at|relative_time}} diff --git a/src/plugins/nonebot_plugin_sentry/config.py b/src/plugins/nonebot_plugin_sentry/config.py index a3fc3fb..ab3f6e4 100644 --- a/src/plugins/nonebot_plugin_sentry/config.py +++ b/src/plugins/nonebot_plugin_sentry/config.py @@ -4,7 +4,7 @@ @Author : yanyongyu @Date : 2020-11-23 18:44:18 @LastEditors : yanyongyu -@LastEditTime : 2020-11-23 22:15:27 +@LastEditTime : 2021-05-21 14:56:31 @Description : None @GitHub : https://github.com/yanyongyu """ @@ -19,7 +19,6 @@ class Config(BaseSettings): sentry_dsn: str sentry_debug: bool = False sentry_release: Optional[str] = None - sentry_release: Optional[str] = None sentry_environment: Optional[str] = None sentry_server_name: Optional[str] = None sentry_sample_rate: float = 1.