Skip to content

Instantly share code, notes, and snippets.

@AdamGagorik
Last active April 9, 2024 15:21
Show Gist options
  • Save AdamGagorik/a082279465074c150c13692047c1428a to your computer and use it in GitHub Desktop.
Save AdamGagorik/a082279465074c150c13692047c1428a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import webbrowser
import argparse
import os
def default() -> list[str]:
return os.environ.get("GITHUB_PULL_REQUEST_AUTHORS", "").split(":")
def format_is(*values) -> str:
return "+".join(f"is%3A{value}" for value in set(values))
def format_authors(*authors) -> str:
return "+".join(f"author%3A{author}" for author in authors if set(author))
def format_https_url(*authors: str, is_: list) -> str:
assert authors or is_
return (
"https://github.com/search?q="
+ "+".join(
(
format_is(*is_),
format_authors(*authors),
)
)
+ "&"
+ "&".join(("type=pullrequests",))
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(usage="--author agagorik --is pr open")
parser.add_argument(
"--author",
dest="authors",
action="append",
default=default(),
)
parser.add_argument(
"--is",
dest="is_",
nargs="*",
metavar="str",
default=["pr", "open"],
)
options = parser.parse_args()
if not any(options.authors):
raise RuntimeError("no authors to query!")
print(url := format_https_url(*options.authors, is_=options.is_))
webbrowser.open(url, new=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment