mirror of
https://github.com/Xtao-Labs/QQ-GitHub-Bot.git
synced 2025-01-30 15:08:54 +00:00
⚗️ add label event and event debug notify
This commit is contained in:
parent
e69ade0823
commit
34a076c767
39
.editorconfig
Normal file
39
.editorconfig
Normal file
@ -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
|
@ -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):
|
||||
@ -90,16 +91,15 @@ class Issue(BaseModel):
|
||||
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:
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -0,0 +1,24 @@
|
||||
<!--
|
||||
* @Author : yanyongyu
|
||||
* @Date : 2021-05-21 14:18:00
|
||||
* @LastEditors : yanyongyu
|
||||
* @LastEditTime : 2021-05-21 14:54:45
|
||||
* @Description : None
|
||||
* @GitHub : https://github.com/yanyongyu
|
||||
-->
|
||||
|
||||
<a
|
||||
class="IssueLabel"
|
||||
style="
|
||||
--label-r: {{ labelcolor[:2]|int(base=16) }};
|
||||
--label-g: {{ labelcolor[2:4]|int(base=16) }};
|
||||
--label-b: {{ labelcolor[4:]|int(base=16) }};
|
||||
--lightness-threshold: 0.453;
|
||||
--perceived-lightness: calc((var(--label-r)*0.2126 + var(--label-g)*0.7152 + var(--label-b)*0.0722)/255);
|
||||
--lightness-switch: max(0,min(calc((var(--perceived-lightness) - var(--lightness-threshold))*-1000),1));
|
||||
background: rgb(var(--label-r),var(--label-g),var(--label-b));
|
||||
color: hsl(0,0%,calc(var(--lightness-switch)*100%));
|
||||
"
|
||||
>
|
||||
{{ labelname }}
|
||||
</a>
|
@ -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
|
||||
-->
|
||||
@ -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" -%}
|
||||
@ -60,6 +63,7 @@
|
||||
{%- else -%}
|
||||
<!-- TODO: other events -->
|
||||
<!-- prettier-ignore -->
|
||||
{{ event|debug_event }}
|
||||
{%- endif %}
|
||||
|
||||
{%- endfor %}
|
||||
|
44
src/plugins/github/libs/issue/templates/label.html
Normal file
44
src/plugins/github/libs/issue/templates/label.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!--
|
||||
* @Author : yanyongyu
|
||||
* @Date : 2021-05-21 14:02:04
|
||||
* @LastEditors : yanyongyu
|
||||
* @LastEditTime : 2021-05-21 14:21:09
|
||||
* @Description : None
|
||||
* @GitHub : https://github.com/yanyongyu
|
||||
-->
|
||||
|
||||
<div class="TimelineItem">
|
||||
<div class="TimelineItem-badge">
|
||||
<svg
|
||||
class="octicon octicon-tag"
|
||||
viewBox="0 0 16 16"
|
||||
version="1.1"
|
||||
width="16"
|
||||
height="16"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M2.5 7.775V2.75a.25.25 0 01.25-.25h5.025a.25.25 0 01.177.073l6.25 6.25a.25.25 0 010 .354l-5.025 5.025a.25.25 0 01-.354 0l-6.25-6.25a.25.25 0 01-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 010 2.474l-5.026 5.026a1.75 1.75 0 01-2.474 0l-6.25-6.25A1.75 1.75 0 011 7.775zM6 5a1 1 0 100 2 1 1 0 000-2z"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="TimelineItem-body">
|
||||
<a class="d-inline-block">
|
||||
<img
|
||||
class="avatar avatar-user"
|
||||
height="20"
|
||||
width="20"
|
||||
src="{{ event.actor.avatar_url }}"
|
||||
/>
|
||||
</a>
|
||||
<a class="author Link--primary text-bold"> {{ event.actor.login }} </a>
|
||||
<!-- prettier-ignore -->
|
||||
added
|
||||
{% set labelname = event.label.name %}
|
||||
{% set labelcolor = event.label.color %}
|
||||
{% include "components/issue-label.html" %}
|
||||
label
|
||||
<a class="Link--secondary">{{event.created_at|relative_time}}</a>
|
||||
</div>
|
||||
</div>
|
@ -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 @@
|
||||
</a>
|
||||
<!-- prettier-ignore -->
|
||||
{%- endif %}
|
||||
{{event.created_at|relative_time}}
|
||||
<a class="Link--secondary">{{event.created_at|relative_time}}</a>
|
||||
</div>
|
||||
</div>
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user