Skip to content

Commit af5515d

Browse files
Update user.url_link (#399)
* 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>
1 parent 6c9d54f commit af5515d

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ lint: pylint pycodestyle flake8 mypy
3232
pylint:
3333
pylint \
3434
--load-plugins pylint_quotes \
35-
--disable=W0511,R0801,cyclic-import,C4001 \
35+
--disable=W0511,R0801,cyclic-import,C4001,R1735 \
3636
$(SOURCE_GLOB)
3737

3838
.PHONY: pycodestyle
@@ -109,7 +109,7 @@ check-python-version:
109109

110110
.PHONY: format
111111
format:
112-
yapf $(SOURCE_GLOB)
112+
yapf $(SOURCE_GLOB)
113113

114114
code:
115115
code .

src/wechaty/user/url_link.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
Optional,
88
Type
99
)
10-
from urllib3 import get_host
11-
from wechaty_puppet import UrlLinkPayload, get_logger
10+
from urllib3.util.url import parse_url
11+
12+
from wechaty_puppet import get_logger, UrlLinkPayload
1213

1314
from wechaty.utils.link import get_url_metadata
1415

15-
from dataclasses import dataclass
1616
from typing import Dict, List
1717
from abc import abstractmethod
1818
from github import Github
@@ -24,22 +24,20 @@
2424
from github.Issue import Issue
2525
from github.IssueComment import IssueComment
2626

27-
from wechaty_puppet.schemas.url_link import UrlLinkPayload
28-
2927

3028
log = get_logger('UrlLink')
3129

3230

3331
class UrlLinkParser:
3432
# valid host-name of one parser
3533
host_names: List[str] = []
36-
34+
3735
@classmethod
3836
def can_parser(cls, url: str) -> bool:
3937
if not cls.host_names:
4038
raise ValueError(f"please set valid host-names for parser, eg: ['github']")
41-
42-
_, host_name, _ = get_host(url)
39+
40+
host_name = parse_url(url).hostname
4341
return host_name in cls.host_names
4442

4543
@abstractmethod
@@ -55,7 +53,7 @@ class GithubUrlLinkParser(UrlLinkParser):
5553
def __init__(self, token: Optional[str] = None):
5654
self._github = Github(login_or_token=token)
5755
self._repositories: Dict[str, Repository] = {}
58-
56+
5957
@staticmethod
6058
def can_parser(url: str) -> bool:
6159
"""the source of url
@@ -64,11 +62,10 @@ def can_parser(url: str) -> bool:
6462
url (str): github urllink
6563
6664
Returns:
67-
bool: wheter is github based urll
65+
bool: whether is github based url
6866
"""
69-
_, host_name, _ = get_host(url)
70-
return host_name
71-
67+
return parse_url(url).hostname
68+
7269
def parse(self, url: str) -> UrlLinkPayload:
7370
"""parse url-link as payload
7471
@@ -115,7 +112,7 @@ def get_pr_payload(self, repo_name: str, pr_id: int) -> UrlLinkPayload:
115112
thumbnailUrl=pull_request.user.avatar_url
116113
)
117114
return payload
118-
115+
119116
def get_pr_comment_payload(self, repo_name: str, pr_id: int, comment_id: int, comment_type: str = 'issue') -> UrlLinkPayload:
120117
"""get comment of pull-request, which can be issue or review comment
121118
@@ -218,7 +215,7 @@ def create(
218215
metadata = get_url_metadata(url)
219216

220217
payload = UrlLinkPayload(url=url)
221-
218+
222219
payload.title = title or metadata.get('title', None)
223220
payload.thumbnailUrl = thumbnail_url or metadata.get('image', None)
224221
payload.description = description or metadata.get('description', None)

0 commit comments

Comments
 (0)