Created
October 27, 2025 15:56
-
-
Save travisbhartwell/900c474fc4627323e443ba1e53fa3a97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env -S uv run --script | |
| # /// script | |
| # requires-python = ">=3.14" | |
| # dependencies = [ | |
| # "typer", | |
| # "typing-extensions", | |
| # "url-data-extractor", | |
| # ] | |
| # | |
| # [tool.uv.sources] | |
| # url-data-extractor = { git = "https://github.com/travisbhartwell/url_data_extractor.git" } | |
| # /// | |
| from url_data_extractor.matchers import CompoundMatcher, HostMatcher, PathPartsMatcher | |
| from url_data_extractor.data_extractors import URLDataExtractor, PathPartDataExtractor | |
| from enum import Enum | |
| from pprint import pprint | |
| import typer | |
| from typing_extensions import Annotated | |
| from sys import stderr | |
| from urllib.parse import urlparse | |
| gitHubIssueURLDataExtractor = ( | |
| URLDataExtractor.Builder() | |
| .with_url_matcher( | |
| CompoundMatcher.Builder() | |
| .with_matcher(HostMatcher("github.com")) | |
| .with_matcher( | |
| PathPartsMatcher.Builder().with_value_at_index(-2, "issues").build() | |
| ) | |
| .build() | |
| ) | |
| .with_data_element_extractor("org", PathPartDataExtractor(0)) | |
| .with_data_element_extractor("repo", PathPartDataExtractor(1)) | |
| .with_data_element_extractor("issue", PathPartDataExtractor(-1)) | |
| .build() | |
| ) | |
| class MarkdownLinkType(str, Enum): | |
| standard = "standard" | |
| descriptive = "descriptive" | |
| fancy = "fancy" | |
| def main( | |
| url: Annotated[str, typer.Argument(help="The URL to process.")], | |
| title: Annotated[str, typer.Argument(help="The page title for the URL.")], | |
| link_type: Annotated[ | |
| MarkdownLinkType, typer.Option(help="The type of link to generate") | |
| ] = MarkdownLinkType.standard, | |
| ) -> None: | |
| try: | |
| parsed_url = urlparse(url) | |
| data = gitHubIssueURLDataExtractor.extract_url_data(parsed_url) | |
| pprint(data) | |
| except Exception as e: | |
| print(e, file=stderr) | |
| raise typer.Exit(code=1) | |
| if __name__ == "__main__": | |
| typer.run(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment