Skip to content

Instantly share code, notes, and snippets.

@angelogladding
Last active October 6, 2022 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelogladding/c61488d2dd82fb73b9078541a4e2ea13 to your computer and use it in GitHub Desktop.
Save angelogladding/c61488d2dd82fb73b9078541a4e2ea13 to your computer and use it in GitHub Desktop.
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