Crate ytil_gh

Crate ytil_gh 

Source
Expand description

Provide lightweight GitHub helpers using the gh CLI.

Provide focused wrappers around gh subcommands plus URL parsing helpers for PR IDs and remote canonicalization.

§Rationale

This module shells out to the GitHub CLI (‘gh’) instead of using a direct HTTP client (e.g. octocrab) because:

  • Reuses the user’s existing authenticated gh session (no PAT / device-flow code, fewer secrets to manage).
  • Keeps this utility crate synchronous and lightweight (avoids adding tokio + reqwest dependency graph).
  • Minimizes compile time and binary size in the broader workspace.
  • Leverages ‘gh’ stable porcelain for JSON output (--json / --jq) and future compatibility with GitHub auth flows / SSO.
  • Current feature surface (latest release tag, PR head branch lookup) is small; process spawn overhead is negligible versus HTTP setup cost.

Trade-offs accepted:

  • Less fine-grained control over rate limiting and retries.
  • Tight coupling to gh output flags (low churn historically, but still external).
  • Requires gh binary presence in runtime environments.

Modules§

issue
pr

Enums§

RepoViewField
Repository fields available for querying via gh repo view.

Constants§

GITHUB_HOST 🔒
The GitHub host domain.
GITHUB_PR_ID_PREFIX 🔒
The URL path segment prefix for pull requests.
GITHUB_PR_ID_QUERY_KEY 🔒
The query parameter key used for pull request IDs in GitHub Actions URLs.

Functions§

extract_pr_id_form_url 🔒
Extracts the pull request numeric ID from a GitHub URL.
get_branch_name_from_url
Extracts the branch name from a GitHub pull request Url.
get_latest_release
Retrieves the latest release tag name for the specified GitHub repository.
get_repo_urls
Returns all GitHub remote URLs for the repository rooted at repo_path.
get_repo_view_field
Return the specified repository field via gh repo view.
log_into_github
Ensures the user is authenticated with the GitHub CLI.
parse_github_url_from_git_remote_url 🔒
Converts a Git remote URL (SSH or HTTPS) to a canonical GitHub HTTPS URL without the .git suffix.