repourl

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package repourl parses git remote URLs into the host/owner/name identity gitten keys repositories by. It is pure: no git, no filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckNoCredentials

func CheckNoCredentials(raw string) error

CheckNoCredentials returns an error naming the URL, redacted, when it embeds a credential. gitten keeps URLs in state and logs, so it never accepts one.

func HasCredentials

func HasCredentials(raw string) bool

HasCredentials reports whether a remote URL embeds a credential: any user info in an http(s) URL, where a token often travels as the user name, or a password in any other URL. The user in git@host:path is not a credential.

func IsHTTP

func IsHTTP(u string) bool

IsHTTP reports whether u is an http(s) URL, whose auth goes through git's credential helper rather than an SSH key.

func MatchKey

func MatchKey(pattern, key string) bool

MatchKey reports whether repo key host/owner/name matches pattern: a key, or a glob over keys in which * matches any run of characters, slashes included, ? matches one, and [...] (or [!...]) one in or out of a class. So github.com/acme/* is every repo of acme, subgroups included, ghes.company.com/* every repo on that host, and */api every repo named api. A malformed pattern matches nothing; ValidatePattern reports it.

func Redact

func Redact(text string) string

Redact hides credentials in any remote URLs within text: all user info of http(s) URLs, the password of others.

func ValidatePattern

func ValidatePattern(pattern string) error

ValidatePattern returns an error when pattern isn't a well-formed glob.

func WithoutCredentials

func WithoutCredentials(raw string) string

WithoutCredentials returns raw with any credential HasCredentials finds taken out: the user info of an http(s) URL, the password of another. It is what to keep of a URL read from a repository's config, which a person may have put a token in; git's credential helper supplies it instead.

Types

type Identity

type Identity struct {
	Host     string // "github.com"
	Owner    string // "ashtonian"
	Name     string // "gitten"
	FullName string // "ashtonian/gitten"
	SSHURL   string // canonical "git@github.com:ashtonian/gitten.git"
	URL      string // the original input URL, verbatim (preserves scheme/port)
}

Identity represents parsed identity from a git remote URL.

func Parse

func Parse(rawURL string) (*Identity, error)

Parse parses a git remote URL into identity components. It accepts every form git itself does:

Owner may be a multi-segment path (GitLab subgroups). For local remotes, which have no real host/owner, Host is "local", Owner is the parent dir, and Name is the repo dir — enough to form a stable tracking key.

func (*Identity) Key

func (id *Identity) Key() string

Key returns the tracking key, host/owner/name.

Jump to

Keyboard shortcuts

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