def get_pull_requests(url: hyperlink.URL) -> t.List[str]: url = url.replace(host="api.github.com", path=("repos", ) + url.path + ("pulls", )) r = requests.get(url) r.raise_for_status() pulls = r.json() out = [] assert isinstance(pulls, list) for pull in pulls: head = pull["head"] if head is None: continue repo = head["repo"] if repo is None: continue clone_url = repo["clone_url"] ref = head["ref"] if clone_url is None or ref is None: continue out.append(f"git+{clone_url}@{ref}") return out
def _watch_url(self, embed_url): """ Generate the URL of the YouTube page at which the embedded video can be viewed. """ video_id = embed_url.path[1] watch_url = URL( scheme='https', host='www.youtube.com', path=('watch',), query=(('v', video_id),), ) try: [start] = embed_url.get('start') except (KeyError, ValueError): return watch_url if not start.isdigit(): return watch_url # Ignore an invalid second offset. return watch_url.replace(fragment='t={}s'.format(start))
def _unprefix(url: URL) -> URL: prefix = URLs.app.path[:-1] assert url.path[:len(prefix)] == prefix, (url.path[len(prefix):], prefix) return url.replace(path=url.path[len(prefix):])
def _unprefix(url: URL) -> URL: prefix = URLs.api.path[:-1] assert url.path[:len(prefix)] == prefix, (url.path[len(prefix):], prefix) return url.replace(path=url.path[len(prefix):])