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
|
@Author : yanyongyu
|
||||||
@Date : 2021-03-11 16:57:04
|
@Date : 2021-03-11 16:57:04
|
||||||
@LastEditors : yanyongyu
|
@LastEditors : yanyongyu
|
||||||
@LastEditTime : 2021-05-21 01:02:36
|
@LastEditTime : 2021-05-21 14:43:11
|
||||||
@Description : None
|
@Description : None
|
||||||
@GitHub : https://github.com/yanyongyu
|
@GitHub : https://github.com/yanyongyu
|
||||||
"""
|
"""
|
||||||
@ -23,7 +23,8 @@ from .comment import Comment
|
|||||||
from .timeline import (TimelineEvent, TimelineEventCommited,
|
from .timeline import (TimelineEvent, TimelineEventCommited,
|
||||||
TimelineEventCommented, TimelineEventReviewed,
|
TimelineEventCommented, TimelineEventReviewed,
|
||||||
TimelineEventReviewRequested, TimelineEventRenamed,
|
TimelineEventReviewRequested, TimelineEventRenamed,
|
||||||
TimelineEventMerged, TimelineEventClosed)
|
TimelineEventLabeled, TimelineEventMerged,
|
||||||
|
TimelineEventClosed)
|
||||||
|
|
||||||
|
|
||||||
class IssuePullRequest(_BaseModel):
|
class IssuePullRequest(_BaseModel):
|
||||||
@ -71,7 +72,7 @@ class Issue(BaseModel):
|
|||||||
async def get_comments(self) -> PaginatedList[Comment]:
|
async def get_comments(self) -> PaginatedList[Comment]:
|
||||||
"""
|
"""
|
||||||
GET /repo/:full_name/issues/:number/comments
|
GET /repo/:full_name/issues/:number/comments
|
||||||
|
|
||||||
https://docs.github.com/en/rest/reference/issues#list-issue-comments
|
https://docs.github.com/en/rest/reference/issues#list-issue-comments
|
||||||
"""
|
"""
|
||||||
headers = {"Accept": "application/vnd.github.v3.full+json"}
|
headers = {"Accept": "application/vnd.github.v3.full+json"}
|
||||||
@ -84,22 +85,21 @@ class Issue(BaseModel):
|
|||||||
async def get_timeline(self) -> PaginatedList[TimelineEvent]:
|
async def get_timeline(self) -> PaginatedList[TimelineEvent]:
|
||||||
"""
|
"""
|
||||||
GET /repo/:full_name/issues/:number/timeline
|
GET /repo/:full_name/issues/:number/timeline
|
||||||
|
|
||||||
https://docs.github.com/en/rest/reference/issues#list-timeline-events-for-an-issue
|
https://docs.github.com/en/rest/reference/issues#list-timeline-events-for-an-issue
|
||||||
"""
|
"""
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/vnd.github.mockingbird-preview.full+json"
|
"Accept": "application/vnd.github.mockingbird-preview.full+json"
|
||||||
}
|
}
|
||||||
return PaginatedList(Union[TimelineEventCommited,
|
return PaginatedList(
|
||||||
TimelineEventCommented,
|
Union[TimelineEventCommited, TimelineEventCommented,
|
||||||
TimelineEventReviewed,
|
TimelineEventReviewed, TimelineEventReviewRequested,
|
||||||
TimelineEventReviewRequested,
|
TimelineEventRenamed, TimelineEventLabeled,
|
||||||
TimelineEventRenamed, TimelineEventMerged,
|
TimelineEventMerged, TimelineEventClosed, TimelineEvent],
|
||||||
TimelineEventClosed, TimelineEvent],
|
self.requester,
|
||||||
self.requester,
|
"GET",
|
||||||
"GET",
|
self.timeline_url,
|
||||||
self.timeline_url,
|
headers=headers)
|
||||||
headers=headers)
|
|
||||||
|
|
||||||
async def get_diff(self) -> str:
|
async def get_diff(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
@Author : yanyongyu
|
@Author : yanyongyu
|
||||||
@Date : 2021-05-14 00:57:33
|
@Date : 2021-05-14 00:57:33
|
||||||
@LastEditors : yanyongyu
|
@LastEditors : yanyongyu
|
||||||
@LastEditTime : 2021-05-21 02:24:18
|
@LastEditTime : 2021-05-21 14:47:24
|
||||||
@Description : None
|
@Description : None
|
||||||
@GitHub : https://github.com/yanyongyu
|
@GitHub : https://github.com/yanyongyu
|
||||||
"""
|
"""
|
||||||
@ -100,7 +100,7 @@ class TimelineEventReviewed(TimelineEvent):
|
|||||||
pull_request_url: str
|
pull_request_url: str
|
||||||
author_association: str
|
author_association: str
|
||||||
submitted_at: datetime
|
submitted_at: datetime
|
||||||
body: str
|
body: Optional[str]
|
||||||
body_text: Optional[str]
|
body_text: Optional[str]
|
||||||
body_html: Optional[str]
|
body_html: Optional[str]
|
||||||
links: TimelineEventReviewedLinks = Field(alias="_links")
|
links: TimelineEventReviewedLinks = Field(alias="_links")
|
||||||
@ -136,17 +136,6 @@ class TimelineEventRenamed(TimelineEvent):
|
|||||||
rename: TimelineEventRenamedDetail
|
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):
|
class TimelineEventLabeledInfo(_BaseModel):
|
||||||
name: str
|
name: str
|
||||||
color: str
|
color: str
|
||||||
@ -164,6 +153,17 @@ class TimelineEventLabeled(TimelineEvent):
|
|||||||
label: TimelineEventLabeledInfo
|
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):
|
class TimelineEventClosed(TimelineEvent):
|
||||||
event: Literal["closed"]
|
event: Literal["closed"]
|
||||||
id: int
|
id: int
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
@Author : yanyongyu
|
@Author : yanyongyu
|
||||||
@Date : 2021-05-14 17:09:12
|
@Date : 2021-05-14 17:09:12
|
||||||
@LastEditors : yanyongyu
|
@LastEditors : yanyongyu
|
||||||
@LastEditTime : 2021-05-16 23:52:11
|
@LastEditTime : 2021-05-21 15:04:44
|
||||||
@Description : None
|
@Description : None
|
||||||
@GitHub : https://github.com/yanyongyu
|
@GitHub : https://github.com/yanyongyu
|
||||||
"""
|
"""
|
||||||
@ -18,8 +18,9 @@ from datetime import datetime
|
|||||||
import jinja2
|
import jinja2
|
||||||
import humanize
|
import humanize
|
||||||
from unidiff import PatchSet
|
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"],
|
env = jinja2.Environment(extensions=["jinja2.ext.loopcontrols"],
|
||||||
loader=jinja2.FileSystemLoader(
|
loader=jinja2.FileSystemLoader(
|
||||||
@ -44,9 +45,19 @@ def review_state(value: str) -> str:
|
|||||||
return states.get(value, value)
|
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["classname"] = classname
|
||||||
env.filters["relative_time"] = relative_time
|
env.filters["relative_time"] = relative_time
|
||||||
env.filters["review_state"] = review_state
|
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:
|
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
|
* @Author : yanyongyu
|
||||||
* @Date : 2021-05-14 17:11:26
|
* @Date : 2021-05-14 17:11:26
|
||||||
* @LastEditors : yanyongyu
|
* @LastEditors : yanyongyu
|
||||||
* @LastEditTime : 2021-05-17 10:06:44
|
* @LastEditTime : 2021-05-21 15:05:28
|
||||||
* @Description : None
|
* @Description : None
|
||||||
* @GitHub : https://github.com/yanyongyu
|
* @GitHub : https://github.com/yanyongyu
|
||||||
-->
|
-->
|
||||||
@ -23,7 +23,7 @@
|
|||||||
{% set event = issue %}
|
{% set event = issue %}
|
||||||
{% set showavatar = true %}
|
{% set showavatar = true %}
|
||||||
{% set ns = namespace(merged=false) %}
|
{% set ns = namespace(merged=false) %}
|
||||||
|
|
||||||
{% include "comment.html" %}
|
{% include "comment.html" %}
|
||||||
|
|
||||||
{% for event in timeline -%}
|
{% for event in timeline -%}
|
||||||
@ -38,11 +38,14 @@
|
|||||||
{% include "review.html" %}
|
{% include "review.html" %}
|
||||||
|
|
||||||
{% elif event|classname == "TimelineEventReviewRequested" -%}
|
{% elif event|classname == "TimelineEventReviewRequested" -%}
|
||||||
{% include "review_request.html" %}
|
{% include "review-request.html" %}
|
||||||
|
|
||||||
{% elif event|classname == "TimelineEventRenamed" -%}
|
{% elif event|classname == "TimelineEventRenamed" -%}
|
||||||
{% include "rename.html" %}
|
{% include "rename.html" %}
|
||||||
|
|
||||||
|
{% elif event|classname == "TimelineEventLabeled" -%}
|
||||||
|
{% include "label.html" %}
|
||||||
|
|
||||||
{% elif event|classname == "TimelineEventMerged" -%}
|
{% elif event|classname == "TimelineEventMerged" -%}
|
||||||
{% include "merge.html" %}
|
{% include "merge.html" %}
|
||||||
{% if loop.nextitem|classname == "TimelineEventClosed" -%}
|
{% if loop.nextitem|classname == "TimelineEventClosed" -%}
|
||||||
@ -56,10 +59,11 @@
|
|||||||
{%- else -%}
|
{%- else -%}
|
||||||
{% include "close.html" %}
|
{% include "close.html" %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
<!-- TODO: other events -->
|
<!-- TODO: other events -->
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
|
{{ event|debug_event }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- endfor %}
|
{%- 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
|
* @Author : yanyongyu
|
||||||
* @Date : 2021-05-21 01:06:07
|
* @Date : 2021-05-21 01:06:07
|
||||||
* @LastEditors : yanyongyu
|
* @LastEditors : yanyongyu
|
||||||
* @LastEditTime : 2021-05-21 01:19:04
|
* @LastEditTime : 2021-05-21 14:21:02
|
||||||
* @Description : None
|
* @Description : None
|
||||||
* @GitHub : https://github.com/yanyongyu
|
* @GitHub : https://github.com/yanyongyu
|
||||||
-->
|
-->
|
||||||
@ -47,6 +47,6 @@
|
|||||||
</a>
|
</a>
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{{event.created_at|relative_time}}
|
<a class="Link--secondary">{{event.created_at|relative_time}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -4,7 +4,7 @@
|
|||||||
@Author : yanyongyu
|
@Author : yanyongyu
|
||||||
@Date : 2020-11-23 18:44:18
|
@Date : 2020-11-23 18:44:18
|
||||||
@LastEditors : yanyongyu
|
@LastEditors : yanyongyu
|
||||||
@LastEditTime : 2020-11-23 22:15:27
|
@LastEditTime : 2021-05-21 14:56:31
|
||||||
@Description : None
|
@Description : None
|
||||||
@GitHub : https://github.com/yanyongyu
|
@GitHub : https://github.com/yanyongyu
|
||||||
"""
|
"""
|
||||||
@ -19,7 +19,6 @@ class Config(BaseSettings):
|
|||||||
sentry_dsn: str
|
sentry_dsn: str
|
||||||
sentry_debug: bool = False
|
sentry_debug: bool = False
|
||||||
sentry_release: Optional[str] = None
|
sentry_release: Optional[str] = None
|
||||||
sentry_release: Optional[str] = None
|
|
||||||
sentry_environment: Optional[str] = None
|
sentry_environment: Optional[str] = None
|
||||||
sentry_server_name: Optional[str] = None
|
sentry_server_name: Optional[str] = None
|
||||||
sentry_sample_rate: float = 1.
|
sentry_sample_rate: float = 1.
|
||||||
|
Loading…
Reference in New Issue
Block a user