reporef

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package reporef parses a git repository reference in any common form (https, http, ssh, git, scp style) into host, owner, repo, provider and a canonical clone URL. It is the one parser every repo URL input goes through.

Index

Constants

View Source
const (
	SchemeHTTPS = "https"
	SchemeHTTP  = "http"
	SchemeSSH   = "ssh"
	SchemeGit   = "git"
	SchemeSCP   = "scp"
)

Scheme values for Ref.Scheme. SchemeSCP is the git@host:owner/repo form.

Variables

View Source
var ErrUnsupported = errors.New("reporef: not a remote git repository URL")

ErrUnsupported is returned for input that is not a remote repository URL.

Functions

func Identity

func Identity(raw string) string

Identity reduces any repository reference, including "owner/repo" shorthand, to Ref.Identity. Unreadable input yields "".

Types

type Provider

type Provider string

Provider is a best guess at the git host software, from the host name only.

const (
	ProviderGitHub    Provider = "github"
	ProviderGitLab    Provider = "gitlab"
	ProviderBitbucket Provider = "bitbucket"
	ProviderOther     Provider = "other"
)

Provider values. Self-hosted instances on custom domains report ProviderOther.

type Ref

type Ref struct {
	// Scheme is the transport the input used, one of the Scheme constants.
	Scheme string
	// Host is the lowercase host name without a port.
	Host string
	// Port is kept only for http and https; an ssh port means nothing over https.
	Port string
	// Owner is every path segment before the repo, so GitLab subgroups stay intact.
	Owner string
	// Repo is the last path segment without a ".git" suffix.
	Repo     string
	Provider Provider
	// HadCredentials is true when a password or token was stripped from the input.
	HadCredentials bool
}

Ref is a parsed repository reference. It never holds credentials.

func Parse

func Parse(raw string) (Ref, error)

Parse reads a repository URL. Shorthand such as "owner/repo" needs ParseWithHost.

func ParseWithHost

func ParseWithHost(raw, defaultHost string) (Ref, error)

ParseWithHost is Parse that also accepts "owner/repo" (on defaultHost) and "host.tld/owner/repo" shorthand, the forms import sources store.

func (Ref) CloneURL

func (r Ref) CloneURL() string

CloneURL is the canonical credential-free clone URL: https, or http when the input was plain http.

func (Ref) Identity

func (r Ref) Identity() string

Identity is the lowercase path, so every form of one repository compares equal.

func (Ref) IsHTTP

func (r Ref) IsHTTP() bool

IsHTTP reports whether the input already used http or https.

func (Ref) Path

func (r Ref) Path() string

Path is "owner/repo", or just "repo" when the host has no owner level.

Jump to

Keyboard shortcuts

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