API Reference¶
Parsing¶
This is the parsing aspect of GitHub.com URLs and shorthands.
GitHub’s api schema for (supported) types are the following:
Issue:
/{owner}/{repo}/issues/{issue_number}Pull Request:
/{owner}/{repo}/pull/{pr_number}Branch/Tag/Commit:
/{owner}/{repo}/tree/{ref}Discussion:
/{owner}/{repo}/discussions/{discussion_number}Tag:
/{owner}/{repo}/releases/tag/{tag}
In addition, issues, pull requests, and commits support comments:
Issue Comment:
/{owner}/{repo}/issues/{issue_number}#issuecomment-{comment_id}Pull Request Comment:
/{owner}/{repo}/pull/{pr_number}#issuecomment-{comment_id}Discussion Comment:
/{owner}/{repo}/discussions/{discussion_number}#discussioncomment-{comment_id}Commit Comment:
/{owner}/{repo}/commit/{commit_sha}#commitcomment-{comment_id}
Issues and pull requests also support events:
Issue Event:
/{owner}/{repo}/issues/{issue_number}#event-{event_id}Pull Request Event:
/{owner}/{repo}/pull/{pr_number}#event-{event_id}
Pull Requests support reviews and review comments:
Review:
/{owner}/{repo}/pull/{pr_number}#pullrequestreview-3373902296Review comments:
/{owner}/{repo}/pull/{pr_number}#discussion_r2269233870
- ghretos.parsing.parse_shorthand(shorthand: str, *, allow_optional_user: bool = False, settings: MatcherSettings = MatcherSettings(domains=['github.com', 'www.github.com'], issues=True, issue_comments=True, issue_events=True, pull_requests=True, pull_request_comments=True, pull_request_reviews=True, pull_request_review_comments=True, pull_request_events=True, discussions=True, discussion_comments=True, commits=True, commit_comments=True, releases=True, shorthand=True, short_repo=True, short_numberables=True, short_refs=True, short_bare_username=False, require_strict_type=True)) GitHubResource | None¶
Parses a shorthand notation for a GitHub resource.
Examples of supported shorthand: - user/repo - user/repo#issue_number - user/repo@ref (can be sha, branch, or tag)
If the user is omitted, default_user is used if provided to enable the following shorthand: - repo#issue_number - repo@ref (can be sha, branch, or tag)
When allow_optional_user is False, the user must be provided. If allow_optional_user is True, returned repos will have an empty string in the User field.
No requests are made to GitHub; this is purely syntactic parsing. No validation is performed on the parsed values, they are simply returned as-is.
- ghretos.parsing.parse_url(url: str | URL, *, settings: MatcherSettings = MatcherSettings(domains=['github.com', 'www.github.com'], issues=True, issue_comments=True, issue_events=True, pull_requests=True, pull_request_comments=True, pull_request_reviews=True, pull_request_review_comments=True, pull_request_events=True, discussions=True, discussion_comments=True, commits=True, commit_comments=True, releases=True, shorthand=True, short_repo=True, short_numberables=True, short_refs=True, short_bare_username=False, require_strict_type=True)) GitHubResource | None¶
Parses a GitHub URL into its corresponding resource.
Please note that PullRequests are a type of Issue in GitHub’s data model, and are represented as such in the API. This method still distinguishes them for clarity.
Note
Unlike
parse_shorthand, this method returns a separate PullRequest type for pull requests. However, since pull requests are represented as issues in GitHub’s data model and API, this distinction is primarily for clarity. In addition, unsanitized input URLs may lead to unexpected results. Do not assume a PullRequest actually refers to a pull request.- Args:
url: The URL to parse. settings:
MatcherSettingsfor the URL matcher.- Returns:
A ParsedResource instance if the URL corresponds to a known GitHub resource, None otherwise.
Models¶
- class ghretos.models.CommitComment(*, repo: Repo, sha: str, comment_id: int)¶
Represents a comment on a GitHub commit.
- class ghretos.models.DiscussionComment(*, repo: Repo, number: int, comment_id: int)¶
Represents a comment on a GitHub discussion.
- class ghretos.models.GitHubResource¶
Base class for all GitHub resources.
- class ghretos.models.IssueComment(*, repo: ghretos.models.Repo, number: int, comment_id: int)¶
- class ghretos.models.IssueEvent(*, repo: ghretos.models.Repo, number: int, event_id: int)¶
- class ghretos.models.MatcherSettings(domains: list[str] = <factory>, issues: bool = True, issue_comments: bool = True, issue_events: bool = True, pull_requests: bool = True, pull_request_comments: bool = True, pull_request_reviews: bool = True, pull_request_review_comments: bool = True, pull_request_events: bool = True, discussions: bool = True, discussion_comments: bool = True, commits: bool = True, commit_comments: bool = True, releases: bool = True, shorthand: bool = True, short_repo: bool = True, short_numberables: bool = True, short_refs: bool = True, short_bare_username: bool = False, require_strict_type: bool = True)¶
Settings for matching GitHub URLs and shorthands.
Each of these settings are completely seperate: disabling one does not affect the others. For example, disabling issues will not disable issue_comments.
- commit_comments: bool = True¶
Whether to match
/owner/repo/commit/{sha}#commitcomment-{number}commit comment URLs.
- discussion_comments: bool = True¶
Whether to match
/owner/repo/discussions/{number}#discussioncomment-{number}discussion comment URLs.
- issue_comments: bool = True¶
Whether to match
/owner/repo/issues/{number}#issuecomment-{number}issue comment URLs.
- issue_events: bool = True¶
Whether to match
/owner/repo/issues/{number}#event-{number}issue event URLs.
- classmethod none() Self¶
Return a MatcherSettings instance with all resource types disabled.
- pull_request_comments: bool = True¶
Whether to match
/owner/repo/pull/{number}#issuecomment-{number}pull request comment URLs.
- pull_request_events: bool = True¶
Whether to match
/owner/repo/pull/{number}#event-{number}pull request event URLs.
- pull_request_review_comments: bool = True¶
Whether to match
/owner/repo/pull/{number}#pullrequestreviewcomment-{number}pull request review comment URLs.
- pull_request_reviews: bool = True¶
Whether to match
/owner/repo/pull/{number}#review-{number}pull request review URLs.
- require_strict_type: bool = True¶
Whether to support /issues/, /pulls/, and /discussions/ only for their respective types. If this is False, issues, pulls, and discussions will be ignored if the fragment indicates a type only supported by another resource.
- short_bare_username: bool = False¶
Whether to support bare short username notation. e.g., username to refer to a user. This is disabled by default to prevent false positives.
- class ghretos.models.NumberedResource(*, repo: Repo, number: int)¶
Special base class for resources with numbers.
This is used for shorthand parsing for numbered resources, where the specific type is not known.
This can represent either a
Issue,PullRequest, orDiscussion.
- class ghretos.models.PullRequestComment(*, repo: Repo, number: int, comment_id: int)¶
Represents a comment on a GitHub pull request.
- class ghretos.models.PullRequestEvent(*, repo: Repo, number: int, event_id: int)¶
Represents an event on a GitHub pull request.
- class ghretos.models.PullRequestReview(*, repo: Repo, number: int, review_id: int)¶
Represents a review on a GitHub pull request.
- class ghretos.models.PullRequestReviewComment(*, repo: Repo, number: int, comment_id: int, sha: str | None = None, commit_page: bool = False, files_page: bool = False)¶
Represents a review comment on a GitHub pull request.