giturl

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package giturl is a tiny, dependency-free predicate package for classifying Git remote URL forms (HTTP(s) vs SSH). Lives outside pkg/utils/git so callers in pkg/config and pkg/config/prompt can import it without the import cycle that pkg/utils/git creates by depending on pkg/config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHTTP

func IsHTTP(s string) bool

IsHTTP reports whether s is an HTTP-form Git URL — i.e. starts with http:// or https://. Trailing whitespace is not trimmed; callers that accept user input should TrimSpace upstream.

func IsSSH

func IsSSH(s string) bool

IsSSH reports whether s looks like an SSH-form Git URL — i.e. is non-empty and not HTTP. Both scp-style (git@host:path) and rfc-3986 (ssh://user@host/path) forms qualify.

Types

type ParsedURL

type ParsedURL struct {
	// Host is the network authority — "github.com" or
	// "gitea.example.com:2223". Includes port when non-standard.
	Host string

	// Owner is the first path segment — typically the org or user.
	Owner string

	// Repo is the second path segment, with any trailing ".git"
	// stripped.
	Repo string

	// Scheme is the URL scheme — "https", "http", or "ssh"
	// (scp-style git@host:path is reported as "ssh").
	Scheme string
}

ParsedURL is the structured representation of a Git remote URL. Host-agnostic — works with any forge (github.com, gitea.example.com:2223, self-hosted gitlab, etc.). Use Parse to construct.

func Parse

func Parse(s string) (*ParsedURL, error)

Parse extracts host/owner/repo/scheme from a Git remote URL. Accepted forms:

Returns an error on empty input, unparseable URLs, or paths that don't carry at least owner/repo segments.

func (*ParsedURL) HTTPCloneURL

func (p *ParsedURL) HTTPCloneURL() string

HTTPCloneURL returns the HTTPS clone-URL form regardless of the original scheme — useful when constructing forge URLs for users to click (e.g., GitHub's "/compare/..." page) without leaking agent-routed credentials.

For ssh-derived URLs (scp-style or ssh://), drops any port suffix on Host: an SSH port is meaningless to HTTPS, and leaving it in produces clickable URLs that 404 (browser trying HTTPS against the SSH daemon — was the bug behind operators clicking "https://gitea.example.com:2223/...").

For http/https-derived URLs, preserves the port — those may legitimately use a non-default HTTPS port like :8443.

func (*ParsedURL) HostName

func (p *ParsedURL) HostName() string

HostName returns Host with any "<host>:<port>" suffix stripped. Use for filesystem paths (where the colon would break tools like docker's -v <src>:<dst> volume specs) and TLS SAN comparisons (where the port is irrelevant). Falls back to Host unchanged when there's no port to strip.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL