Last active
October 6, 2022 20:56
-
-
Save angelogladding/c61488d2dd82fb73b9078541a4e2ea13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import mf | |
def summarize_github_profile(user): | |
name = mf.get(f"https://github.com/{user}").card["name"] | |
return f"GitHub profile for {name}" | |
url_summary_templates = [ | |
( | |
r"https://github.com/(?P<user>\w+)/(?P<project>[\w-]+)/pulls/(?P<pull>\d+)", | |
"A comment on a pull request in the {project} GitHub repository", | |
), | |
( | |
r"https://github.com/(?P<user>\w+)", | |
summarize_github_profile, | |
), | |
] | |
def get_summary(url: str): | |
""" | |
Return a text summary for given `url`. | |
>>> get_summary("https://github.com/capjamesg/indieweb-utils/pulls/1") | |
'A comment on a pull request in the indieweb-utils GitHub repository' | |
""" | |
for pattern, summary in url_summary_templates: | |
if match := re.match(pattern, url): | |
matches = match.groupdict() | |
try: | |
return summary(**matches) | |
except TypeError: | |
return summary.format(**matches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment