gitremote

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gitremote reads a git remote as the GitHub repository it names.

`cloop remote init` (Task 20417) creates a hub project from the checkout it is run in, and the first thing it needs from that checkout is which repository it is a clone of — the name the project's GitHub grant is then narrowed to. The answer is in the origin remote, written in whichever of git's spellings the developer cloned with: https, the scp form GitHub prints for ssh (git@github.com:owner/name.git), an ssh:// URL, the ssh-over-443 host. All of them name the same owner/name, and that is all this package returns.

Two things are refused rather than read, and both by name:

  • A remote that is not on GitHub. The hub reaches repositories through a GitHub App installation or a GitHub token, so a GitLab or Bitbucket remote names nothing either could reach, and guessing an owner/name from its path would attach a GitHub repository of the same name — somebody else's.
  • A remote that carries a credential: https://<token>@github.com/…, a password in an ssh URL, an access_token query. Nothing here would use it, and every place the remote would go next — a grant, an audit row, an error message — is somewhere a credential must not. Errors print the remote with its user information replaced (Redact).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotGitHub: the remote names a repository somewhere other than
	// github.com, or a local path.
	ErrNotGitHub = errors.New("not a GitHub repository")
	// ErrCredential: the remote embeds a credential.
	ErrCredential = errors.New("embeds a credential")
	// ErrMalformed: the remote is not a repository URL at all.
	ErrMalformed = errors.New("not a repository URL")
)

The three ways a remote can fail to name a GitHub repository. An *Error matches exactly one of them with errors.Is.

Functions

func Redact

func Redact(remote string) string

Redact returns remote with any user information and query replaced by "***", so a remote can be quoted in an error without the credential it may carry.

Types

type Error

type Error struct {
	Remote string
	Reason string
	// contains filtered or unexported fields
}

Error says why a remote names no GitHub repository. Remote is already redacted, so the error is safe to print.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports which of the three sentinels the error is.

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo is a repository on github.com.

func ParseGitHub

func ParseGitHub(remote string) (Repo, error)

ParseGitHub reads a git remote — https, http, ssh, git+ssh, git://, or the scp form [user@]host:owner/name — as the GitHub repository it names.

func ParseRepo

func ParseRepo(s string) (Repo, error)

ParseRepo reads a repository named on a command line: owner/name, or any remote ParseGitHub accepts.

func (Repo) FullName

func (r Repo) FullName() string

FullName is owner/name, the form a grant's repository allowlist takes.

func (Repo) String

func (r Repo) String() string

String is FullName.

func (Repo) URL

func (r Repo) URL() string

URL is the repository's https address.

Jump to

Keyboard shortcuts

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