Skip to content

Commit

Permalink
Pull in some pre-PR testing changes
Browse files Browse the repository at this point in the history
Need to test these regex changes pretty heavily before merging, so might
as well start even before opening a PR.

Also reverted back to the 0.2.0a7 state of the commit-link handler
pluralization code, since the extra parentheses weren't actually needed.
  • Loading branch information
dgw committed Apr 30, 2019
1 parent 2f97301 commit ab383d0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sopel_modules/github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@
'''

issueURL = (r'https?://(?:www\.)?github.com/([A-z0-9\-_]+/[A-z0-9\-_]+)/(?:issues|pull)/([\d]+)(?:#issuecomment-([\d]+))?')
commitURL = (r'https?://(?:www\.)?github.com/([A-z0-9\-_]+/[A-z0-9\-_]+)/(?:commit)/([A-z0-9\-]+)')
# GitHub enforces alphanumeric usernames, and allows only one punctuation character: hyphen ('-')
# Regex copied and slightly modified to meet our needs from CC0 source:
# https://github.com/shinnn/github-username-regex/blob/0794566cc10e8c5a0e562823f8f8e99fa044e5f4/module.js#L1
githubUsername = r'[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}'
# not from anywhere, but handy to simply reuse
githubRepoSlug = r'[A-Za-z0-9\.\-]+'
# lots of regex and other globals to make this stuff work
issueURL = (r'https?://(?:www\.)?github.com/({username}/{repo})/(?:issues|pull)/([\d]+)(?:#issuecomment-([\d]+))?'.format(username=githubUsername, repo=githubRepoSlug))
commitURL = (r'https?://(?:www\.)?github.com/({username}/{repo})/(?:commit)/([A-z0-9\-]+)'.format(username=githubUsername, repo=githubRepoSlug))
regex = re.compile(issueURL)
commitRegex = re.compile(commitURL)
repoRegex = re.compile('github\.com/([^ /]+?)/([^ /]+)/?(?!\S)')
repoRegex = re.compile(r'github\.com/({username})/({repo})/?(?!\S)'.format(username=githubUsername, repo=githubRepoSlug))
sopel_instance = None


Expand Down Expand Up @@ -188,7 +195,7 @@ def commit_info(bot, trigger, match=None):
str(data['stats']['total']),
' changes in ',
str(file_count),
(' file' if file_count == 1 else ' files')
' file' if file_count == 1 else ' files'
]
bot.say(''.join(response))

Expand Down

0 comments on commit ab383d0

Please sign in to comment.