Skip to content

Commit

Permalink
Update user.url_link (#399)
Browse files Browse the repository at this point in the history
* invert the ASCII characters of the terminal qrcode

Signed-off-by: doublewinter0 <erdong.me@gmail.com>

* Update user.url_link

Signed-off-by: doublewinter0 <erdong.me@gmail.com>

* pylint ignore R1735

Signed-off-by: doublewinter0 <erdong.me@gmail.com>

---------

Signed-off-by: doublewinter0 <erdong.me@gmail.com>
  • Loading branch information
doublewinter0 committed Jul 15, 2023
1 parent 6c9d54f commit af5515d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ lint: pylint pycodestyle flake8 mypy
pylint:
pylint \
--load-plugins pylint_quotes \
--disable=W0511,R0801,cyclic-import,C4001 \
--disable=W0511,R0801,cyclic-import,C4001,R1735 \
$(SOURCE_GLOB)

.PHONY: pycodestyle
Expand Down Expand Up @@ -109,7 +109,7 @@ check-python-version:

.PHONY: format
format:
yapf $(SOURCE_GLOB)
yapf $(SOURCE_GLOB)

code:
code .
Expand Down
27 changes: 12 additions & 15 deletions src/wechaty/user/url_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
Optional,
Type
)
from urllib3 import get_host
from wechaty_puppet import UrlLinkPayload, get_logger
from urllib3.util.url import parse_url

from wechaty_puppet import get_logger, UrlLinkPayload

from wechaty.utils.link import get_url_metadata

from dataclasses import dataclass
from typing import Dict, List
from abc import abstractmethod
from github import Github
Expand All @@ -24,22 +24,20 @@
from github.Issue import Issue
from github.IssueComment import IssueComment

from wechaty_puppet.schemas.url_link import UrlLinkPayload


log = get_logger('UrlLink')


class UrlLinkParser:
# valid host-name of one parser
host_names: List[str] = []

@classmethod
def can_parser(cls, url: str) -> bool:
if not cls.host_names:
raise ValueError(f"please set valid host-names for parser, eg: ['github']")
_, host_name, _ = get_host(url)

host_name = parse_url(url).hostname
return host_name in cls.host_names

@abstractmethod
Expand All @@ -55,7 +53,7 @@ class GithubUrlLinkParser(UrlLinkParser):
def __init__(self, token: Optional[str] = None):
self._github = Github(login_or_token=token)
self._repositories: Dict[str, Repository] = {}

@staticmethod
def can_parser(url: str) -> bool:
"""the source of url
Expand All @@ -64,11 +62,10 @@ def can_parser(url: str) -> bool:
url (str): github urllink
Returns:
bool: wheter is github based urll
bool: whether is github based url
"""
_, host_name, _ = get_host(url)
return host_name

return parse_url(url).hostname

def parse(self, url: str) -> UrlLinkPayload:
"""parse url-link as payload
Expand Down Expand Up @@ -115,7 +112,7 @@ def get_pr_payload(self, repo_name: str, pr_id: int) -> UrlLinkPayload:
thumbnailUrl=pull_request.user.avatar_url
)
return payload

def get_pr_comment_payload(self, repo_name: str, pr_id: int, comment_id: int, comment_type: str = 'issue') -> UrlLinkPayload:
"""get comment of pull-request, which can be issue or review comment
Expand Down Expand Up @@ -218,7 +215,7 @@ def create(
metadata = get_url_metadata(url)

payload = UrlLinkPayload(url=url)

payload.title = title or metadata.get('title', None)
payload.thumbnailUrl = thumbnail_url or metadata.get('image', None)
payload.description = description or metadata.get('description', None)
Expand Down

0 comments on commit af5515d

Please sign in to comment.