diff options
| author | 2021-01-19 21:00:34 +0200 | |
|---|---|---|
| committer | 2021-01-19 21:00:34 +0200 | |
| commit | 318a0f6c5e597c61833984cd608359c8b4e5ddf0 (patch) | |
| tree | c903d004751ca6718aab80be3c3612e655928b5f | |
| parent | Better error reporting in _fetch_response(?) (diff) | |
Better GitHub regex
| -rw-r--r-- | bot/exts/info/code_snippets.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/bot/exts/info/code_snippets.py b/bot/exts/info/code_snippets.py index 3469b88f4..84f606036 100644 --- a/bot/exts/info/code_snippets.py +++ b/bot/exts/info/code_snippets.py @@ -13,27 +13,27 @@ from bot.utils.messages import wait_for_deletion log = logging.getLogger(__name__) GITHUB_RE = re.compile( - r'https://github\.com/(?P<repo>\S+?)/blob/(?P<path>\S+/[^\s#,>]+)' - r'(#L(?P<start_line>\d+)([-~:]L(?P<end_line>\d+))?)?($|\s|,|>)' + r'https://github\.com/(?P<repo>[a-zA-Z0-9-]+/[\w.-]+)/blob/' + r'(?P<path>[^#>]+/{0,1})(#L(?P<start_line>\d+)([-~:]L(?P<end_line>\d+))?)' ) GITHUB_GIST_RE = re.compile( r'https://gist\.github\.com/([^/]+)/(?P<gist_id>[^\W_]+)/*' r'(?P<revision>[^\W_]*)/*#file-(?P<file_path>\S+?)' - r'(-L(?P<start_line>\d+)([-~:]L(?P<end_line>\d+))?)?($|\s|,|>)' + r'(-L(?P<start_line>\d+)([-~:]L(?P<end_line>\d+))?)' ) GITHUB_HEADERS = {'Accept': 'application/vnd.github.v3.raw'} GITLAB_RE = re.compile( r'https://gitlab\.com/(?P<repo>\S+?)/\-/blob/(?P<path>\S+/[^\s#,>]+)' - r'(#L(?P<start_line>\d+)([-](?P<end_line>\d+))?)?($|\s|,|>)' + r'(#L(?P<start_line>\d+)([-](?P<end_line>\d+))?)' ) BITBUCKET_RE = re.compile( r'https://bitbucket\.org/(?P<repo>\S+?)/src/' r'(?P<ref>\S+?)/(?P<file_path>[^\s#,>]+)' - r'(#lines-(?P<start_line>\d+)(:(?P<end_line>\d+))?)?($|\s|,|>)' + r'(#lines-(?P<start_line>\d+)(:(?P<end_line>\d+))?)' ) |